Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Texturing] Add option to choose the internal colorspace used for color fusion #651

Merged
merged 6 commits into from
Jul 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/aliceVision/depthMap/DepthSimMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <aliceVision/mvsData/geometry.hpp>
#include <aliceVision/mvsData/jetColorMap.hpp>
#include <aliceVision/mvsData/imageIO.hpp>
#include <aliceVision/mvsData/imageAlgo.hpp>

#include <iostream>

Expand Down
5 changes: 3 additions & 2 deletions src/aliceVision/fuseCut/DelaunayGraphCut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <aliceVision/mvsData/Universe.hpp>
#include <aliceVision/mvsUtils/fileIO.hpp>
#include <aliceVision/mvsData/imageIO.hpp>
#include <aliceVision/mvsData/imageAlgo.hpp>
#include <aliceVision/alicevision_omp.hpp>

#include "nanoflann.hpp"
Expand Down Expand Up @@ -310,7 +311,7 @@ void createVerticesWithVisibilities(const StaticVector<int>& cams, std::vector<P
throw std::runtime_error("Similarity map size doesn't match the depth map size: " + simMapFilepath + ", " + depthMapFilepath);
{
std::vector<float> simMapTmp(simMap.size());
imageIO::convolveImage(width, height, simMap, simMapTmp, "gaussian", simGaussianSize, simGaussianSize);
imageAlgo::convolveImage(width, height, simMap, simMapTmp, "gaussian", simGaussianSize, simGaussianSize);
simMap.swap(simMapTmp);
}
}
Expand Down Expand Up @@ -870,7 +871,7 @@ void DelaunayGraphCut::fuseFromDepthMaps(const StaticVector<int>& cams, const Po
throw std::runtime_error("Wrong sim map dimensions: " + simMapFilepath);
{
std::vector<float> simMapTmp(simMap.size());
imageIO::convolveImage(width, height, simMap, simMapTmp, "gaussian", params.simGaussianSizeInit, params.simGaussianSizeInit);
imageAlgo::convolveImage(width, height, simMap, simMapTmp, "gaussian", params.simGaussianSizeInit, params.simGaussianSizeInit);
simMap.swap(simMapTmp);
}

Expand Down
1 change: 1 addition & 0 deletions src/aliceVision/fuseCut/Fuser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <aliceVision/mvsUtils/common.hpp>
#include <aliceVision/mvsUtils/fileIO.hpp>
#include <aliceVision/mvsData/imageIO.hpp>
#include <aliceVision/mvsData/imageAlgo.hpp>

#include <boost/filesystem.hpp>
#include <boost/accumulators/accumulators.hpp>
Expand Down
50 changes: 29 additions & 21 deletions src/aliceVision/mesh/Texturing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <aliceVision/mvsData/Pixel.hpp>
#include <aliceVision/mvsData/Image.hpp>
#include <aliceVision/mvsData/imageIO.hpp>
#include <aliceVision/mvsData/imageAlgo.hpp>

#include <geogram/basic/common.h>
#include <geogram/basic/geometry_nd.h>
Expand Down Expand Up @@ -273,14 +274,14 @@ void Texturing::generateTextures(const mvsUtils::MultiViewParams &mp,
{
ALICEVISION_LOG_INFO(" - " << c);
}

std::partial_sum(m.begin(), m.end(), m.begin());

mvsUtils::ImagesCache imageCache(&mp, 0, imageIO::EImageColorSpace::SRGB);
ALICEVISION_LOG_INFO("Texturing in " + imageIO::EImageColorSpace_enumToString(texParams.processColorspace) + " colorspace.");
mvsUtils::ImagesCache imageCache(&mp, 0, texParams.processColorspace);
imageCache.setCacheSize(2);
system::MemoryInfo memInfo = system::getMemoryInfo();

//calculate the maximum number of atlases in memory in Mb
system::MemoryInfo memInfo = system::getMemoryInfo();
const std::size_t atlasContribMemSize = texParams.textureSide * texParams.textureSide * (sizeof(Color)+sizeof(int)) / std::pow(2,20); //Mb
const std::size_t imageMaxMemSize = mp.getMaxImageWidth() * mp.getMaxImageHeight() * sizeof(Color) / std::pow(2,20); //Mb
const std::size_t pyramidMaxMemSize = texParams.nbBand * atlasContribMemSize;
Expand Down Expand Up @@ -481,7 +482,6 @@ void Texturing::generateTexturesSubSet(const mvsUtils::MultiViewParams& mp,
ALICEVISION_LOG_INFO("- camera " << mp.getViewId(camId) << " (" << camId + 1 << "/" << mp.ncams << ") with contributions to " << cameraContributions.size() << " texture files:");

//Load camera image from cache
imageCache.refreshData(camId);
mvsUtils::ImagesCache::ImgSharedPtr imgPtr = imageCache.getImg_sync(camId);
const Image& camImg = *imgPtr;

Expand Down Expand Up @@ -605,26 +605,34 @@ void Texturing::generateTexturesSubSet(const mvsUtils::MultiViewParams& mp,
#if TEXTURING_MBB_DEBUG
{
// write the number of contribution per atlas frequency bands
for(std::size_t level = 0; level < accuPyramid.pyramid.size(); ++level)
if(!texParams.useScore)
{
AccuImage& atlasLevelTexture = accuPyramid.pyramid[level];
for(std::size_t level = 0; level < accuPyramid.pyramid.size(); ++level)
{
AccuImage& atlasLevelTexture = accuPyramid.pyramid[level];

//write the number of contributions for each texture
std::vector<float> imgContrib(textureSize);
//write the number of contributions for each texture
std::vector<float> imgContrib(textureSize);

for(unsigned int yp = 0; yp < texParams.textureSide; ++yp)
{
unsigned int yoffset = yp * texParams.textureSide;
for(unsigned int xp = 0; xp < texParams.textureSide; ++xp)
for(unsigned int yp = 0; yp < texParams.textureSide; ++yp)
{
unsigned int xyoffset = yoffset + xp;
imgContrib[xyoffset] = atlasLevelTexture.imgCount[xyoffset];
unsigned int yoffset = yp * texParams.textureSide;
for(unsigned int xp = 0; xp < texParams.textureSide; ++xp)
{
unsigned int xyoffset = yoffset + xp;
imgContrib[xyoffset] = atlasLevelTexture.imgCount[xyoffset];
}
}
}

const std::string textureName = "contrib_" + std::to_string(1001 + atlasID) + std::string("_") + std::to_string(level) + std::string(".") + EImageFileType_enumToString(textureFileType); // starts at '1001' for UDIM compatibility
bfs::path texturePath = outPath / textureName;
imageIO::writeImage(texturePath.string(), texParams.textureSide, texParams.textureSide, imgContrib, imageIO::EImageQuality::OPTIMIZED, imageIO::EImageColorSpace::AUTO);
const std::string textureName = "contrib_" + std::to_string(1001 + atlasID) + std::string("_") + std::to_string(level) + std::string(".") + EImageFileType_enumToString(textureFileType); // starts at '1001' for UDIM compatibility
bfs::path texturePath = outPath / textureName;

using namespace imageIO;
OutputFileColorSpace colorspace(EImageColorSpace::SRGB, EImageColorSpace::AUTO);
if(texParams.convertLAB)
colorspace.from = EImageColorSpace::LAB;
writeImage(texturePath.string(), texParams.textureSide, texParams.textureSide, imgContrib, EImageQuality::OPTIMIZED, colorspace);
}
}
}
#endif
Expand Down Expand Up @@ -799,7 +807,7 @@ void Texturing::writeTexture(AccuImage& atlasTexture, const std::size_t atlasID,
alphaBuffer[xyoffset] = atlasTexture.imgCount[xyoffset] ? 1 : 0;
}
}
imageIO::fillHoles(atlasTexture.img, alphaBuffer);
imageAlgo::fillHoles(atlasTexture.img, alphaBuffer);
alphaBuffer.clear();
}

Expand All @@ -809,7 +817,7 @@ void Texturing::writeTexture(AccuImage& atlasTexture, const std::size_t atlasID,
Image resizedColorBuffer;

ALICEVISION_LOG_INFO(" - Downscaling texture (" << texParams.downscale << "x).");
imageIO::resizeImage(texParams.downscale, atlasTexture.img, resizedColorBuffer);
imageAlgo::resizeImage(texParams.downscale, atlasTexture.img, resizedColorBuffer);
std::swap(resizedColorBuffer, atlasTexture.img);
}

Expand All @@ -818,7 +826,7 @@ void Texturing::writeTexture(AccuImage& atlasTexture, const std::size_t atlasID,
ALICEVISION_LOG_INFO(" - Writing texture file: " << texturePath.string());

using namespace imageIO;
OutputFileColorSpace colorspace(EImageColorSpace::SRGB, EImageColorSpace::AUTO);
OutputFileColorSpace colorspace(texParams.processColorspace, EImageColorSpace::AUTO);
writeImage(texturePath.string(), atlasTexture.img, EImageQuality::OPTIMIZED, colorspace);
}

Expand Down
1 change: 1 addition & 0 deletions src/aliceVision/mesh/Texturing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct TexturingParams
unsigned int nbBand = 4;
unsigned int multiBandDownscale = 4;
std::vector<int> multiBandNbContrib = {1, 5, 10, 0}; // number of contributions per frequency band for the multi-band blending
imageIO::EImageColorSpace processColorspace = imageIO::EImageColorSpace::SRGB; // colorspace for the texturing internal computation

double bestScoreThreshold = 0.1; //< 0.0 to disable filtering based on threshold to relative best score
double angleHardThreshold = 90.0; //< 0.0 to disable angle hard threshold filtering
Expand Down
2 changes: 2 additions & 0 deletions src/aliceVision/mvsData/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(mvsData_files_headers
Image.hpp
geometry.hpp
geometryTriTri.hpp
imageAlgo.hpp
imageIO.hpp
jetColorMap.hpp
Matrix3x3.hpp
Expand All @@ -25,6 +26,7 @@ set(mvsData_files_headers
set(mvsData_files_sources
jetColorMap.cpp
Image.cpp
imageAlgo.cpp
imageIO.cpp
geometry.cpp
geometryTriTri.cpp
Expand Down
3 changes: 2 additions & 1 deletion src/aliceVision/mvsData/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Image.hpp"

#include <aliceVision/mvsData/imageIO.hpp>
#include <aliceVision/mvsData/imageAlgo.hpp>


namespace aliceVision{
Expand Down Expand Up @@ -39,7 +40,7 @@ void Image::laplacianPyramid(std::vector<Image>& out_pyramidL, int nbBand, unsig
//Create Laplacian pyramid
for(int b = 0; b < nbBand-1; ++b)
{
imageIO::resizeImage(static_cast<int>(downscale), img, imgDownscaled, "gaussian");
imageAlgo::resizeImage(static_cast<int>(downscale), img, imgDownscaled, "gaussian");
img.imageDiff(imgDownscaled, out_pyramidL[b], downscale);
img.swap(imgDownscaled);
/*
Expand Down
Loading