diff --git a/src/aliceVision/hdr/brackets.cpp b/src/aliceVision/hdr/brackets.cpp index e9d75c0827..e0f94cc5c7 100644 --- a/src/aliceVision/hdr/brackets.cpp +++ b/src/aliceVision/hdr/brackets.cpp @@ -303,6 +303,42 @@ std::vector> splitMonotonics(const std::vector & smaller, const std::vector & 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> estimateGroups(const std::vector & luminanceInfos) { std::vector> groups; @@ -321,6 +357,16 @@ std::vector> estimateGroups(const std::vector 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 counters; for (const auto& group : monotonics) @@ -355,10 +401,12 @@ std::vector> estimateGroups(const std::vector // Only keep voters with the majority bracket size auto groupIt = monotonics.begin(); + std::vector> eraseds; while (groupIt != monotonics.end()) { if (groupIt->size() != bestBracketCount) { + eraseds.push_back(*groupIt); groupIt = monotonics.erase(groupIt); } else @@ -367,14 +415,39 @@ std::vector> estimateGroups(const std::vector } } - //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 subpart; + for (int index = 0; index < bestBracketCount; index++) + { + subpart.push_back(erased[offset + index]); + } + monotonics.push_back(subpart); + } } //check coherency @@ -411,6 +484,8 @@ std::vector> estimateGroups(const std::vector groups.push_back(group); } + ALICEVISION_LOG_INFO("Groups found : " << monotonics.size()); + return groups; }