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

[software] ImageProcessing: add option to fix non finite pixels #890

Merged
merged 1 commit into from
Sep 11, 2020
Merged
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
18 changes: 17 additions & 1 deletion src/software/utils/main_imageProcessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ struct ProcessingParams
float contrast = 1.0f;
int medianFilter = 0;
bool fillHoles = false;
bool fixNonFinite = false;

SharpenParams sharpen =
{
Expand Down Expand Up @@ -306,6 +307,17 @@ void processImage(image::Image<image::RGBAfColor>& image, const ProcessingParams
{
const unsigned int nchannels = 4;

// Fix non-finite pixels
// Note: fill holes needs to fix non-finite values first
if(pParams.fixNonFinite || pParams.fillHoles)
{
oiio::ImageBuf inBuf(oiio::ImageSpec(image.Width(), image.Height(), nchannels, oiio::TypeDesc::FLOAT), image.data());
int pixelsFixed = 0;
// Works inplace
oiio::ImageBufAlgo::fixNonFinite(inBuf, inBuf, oiio::ImageBufAlgo::NonFiniteFixMode::NONFINITE_BOX3, &pixelsFixed);
ALICEVISION_LOG_INFO("Fixed " << pixelsFixed << " non-finite pixels.");
}

if (pParams.scaleFactor != 1.0f)
{
const unsigned int w = image.Width();
Expand Down Expand Up @@ -421,12 +433,12 @@ void processImage(image::Image<image::RGBAfColor>& image, const ProcessingParams
throw std::invalid_argument( "Unsupported mode! If you intended to use a Clahe filter, please add OpenCV support.");
#endif
}

if(pParams.fillHoles)
{
image::Image<image::RGBAfColor> filtered(image.Width(), image.Height());
oiio::ImageBuf inBuf(oiio::ImageSpec(image.Width(), image.Height(), nchannels, oiio::TypeDesc::FLOAT), image.data());
oiio::ImageBuf outBuf(oiio::ImageSpec(image.Width(), image.Height(), nchannels, oiio::TypeDesc::FLOAT), filtered.data());

// Premult necessary to ensure that the fill holes works as expected
oiio::ImageBufAlgo::premult(inBuf, inBuf);
oiio::ImageBufAlgo::fillholes_pushpull(outBuf, inBuf);
Expand Down Expand Up @@ -541,6 +553,10 @@ int aliceVision_main(int argc, char * argv[])
"Use images metadata from specific folder(s) instead of those specified in the input images.")
("reconstructedViewsOnly", po::value<bool>(&pParams.reconstructedViewsOnly)->default_value(pParams.reconstructedViewsOnly),
"Process only recontructed views or all views.")

("fixNonFinite", po::value<bool>(&pParams.fixNonFinite)->default_value(pParams.fixNonFinite),
"Fill non-finite pixels.")

("scaleFactor", po::value<float>(&pParams.scaleFactor)->default_value(pParams.scaleFactor),
"Scale Factor (1.0: no change).")

Expand Down