Skip to content

Commit

Permalink
augment contaminated brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
servantftechnicolor committed Oct 1, 2024
1 parent f625b25 commit 0bf77b0
Showing 1 changed file with 82 additions and 7 deletions.
89 changes: 82 additions & 7 deletions src/aliceVision/hdr/brackets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,42 @@ std::vector<std::vector<LuminanceInfo>> splitMonotonics(const std::vector<Lumina
return splitted;
}

/**
* @brief assume ref is smaller than larger
* Try to find a subpart of larger which has the same set of exposures that smaller
* @param smaller the set to compare
* @param larger the set where the subpart should be
* @return the index of the subpart or -1 if not found
*/
int extractIndex(const std::vector<LuminanceInfo> & smaller, const std::vector<LuminanceInfo> & larger)
{
int largerSize = larger.size();
int smallerSize = smaller.size();
int diff = largerSize - smallerSize;

//For all continuous subparts of the erased sequence
for (int indexStart = 0; indexStart < diff; indexStart++)
{
//Check that the subpart is the same set of exposures
bool allCorrect = true;
for (int pos = 0; pos < smallerSize; pos++)
{
if (smaller[pos].mexposure != larger[indexStart + pos].mexposure)
{
allCorrect = false;
}
}

if (allCorrect)
{
return indexStart;
}
}

return -1;
}


std::vector<std::vector<IndexT>> estimateGroups(const std::vector<LuminanceInfo> & luminanceInfos)
{
std::vector<std::vector<IndexT>> groups;
Expand All @@ -321,6 +357,16 @@ std::vector<std::vector<IndexT>> estimateGroups(const std::vector<LuminanceInfo>
monotonics.insert(monotonics.end(), lmonotonics.begin(), lmonotonics.end());
}

//Sort the voters groups by exposure increasing
for (auto & group : monotonics)
{
std::sort(group.begin(),
group.end(),
[](const LuminanceInfo& a, const LuminanceInfo& b) {
return (a.mexposure < b.mexposure);
});
}

// Vote for the best bracket count
std::map<size_t, int> counters;
for (const auto& group : monotonics)
Expand Down Expand Up @@ -355,10 +401,12 @@ std::vector<std::vector<IndexT>> estimateGroups(const std::vector<LuminanceInfo>

// Only keep voters with the majority bracket size
auto groupIt = monotonics.begin();
std::vector<std::vector<LuminanceInfo>> eraseds;
while (groupIt != monotonics.end())
{

Check notice on line 406 in src/aliceVision/hdr/brackets.cpp

View check run for this annotation

codefactor.io / CodeFactor

src/aliceVision/hdr/brackets.cpp#L296-L406

Complex Method
if (groupIt->size() != bestBracketCount)
{
eraseds.push_back(*groupIt);
groupIt = monotonics.erase(groupIt);
}
else
Expand All @@ -367,14 +415,39 @@ std::vector<std::vector<IndexT>> estimateGroups(const std::vector<LuminanceInfo>
}
}

//Sort the voters groups by exposure increasing
for (auto & group : monotonics)
//Try to push back erased
for (const auto & erased: eraseds)
{
std::sort(group.begin(),
group.end(),
[](const LuminanceInfo& a, const LuminanceInfo& b) {
return (a.mexposure < b.mexposure);
});
//If erased is larger than the most voted, then
//Maybe it contains outliers. Try to find a correct subpart
int diff = int(erased.size()) - bestBracketCount;
if (diff < 0)
{
continue;
}


//Compare with all valid monotonics
int offset = -1;
for (const auto& monotonic : monotonics)
{
offset = extractIndex(monotonic, erased);
if (offset >= 0)
{
break;
}
}

//If something found, put it back on list of monotonics
if (offset >= 0)
{
std::vector<LuminanceInfo> subpart;
for (int index = 0; index < bestBracketCount; index++)
{
subpart.push_back(erased[offset + index]);
}
monotonics.push_back(subpart);
}
}

//check coherency
Expand Down Expand Up @@ -411,6 +484,8 @@ std::vector<std::vector<IndexT>> estimateGroups(const std::vector<LuminanceInfo>
groups.push_back(group);
}

ALICEVISION_LOG_INFO("Groups found : " << monotonics.size());

return groups;
}

Expand Down

0 comments on commit 0bf77b0

Please sign in to comment.