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

Automatic reorientation #1585

Merged
merged 1 commit into from
Nov 6, 2023
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
26 changes: 26 additions & 0 deletions src/software/utils/main_imageProcessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ struct ProcessingParams
bool useDCPColorMatrixOnly = false;
bool enableColorTempProcessing = false;
double correlatedColorTemperature = -1.0;
bool reorient = false;

LensCorrectionParams lensCorrection =
{
Expand Down Expand Up @@ -603,6 +604,27 @@ void processImage(image::Image<image::RGBAfColor>& image, ProcessingParams& pPar
image.swap(rescaled);
}

if (pParams.reorient)
{
oiio::ImageBuf inBuf(oiio::ImageSpec(image.Width(), image.Height(), nchannels, oiio::TypeDesc::FLOAT), image.data());
inBuf.set_orientation(std::stoi(imageMetadata["Orientation"]));
oiio::ImageBuf outBuf = oiio::ImageBufAlgo::reorient(inBuf);

if (outBuf.spec().get_int_attribute("orientation") != inBuf.spec().get_int_attribute("orientation"))
{
imageMetadata.at("Orientation") = std::to_string(outBuf.spec().get_int_attribute("orientation"));

image::Image<image::RGBAfColor> reoriented(outBuf.spec().width, outBuf.spec().height);

oiio::ROI exportROI = outBuf.roi();
exportROI.chbegin = 0;
exportROI.chend = nchannels;
outBuf.get_pixels(exportROI, oiio::TypeDesc::FLOAT, reoriented.data());

image.swap(reoriented);
}
}

if (pParams.contrast != 1.0f)
{
image::Image<image::RGBAfColor> filtered(image.Width(), image.Height());
Expand Down Expand Up @@ -1090,6 +1112,9 @@ int aliceVision_main(int argc, char * argv[])
("sensorDatabase,s", po::value<std::string>(&sensorDatabasePath)->default_value(""),
"Camera sensor width database path.")

("reorient", po::value<bool>(&pParams.reorient)->default_value(pParams.reorient),
"Enable automatic reorientation of images.")

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

Expand Down Expand Up @@ -1359,6 +1384,7 @@ int aliceVision_main(int argc, char * argv[])
view.getImage().setWidth(image.Width());
view.getImage().setHeight(image.Height());
view.getImage().addMetadata("AliceVision:ColorSpace", image::EImageColorSpace_enumToString(outputColorSpace));
view.getImage().addMetadata("Orientation", viewMetadata.at("Orientation"));
}

if (pParams.scaleFactor != 1.0f)
Expand Down
Loading