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

HDR luminance statistics bugfix #1353

Merged
merged 3 commits into from
Feb 20, 2023
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
16 changes: 11 additions & 5 deletions src/aliceVision/hdr/brackets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,20 @@ void selectTargetViews(std::vector<std::shared_ptr<sfmData::View>> & out_targetV
{
lines.push_back(line);
}
if ((lines.size() < 3) || (std::stoi(lines[0].c_str()) != groups.size()) || (std::stoi(lines[1].c_str()) < groups[0].size()))
if ((lines.size() < 3) || (std::stoi(lines[0]) != groups.size()) || (std::stoi(lines[1]) < groups[0].size()) ||
(lines.size() < 3 + std::stoi(lines[0]) * std::stoi(lines[1])))
{
ALICEVISION_THROW_ERROR("File: " << lumaStatFilepath << " is not a valid file");
}
int nbGroup = std::stoi(lines[0].c_str());
int nbExp = std::stoi(lines[1].c_str());
int nbGroup = std::stoi(lines[0]);
int nbExp = std::stoi(lines[1]);

std::vector<double> v_lumaMeanMean;

for (int i = 0; i < nbExp; ++i)
{
double lumaMeanMean = 0.0;
double nbValidViews = 0;
for (int j = 0; j < nbGroup; ++j)
{
std::istringstream iss(lines[3 + j * nbExp + i]);
Expand All @@ -176,9 +178,13 @@ void selectTargetViews(std::vector<std::shared_ptr<sfmData::View>> & out_targetV
{
ALICEVISION_THROW_ERROR("File: " << lumaStatFilepath << " is not a valid file");
}
lumaMeanMean += lumaMean;
if (exposure > 0.0) // discard dummy luminance info (with exposure set to -1.0) added at calibration stage if samples are missing for a view
{
lumaMeanMean += lumaMean;
++nbValidViews;
}
}
v_lumaMeanMean.push_back(lumaMeanMean / nbGroup);
v_lumaMeanMean.push_back(lumaMeanMean / nbValidViews);
}

// adjust last index to avoid non increasing luminance curve due to saturation in highlights
Expand Down
20 changes: 19 additions & 1 deletion src/software/pipeline/main_LdrToHdrCalibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,17 @@ int aliceVision_main(int argc, char** argv)
std::map<int, luminanceInfo> luminanceInfos;
computeLuminanceStatFromSamples(samples, luminanceInfos);

// Check that all views in the group have an associated luminance stat info
for (const auto& v : group)
{
if (luminanceInfos.find(v->getViewId()) == luminanceInfos.end())
{
luminanceInfo lumaInfo;
lumaInfo.exposure = -1.0; // Dummy exposure used later indicating a dummy info
luminanceInfos[v->getViewId()] = lumaInfo;
}
}

v_luminanceInfos.push_back(luminanceInfos);

++group_pos;
Expand Down Expand Up @@ -452,7 +463,14 @@ int aliceVision_main(int argc, char** argv)
// write in file
file << srcIdWithMinimalExposure << " ";
file << v_luminanceInfos[i][srcIdWithMinimalExposure].exposure << " " << v_luminanceInfos[i][srcIdWithMinimalExposure].itemNb << " ";
file << v_luminanceInfos[i][srcIdWithMinimalExposure].meanLum / v_luminanceInfos[i][srcIdWithMinimalExposure].itemNb << " ";
if (v_luminanceInfos[i][srcIdWithMinimalExposure].itemNb > 0)
{
file << v_luminanceInfos[i][srcIdWithMinimalExposure].meanLum / v_luminanceInfos[i][srcIdWithMinimalExposure].itemNb << " ";
}
else
{
file << "0.0 ";
}
file << v_luminanceInfos[i][srcIdWithMinimalExposure].minLum << " " << v_luminanceInfos[i][srcIdWithMinimalExposure].maxLum << std::endl;
// erase from map
v_luminanceInfos[i].erase(srcIdWithMinimalExposure);
Expand Down