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 storageDataType option #896

Merged
merged 2 commits into from
Sep 20, 2020
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
8 changes: 4 additions & 4 deletions src/aliceVision/image/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ std::string EStorageDataType_enumToString(const EStorageDataType dataType)
{
switch (dataType)
{
case EStorageDataType::Float: return "Float";
case EStorageDataType::Half: return "Half";
case EStorageDataType::HalfFinite: return "HalfFinite";
case EStorageDataType::Auto: return "Auto";
case EStorageDataType::Float: return "float";
case EStorageDataType::Half: return "half";
case EStorageDataType::HalfFinite: return "halfFinite";
case EStorageDataType::Auto: return "auto";
}
throw std::out_of_range("Invalid EStorageDataType enum");
}
Expand Down
20 changes: 16 additions & 4 deletions src/software/utils/main_imageProcessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,14 @@ void processImage(image::Image<image::RGBAfColor>& image, const ProcessingParams

void saveImage(image::Image<image::RGBAfColor>& image, const std::string& inputPath, const std::string& outputPath,
const std::vector<std::string>& metadataFolders,
const EImageFormat& outputFormat)
const EImageFormat outputFormat, const image::EStorageDataType storageDataType)
{
// Read metadata path
std::string metadataFilePath;

const std::string filename = fs::path(inputPath).filename().string();
const std::string outExtension = boost::to_lower_copy(fs::path(outputPath).extension().string());
const bool isEXR = (outExtension == ".exr");
// If metadataFolders is specified
if(!metadataFolders.empty())
{
Expand Down Expand Up @@ -496,7 +498,13 @@ void saveImage(image::Image<image::RGBAfColor>& image, const std::string& inputP
metadataFilePath = inputPath;
}

const oiio::ParamValueList metadata = image::readImageMetadata(metadataFilePath);
oiio::ParamValueList metadata = image::readImageMetadata(metadataFilePath);

if(isEXR)
{
// Select storage data type
metadata.push_back(oiio::ParamValue("AliceVision:storageDataType", image::EStorageDataType_enumToString(storageDataType)));
}

// Save image
ALICEVISION_LOG_TRACE("Export image: '" << outputPath << "'.");
Expand Down Expand Up @@ -528,6 +536,7 @@ int aliceVision_main(int argc, char * argv[])
std::vector<std::string> metadataFolders;
std::string outputPath;
EImageFormat outputFormat = EImageFormat::RGBA;
image::EStorageDataType storageDataType = image::EStorageDataType::Float;
std::string extension;

ProcessingParams pParams;
Expand Down Expand Up @@ -603,6 +612,9 @@ int aliceVision_main(int argc, char * argv[])

("outputFormat", po::value<EImageFormat>(&outputFormat)->default_value(outputFormat),
"Output image format (rgba, rgb, grayscale)")

("storageDataType", po::value<image::EStorageDataType>(&storageDataType)->default_value(storageDataType),
("Storage data type: " + image::EStorageDataType_informations()).c_str())

("extension", po::value<std::string>(&extension)->default_value(extension),
"Output image extension (like exr, or empty to keep the source file format.")
Expand Down Expand Up @@ -760,7 +772,7 @@ int aliceVision_main(int argc, char * argv[])
processImage(image, pParams);

// Save the image
saveImage(image, viewPath, outputfilePath, metadataFolders, outputFormat);
saveImage(image, viewPath, outputfilePath, metadataFolders, outputFormat, storageDataType);

// Update view for this modification
view.setImagePath(outputfilePath);
Expand Down Expand Up @@ -855,7 +867,7 @@ int aliceVision_main(int argc, char * argv[])
processImage(image, pParams);

// Save the image
saveImage(image, inputFilePath, outputFilePath, metadataFolders, outputFormat);
saveImage(image, inputFilePath, outputFilePath, metadataFolders, outputFormat, storageDataType);
}
}

Expand Down