Skip to content

Commit

Permalink
[Apps] handle very high intensities
Browse files Browse the repository at this point in the history
  • Loading branch information
servantftechnicolor committed Sep 11, 2020
1 parent fb1e41d commit 91c1016
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/aliceVision/image/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,12 @@ void writeImage(const std::string& path,
oiio::ImageBuf formatBuf; // buffer for image format modification
if(isEXR)
{
formatBuf.copy(*outBuf, oiio::TypeDesc::HALF); // override format, use half instead of float
outBuf = &formatBuf;
int useFullFloat = imageSpec.get_int_attribute("AliceVision:useFullFloat", 0);

if (!useFullFloat) {
formatBuf.copy(*outBuf, oiio::TypeDesc::HALF); // override format, use half instead of float
outBuf = &formatBuf;
}
}

// write image
Expand Down
11 changes: 11 additions & 0 deletions src/software/pipeline/main_LdrToHdrMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ std::string getHdrImagePath(const std::string& outputPath, std::size_t g)
return hdrImagePath;
}

bool isOverflow(const image::Image<image::RGBfColor> & input) {
const float maxHalfFloat = 65504.0f;
return (input.maxCoeff() > maxHalfFloat);
}

int aliceVision_main(int argc, char** argv)
{
std::string verboseLevel = system::EVerboseLevel_enumToString(system::Logger::getDefaultVerboseLevel());
Expand Down Expand Up @@ -287,6 +292,12 @@ int aliceVision_main(int argc, char** argv)

// Write an image with parameters from the target view
oiio::ParamValueList targetMetadata = image::readImageMetadata(targetView->getImagePath());

if (isOverflow(HDRimage))
{
targetMetadata.push_back(oiio::ParamValue("AliceVision:useFullFloat", int(1)));
}

image::writeImage(hdrImagePath, HDRimage, image::EImageColorSpace::AUTO, targetMetadata);
}

Expand Down
16 changes: 16 additions & 0 deletions src/software/pipeline/main_panoramaCompositing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ typedef struct {
std::string weights_path;
} ConfigView;

bool isOverflow(const image::Image<image::RGBAfColor> & input) {
const float maxHalfFloat = 65504.0f;
return (input.maxCoeff() > maxHalfFloat);
}

/**
* @brief Maxflow computation based on a standard Adjacency List graph reprensentation.
*
Expand Down Expand Up @@ -1842,6 +1847,10 @@ class GraphcutSeams {
if (((mask(i, j) & 1) && (mask(i + 1, j) & 2)) || ((mask(i, j) & 2) && (mask(i + 1, j) & 1))) {
float d1 = (color_label(i, j) - color_other(i, j)).norm();
float d2 = (color_label(i + 1, j) - color_other(i + 1, j)).norm();

d1 = std::min(2.0f, d1);
d2 = std::min(2.0f, d2);

w = (d1 + d2) * 100.0 + 1.0;
}

Expand Down Expand Up @@ -2480,6 +2489,13 @@ int aliceVision_main(int argc, char **argv)
// Store output
ALICEVISION_LOG_INFO("Write output panorama to file " << outputPanorama);
const aliceVision::image::Image<image::RGBAfColor> & panorama = compositer->getPanorama();

oiio::ParamValueList view_metadata = outputMetadata;
if (isOverflow(panorama))
{
outputMetadata.push_back(oiio::ParamValue("AliceVision:useFullFloat", int(1)));
}

image::writeImage(outputPanorama, panorama, image::EImageColorSpace::AUTO, outputMetadata);

return EXIT_SUCCESS;
Expand Down
13 changes: 12 additions & 1 deletion src/software/pipeline/main_panoramaWarping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ namespace po = boost::program_options;
namespace bpt = boost::property_tree;
namespace fs = boost::filesystem;

bool isOverflow(const image::Image<image::RGBfColor> & input) {
const float maxHalfFloat = 65504.0f;
return (input.maxCoeff() > maxHalfFloat);
}

namespace SphericalMapping
{
/**
Expand Down Expand Up @@ -1197,9 +1202,15 @@ int aliceVision_main(int argc, char **argv)
{
const aliceVision::image::Image<image::RGBfColor> & cam = warper.getColor();

oiio::ParamValueList view_metadata = metadata;
if (isOverflow(cam))
{
view_metadata.push_back(oiio::ParamValue("AliceVision:useFullFloat", int(1)));
}

const std::string viewFilepath = (fs::path(outputDirectory) / (viewIdStr + ".exr")).string();
ALICEVISION_LOG_INFO("Store view " << i << " with path " << viewFilepath);
image::writeImage(viewFilepath, cam, image::EImageColorSpace::AUTO, metadata);
image::writeImage(viewFilepath, cam, image::EImageColorSpace::AUTO, view_metadata);
}
{
const aliceVision::image::Image<unsigned char> & mask = warper.getMask();
Expand Down

0 comments on commit 91c1016

Please sign in to comment.