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

[mesh] Texturing: Multi-band blending #629

Merged
merged 54 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
9152f4b
[mvsData] Create Image class
cvere Mar 22, 2019
5dfaf62
[mesh] Texturing: add missing reference
cvere Mar 22, 2019
84ee7ba
[mesh] texturing: create laplacian pyramid and recompose the image
cvere Mar 22, 2019
cf02002
[mvsUtils] ImageCache : function to setCacheSize
cvere Mar 29, 2019
885d38d
[mesh] Texturing : create laplacian pyramid from downscaled images
cvere Mar 29, 2019
6ea3306
[mvsData] Image : Color interpolation valid on borders
cvere Mar 29, 2019
f4e9ebb
[mvsData] Image : operators
cvere Mar 29, 2019
b124297
[mvsData] Image : difference between different sizes images
cvere Mar 29, 2019
94ac053
[mesh] Texturing : new function to write a texture + fix padding
cvere Mar 29, 2019
d7b38d1
[mesh] Texturing : memory management
cvere Mar 29, 2019
9160841
[mesh] Texturing : multiBandBlending
cvere Mar 29, 2019
553e178
[mesh] Texturing : debug mode
cvere Mar 29, 2019
4e3383d
[mesh] Texturing : delete sizeKernel & maxNbImagesForFusion
cvere Mar 29, 2019
95f373d
[mesh] Texturing : optimize padding
cvere Mar 29, 2019
7dc8eb6
[mesh] Texturing: add downscale param for multiband blending
cvere Apr 5, 2019
f41101e
[mesh] Texturing: add nbBand param for multiband blending
cvere Apr 5, 2019
35d33a7
[mesh] Texturing: keep margin in memory use
cvere Apr 5, 2019
fa0f07c
[mesh] Texturing : optimize texture padding
cvere Apr 5, 2019
d2f29dd
[mvsData] Image: handle invalid pixels in color interpolation
cvere Apr 5, 2019
77b549d
Merge remote-tracking branch 'origin/develop' into dev_multiBandBlending
cvere Apr 9, 2019
8e6b830
[mesh] Texturing : error fix
cvere Apr 12, 2019
19dac6f
[mesh] Texturing : final memory optimization
cvere Apr 12, 2019
770499e
[mesh] Texturing: taking triangles scores into account
cvere Apr 15, 2019
000aba7
[utils] New main to test multi-band blending
cvere Apr 26, 2019
22096c7
[mvsUtils] load images from cache in a chosen colorspace
cvere Apr 26, 2019
9a85cd0
[mesh] texturing: write textures from sRGB colorspace
cvere Apr 26, 2019
c7929e8
[imageIO] image: fix error
cvere Apr 26, 2019
e841b64
[mvsData] Image: fix color interpolation and resize functions
cvere Apr 26, 2019
70f7a75
[mesh] texturing: taking triangles scores into account
cvere Apr 26, 2019
3202d80
[mesh] Texturing: fix number of contributions for multi-band blending
cvere Apr 26, 2019
788705a
[imageIO] add OutputFileColorSpace struct
cvere Apr 26, 2019
3b0681e
[mesh] texturing: debug mode
cvere Apr 26, 2019
d3c8ca7
[mesh] texturing: fix padding
cvere Apr 26, 2019
69998ac
[mesh] texturing: change memory estimation
cvere Apr 26, 2019
94546a2
[mesh] texturing: add comments
cvere Apr 26, 2019
4d126bf
[samples] Move main_multibandtest to samples
yann-lty May 13, 2019
29c9e1d
[mesh] Texturing: set parameters for multi-band blending
cvere May 7, 2019
da08a26
[mesh] Texturing: add multiBandNbContrib param
cvere May 13, 2019
e503f75
[mesh] Texturing: add log infos, comments and delete useless variables
cvere May 14, 2019
6249819
[mesh] Texturing: add debug mode
cvere May 14, 2019
b488f2c
[mesh] Texturing: fix number of contributions per band
cvere May 14, 2019
bd89d50
[mesh] Texturing: handle "0"or illogical contributions for MBB
cvere May 14, 2019
01d9862
Texturing: merge MultiBandBlending class in Image class + clean code
cvere Jun 4, 2019
c4d3678
Merge imageIO module into mvsData/imageIO
cvere Jun 5, 2019
973af01
Merge mvsUtils::ImagesCache::Img class into mvsData::Image
cvere Jun 5, 2019
17a5d51
[mesh][mvsUtils] check if mesh triangles reproject correctly
cvere Jun 12, 2019
1531052
[mesh] Texturing: fix nbContribMax calculus
cvere Jun 12, 2019
850ca7a
[mesh] Texturing: bug fix on a shared_ptr
cvere Jun 12, 2019
118ed54
[mesh] Texturing: code cleaning & setting param default value
cvere Jun 12, 2019
7fdc82b
[mesh] Texturing: set bestScoreThreshold default value to 0.1
cvere Jun 13, 2019
d794c42
code cleaning on struct OutputFileColorSpace
cvere Jun 14, 2019
8bc2e79
Merge remote-tracking branch 'origin/develop' into dev_multiBandBlending
cvere Jun 18, 2019
9f189bc
Explicit constructor for OutputFileColorSpace struct & missing reference
cvere Jun 20, 2019
956df2a
Merge branch 'develop' into dev_multiBandBlending
cvere Jun 20, 2019
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
2 changes: 0 additions & 2 deletions src/aliceVision/mesh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ set(mesh_files_headers
MeshEnergyOpt.hpp
meshPostProcessing.hpp
meshVisibility.hpp
MultiBandBlending.hpp
Texturing.hpp
UVAtlas.hpp
)
Expand All @@ -20,7 +19,6 @@ set(mesh_files_sources
MeshEnergyOpt.cpp
meshPostProcessing.cpp
meshVisibility.cpp
MultiBandBlending.cpp
Texturing.cpp
UVAtlas.cpp
)
Expand Down
71 changes: 0 additions & 71 deletions src/aliceVision/mesh/MultiBandBlending.cpp

This file was deleted.

28 changes: 0 additions & 28 deletions src/aliceVision/mesh/MultiBandBlending.hpp

This file was deleted.

5 changes: 2 additions & 3 deletions src/aliceVision/mesh/Texturing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include <aliceVision/mvsData/Color.hpp>
#include <aliceVision/mvsData/geometry.hpp>
#include <aliceVision/mvsData/Pixel.hpp>
#include <aliceVision/mvsData/Image.hpp>
#include <aliceVision/imageIO/image.hpp>
#include <aliceVision/mesh/MultiBandBlending.hpp>

#include <geogram/basic/common.h>
#include <geogram/basic/geometry_nd.h>
Expand Down Expand Up @@ -488,9 +488,8 @@ void Texturing::generateTexturesSubSet(const mvsUtils::MultiViewParams& mp,
Image camImg(imgPtr->data, imgPtr->getWidth(), imgPtr->getHeight());

//Calculate laplacianPyramid
MultiBandBlending multiBandBlending;
std::vector<Image> pyramidL; //laplacian pyramid
multiBandBlending.laplacianDownscalePyramid(pyramidL, camImg, texParams.nbBand, texParams.multiBandDownscale);
camImg.laplacianPyramid(pyramidL, texParams.nbBand, texParams.multiBandDownscale);

// for each output texture file
for(const auto& c : cameraContributions)
Expand Down
3 changes: 3 additions & 0 deletions src/aliceVision/mvsData/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ set(mvsData_files_headers
# Sources
set(mvsData_files_sources
jetColorMap.cpp
Image.cpp
imageIO.cpp
geometry.cpp
geometryTriTri.cpp
Expand All @@ -39,7 +40,9 @@ alicevision_add_library(aliceVision_mvsData
aliceVision_system
${ZLIB_LIBRARIES}
${Boost_FILESYSTEM_LIBRARY}
${OPENIMAGEIO_LIBRARIES}
PUBLIC_INCLUDE_DIRS
${ZLIB_INCLUDE_DIR}
${Boost_INCLUDE_DIR}
${OPENIMAGEIO_INCLUDE_DIRS}
)
87 changes: 87 additions & 0 deletions src/aliceVision/mvsData/Image.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// This file is part of the AliceVision project.
// Copyright (c) 2019 AliceVision contributors.
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#include "Image.hpp"

#include <aliceVision/imageIO/image.hpp>


namespace aliceVision{


void Image::imageDiff(Image& inImgDownscaled, Image& outImg, unsigned int downscale)
{
outImg.resize(_width, _height);
for(int i = 0; i < _width*_height; ++i)
{
Point2d pix(i%_width, static_cast<int>(i/_width));
Point2d pixd = pix/downscale;

outImg._img[i] = _img[i] - inImgDownscaled.getInterpolateColor(pixd);
}

}

void Image::laplacianPyramid(std::vector<Image>& out_pyramidL, int nbBand, unsigned int downscale)
{
assert(nbBand >= 1);

Image img(*this);
int outW = static_cast<int>(img.width()/downscale);
int outH = static_cast<int>(img.height()/downscale);

Image imgDownscaled(outW, outH);
out_pyramidL.resize(nbBand);

//Create Laplacian pyramid
for(int b = 0; b < nbBand-1; ++b)
{
imageIO::resizeImage(img.width(), img.height(), static_cast<int>(downscale), img.data(), imgDownscaled.data(), "gaussian");
img.imageDiff(imgDownscaled, out_pyramidL[b], downscale);
img.swap(imgDownscaled);

outW = static_cast<int>(outW/downscale);
outH = static_cast<int>(outH/downscale);
imgDownscaled.resize(outW, outH);

}
out_pyramidL[nbBand-1] = img;

for(std::size_t i = 0; i < out_pyramidL.size(); ++i)
ALICEVISION_LOG_DEBUG("laplacianDownscalePyramid: Size level " << i << " : " << out_pyramidL[i].width() << "x" << out_pyramidL[i].height());
}

Color Image::getInterpolateColor(const Point2d& pix) const
{
const int xp = std::min(static_cast<int>(pix.x), _width-2);
const int yp = std::min(static_cast<int>(pix.y), _height-2);

// precision to 4 decimal places
const float ui = pix.x - static_cast<float>(xp);
const float vi = pix.y - static_cast<float>(yp);

const Color lu = _img.at( yp * _width + xp );
const Color ru = _img.at( yp * _width + (xp+1) );
const Color rd = _img.at( (yp+1) * _width + (xp+1) );
const Color ld = _img.at( (yp+1) * _width + xp );

// bilinear interpolation of the pixel intensity value
const Color u = lu + (ru - lu) * ui;
const Color d = ld + (rd - ld) * ui;
const Color out = u + (d - u) * vi;
return out;
}

Color Image::getNearestPixelColor(const Point2d& pix) const
{
const int xp = std::min(static_cast<int>(pix.x), _width-1);
const int yp = std::min(static_cast<int>(pix.y), _height-1);
const Color lu = _img.at( yp * _width + xp );
return lu;
}


}
95 changes: 23 additions & 72 deletions src/aliceVision/mvsData/Image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include <aliceVision/mvsData/Color.hpp>
#include <aliceVision/mvsData/StaticVector.hpp>
#include <aliceVision/mvsUtils/ImagesCache.hpp>
#include <aliceVision/mvsData/Point2d.hpp>

#include <algorithm>
Expand All @@ -19,15 +18,11 @@ class Image
{
private:
std::vector<Color> _img;
int _width = 0;
int _height = 0;
int _width{0};
int _height{0};

public:
Image()
{
_width = 0;
_height = 0;
}
Image() = default;

Image(int width, int height)
: _width(width)
Expand All @@ -36,12 +31,8 @@ class Image
_img.resize(width*height);
}

Image(Color* data, int width, int height)
Image(Color* data, int width, int height) : Image(width, height)
{
_width = width;
_height = height;
_img.resize(_width * _height);

for(int i = 0; i < _width*_height; ++i)
_img[i] = data[i];
}
Expand Down Expand Up @@ -80,35 +71,6 @@ class Image
return *this;
}

//outImg = inImga - inImgb
static void imageDiff(const Image& inImga, const Image& inImgb, Image& outImg)
{
if(inImga._width != inImgb._width || inImga._height != inImgb._height)
throw std::runtime_error("Incompatible image sizes");

outImg.resize(inImga._width, inImga._height);
for(int i = 0; i < inImga._width*inImga._height; ++i)
{
outImg._img[i] = inImga._img.at(i) - inImgb._img.at(i);
}
}

static void imageDownscaleDiff(Image& inImga, Image& inImgb, Image& outImg, unsigned int downscale)
{
//inImga = largest image
if(inImga.height() < inImgb.height())
inImga.swap(inImgb);

outImg.resize(inImga._width, inImga._height);
for(int i = 0; i < inImga._width*inImga._height; ++i)
{
Point2d pix(i%inImga.width(), static_cast<int>(i/inImga.width()));
Point2d pixd = pix/downscale;

outImg._img[i] = inImga._img[i] - inImgb.getInterpolateColor(pixd);
}

}

int width() const { return _width; }
int height() const { return _height; }
Expand All @@ -119,38 +81,27 @@ class Image
const Color& operator[](std::size_t index) const { return _img[index]; }
Color& operator[](std::size_t index) { return _img[index]; }

Color getInterpolateColor(const Point2d& pix) const
{
const int xp = std::min(static_cast<int>(pix.x), _width-2);
const int yp = std::min(static_cast<int>(pix.y), _height-2);

// precision to 4 decimal places
const float ui = pix.x - static_cast<float>(xp);
const float vi = pix.y - static_cast<float>(yp);

const Color lu = _img.at( yp * _width + xp );
const Color ru = _img.at( yp * _width + (xp+1) );
const Color rd = _img.at( (yp+1) * _width + (xp+1) );
const Color ld = _img.at( (yp+1) * _width + xp );

// bilinear interpolation of the pixel intensity value
const Color u = lu + (ru - lu) * ui;
const Color d = ld + (rd - ld) * ui;
const Color out = u + (d - u) * vi;
return out;
}

Color getNearestPixelColor(const Point2d& pix) const
{
const int xp = std::min(static_cast<int>(pix.x), _width-1);
const int yp = std::min(static_cast<int>(pix.y), _height-1);
const Color lu = _img.at( yp * _width + xp );
return lu;
}
};
Color getInterpolateColor(const Point2d& pix) const;
Color getNearestPixelColor(const Point2d& pix) const;

/**
* @brief Calculate the difference between images of different sizes
* @param [inImgDownscaled] the smaller image
* @param [outImg] the difference
* @param [downscale] the downscale coefficient between image sizes
*/
void imageDiff(Image& inImgDownscaled, Image& outImg, unsigned int downscale);

}
/**
* @brief Calculate the laplacian pyramid of a given image,
* ie. its decomposition in frequency bands
* @param [out_pyramidL] the laplacian pyramid
* @param [nbBand] the number of frequency bands
* @param [downscale] the downscale coefficient between floors of the pyramid
*/
void laplacianPyramid(std::vector<Image>& out_pyramidL, int nbBand, unsigned int downscale);


};

}
1 change: 0 additions & 1 deletion src/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ add_subdirectory(featuresRepeatability)
# add_subdirectory(imageData)
add_subdirectory(imageDescriberMatches)
add_subdirectory(kvldFilter)
add_subdirectory(multiBandBlending)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a mistake as the sample itself is not removed...

add_subdirectory(robustEssential)
add_subdirectory(robustEssentialBA)
add_subdirectory(robustEssentialSpherical)
Expand Down