From 57c7e701acf2b0d5502df4f19375976f34fa0029 Mon Sep 17 00:00:00 2001 From: demoulinv Date: Fri, 6 Jan 2023 18:11:13 +0100 Subject: [PATCH 1/2] [dcp error and HDR parameters] Throw an error instead of a warning when trying to load a non existing DCP profile. rawColorInterpretation: In cameraInit, automatically switch to librawWhiteBalancing mode when a DCP profile is required but no error is requested if it is missing and no database or an erroneous one is given as parameter or if the expected profile does not exist in the database. Add working color space as a parameter in sampling and merging HDR exec. --- src/aliceVision/image/dcp.cpp | 3 +-- src/software/pipeline/main_LdrToHdrMerge.cpp | 5 +++- .../pipeline/main_LdrToHdrSampling.cpp | 5 +++- src/software/pipeline/main_cameraInit.cpp | 27 ++++++++++++++----- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/aliceVision/image/dcp.cpp b/src/aliceVision/image/dcp.cpp index 093c649712..8950196cca 100644 --- a/src/aliceVision/image/dcp.cpp +++ b/src/aliceVision/image/dcp.cpp @@ -955,8 +955,7 @@ void DCPProfile::Load(const std::string& filename) if (file == nullptr) { - ALICEVISION_LOG_WARNING("Unable to load DCP profile " << filename); - return; + ALICEVISION_THROW_ERROR("Unable to load DCP profile " << filename); } // read tiff header diff --git a/src/software/pipeline/main_LdrToHdrMerge.cpp b/src/software/pipeline/main_LdrToHdrMerge.cpp index 76e7bedef0..879c9c3bf5 100644 --- a/src/software/pipeline/main_LdrToHdrMerge.cpp +++ b/src/software/pipeline/main_LdrToHdrMerge.cpp @@ -54,6 +54,7 @@ int aliceVision_main(int argc, char** argv) int nbBrackets = 3; bool byPass = false; int channelQuantizationPower = 10; + image::EImageColorSpace workingColorSpace = image::EImageColorSpace::SRGB; int offsetRefBracketIndex = 0; hdr::EFunctionType fusionWeightFunction = hdr::EFunctionType::GAUSSIAN; @@ -83,6 +84,8 @@ int aliceVision_main(int argc, char** argv) "bypass HDR creation and use medium bracket as input for next steps") ("channelQuantizationPower", po::value(&channelQuantizationPower)->default_value(channelQuantizationPower), "Quantization level like 8 bits or 10 bits.") + ("workingColorSpace", po::value(&workingColorSpace)->default_value(workingColorSpace), + ("Working color space: " + image::EImageColorSpace_informations()).c_str()) ("fusionWeight,W", po::value(&fusionWeightFunction)->default_value(fusionWeightFunction), "Weight function used to fuse all LDR images together (gaussian, triangle, plateau).") ("offsetRefBracketIndex", po::value(&offsetRefBracketIndex)->default_value(offsetRefBracketIndex), @@ -253,7 +256,7 @@ int aliceVision_main(int argc, char** argv) ALICEVISION_LOG_INFO("Load " << filepath); image::ImageReadOptions options; - options.workingColorSpace = image::EImageColorSpace::SRGB; + options.workingColorSpace = workingColorSpace; options.rawColorInterpretation = image::ERawColorInterpretation_stringToEnum(group[i]->getRawColorInterpretation()); options.colorProfileFileName = group[i]->getColorProfileFileName(); image::readImage(filepath, images[i], options); diff --git a/src/software/pipeline/main_LdrToHdrSampling.cpp b/src/software/pipeline/main_LdrToHdrSampling.cpp index 1c492b7416..e412d64a91 100644 --- a/src/software/pipeline/main_LdrToHdrSampling.cpp +++ b/src/software/pipeline/main_LdrToHdrSampling.cpp @@ -54,6 +54,7 @@ int aliceVision_main(int argc, char** argv) std::string outputFolder; int nbBrackets = 0; int channelQuantizationPower = 10; + image::EImageColorSpace workingColorSpace = image::EImageColorSpace::SRGB; hdr::Sampling::Params params; bool debug = false; @@ -75,6 +76,8 @@ int aliceVision_main(int argc, char** argv) "bracket count per HDR image (0 means automatic).") ("channelQuantizationPower", po::value(&channelQuantizationPower)->default_value(channelQuantizationPower), "Quantization level like 8 bits or 10 bits.") + ("workingColorSpace", po::value(&workingColorSpace)->default_value(workingColorSpace), + ("Working color space: " + image::EImageColorSpace_informations()).c_str()) ("blockSize", po::value(¶ms.blockSize)->default_value(params.blockSize), "Size of the image tile to extract a sample.") ("radius", po::value(¶ms.radius)->default_value(params.radius), @@ -209,7 +212,7 @@ int aliceVision_main(int argc, char** argv) std::vector exposures = getExposures(exposuresSetting); image::ImageReadOptions imgReadOptions; - imgReadOptions.workingColorSpace = image::EImageColorSpace::SRGB; + imgReadOptions.workingColorSpace = workingColorSpace; imgReadOptions.rawColorInterpretation = rawColorInterpretation; imgReadOptions.colorProfileFileName = colorProfileFileName; diff --git a/src/software/pipeline/main_cameraInit.cpp b/src/software/pipeline/main_cameraInit.cpp index 40d14b0e04..91561228c7 100644 --- a/src/software/pipeline/main_cameraInit.cpp +++ b/src/software/pipeline/main_cameraInit.cpp @@ -162,7 +162,7 @@ int aliceVision_main(int argc, char **argv) bool allowSingleView = false; bool errorOnMissingColorProfile = true; - image::ERawColorInterpretation rawColorInterpretation = image::ERawColorInterpretation::LibRawNoWhiteBalancing; + image::ERawColorInterpretation rawColorInterpretation = image::ERawColorInterpretation::LibRawWhiteBalancing; po::options_description requiredParams("Required parameters"); @@ -452,6 +452,8 @@ int aliceVision_main(int argc, char **argv) std::string imgFormat = in->format_name(); + bool dcpError = false; + // if a color profile is required check if a dcp database exists and if one is available inside // if yes and if metadata exist and image format is raw then update metadata with DCP info if((rawColorInterpretation == image::ERawColorInterpretation::DcpLinearProcessing || @@ -465,7 +467,7 @@ int aliceVision_main(int argc, char **argv) // No color profile available boost::atomic_ref{allColorProfilesFound} = 0; } - else if (!dcpDatabase.empty()) + else if (!dcpDatabase.empty() || (dcpDatabase.empty() && !errorOnMissingColorProfile)) { image::DCPProfile dcpProf; @@ -476,17 +478,29 @@ int aliceVision_main(int argc, char **argv) #pragma omp critical viewsWithDCPMetadata++; } - else if (allColorProfilesFound) + else { - // there is a missing color profile for one image or more - boost::atomic_ref{allColorProfilesFound} = 0; + dcpError = true; + if (allColorProfilesFound) + { + // there is a missing color profile for one image or more + boost::atomic_ref{allColorProfilesFound} = 0; + } } } } // Store the color interpretation mode choosed for raw images in metadata, // so all future loads of this image will be interpreted in the same way. - view.addMetadata("AliceVision:rawColorInterpretation", image::ERawColorInterpretation_enumToString(rawColorInterpretation)); + if (!dcpError) + { + view.addMetadata("AliceVision:rawColorInterpretation", image::ERawColorInterpretation_enumToString(rawColorInterpretation)); + } + else + { + view.addMetadata("AliceVision:rawColorInterpretation", image::ERawColorInterpretation_enumToString(image::ERawColorInterpretation::LibRawWhiteBalancing)); + ALICEVISION_LOG_WARNING("DCP Profile not found. Use LibRawWhiteBalancing option for raw color processing."); + } // check if the view intrinsic is already defined if(intrinsicId != UndefinedIndexT) @@ -752,6 +766,7 @@ int aliceVision_main(int argc, char **argv) else { ALICEVISION_LOG_WARNING("Can't find color profile for at least one input image."); + ALICEVISION_LOG_WARNING("Images without color profiles have been decoded with the LibRawWhiteBalancing option."); } } From eb675da156f8d7d88b53077aa2e54fcc00d29557 Mon Sep 17 00:00:00 2001 From: demoulinv Date: Mon, 9 Jan 2023 11:35:19 +0100 Subject: [PATCH 2/2] [cameraInit] Code adjustment --- src/software/pipeline/main_cameraInit.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/software/pipeline/main_cameraInit.cpp b/src/software/pipeline/main_cameraInit.cpp index 91561228c7..8893a47896 100644 --- a/src/software/pipeline/main_cameraInit.cpp +++ b/src/software/pipeline/main_cameraInit.cpp @@ -452,7 +452,7 @@ int aliceVision_main(int argc, char **argv) std::string imgFormat = in->format_name(); - bool dcpError = false; + bool dcpError = true; // if a color profile is required check if a dcp database exists and if one is available inside // if yes and if metadata exist and image format is raw then update metadata with DCP info @@ -467,26 +467,25 @@ int aliceVision_main(int argc, char **argv) // No color profile available boost::atomic_ref{allColorProfilesFound} = 0; } - else if (!dcpDatabase.empty() || (dcpDatabase.empty() && !errorOnMissingColorProfile)) + else { image::DCPProfile dcpProf; - if (dcpDatabase.getDcpForCamera(make, model, dcpProf)) + if (!dcpDatabase.empty() && dcpDatabase.getDcpForCamera(make, model, dcpProf)) { view.addDCPMetadata(dcpProf); #pragma omp critical viewsWithDCPMetadata++; + + dcpError = false; } - else + else if (allColorProfilesFound) { - dcpError = true; - if (allColorProfilesFound) - { - // there is a missing color profile for one image or more - boost::atomic_ref{allColorProfilesFound} = 0; - } + // there is a missing color profile for at least one image + boost::atomic_ref{allColorProfilesFound} = 0; } + } } @@ -499,7 +498,8 @@ int aliceVision_main(int argc, char **argv) else { view.addMetadata("AliceVision:rawColorInterpretation", image::ERawColorInterpretation_enumToString(image::ERawColorInterpretation::LibRawWhiteBalancing)); - ALICEVISION_LOG_WARNING("DCP Profile not found. Use LibRawWhiteBalancing option for raw color processing."); + if (!dcpDatabase.empty()) + ALICEVISION_LOG_WARNING("DCP Profile not found for image: " << view.getImagePath() << ". Use LibRawWhiteBalancing option for raw color processing."); } // check if the view intrinsic is already defined