Fix potential bug in histogram matching (#5249)
This commit is contained in:
@@ -69,7 +69,7 @@ CdfInfo getCdf(const IImage8 &img)
|
|||||||
sum += ret.cdf[i];
|
sum += ret.cdf[i];
|
||||||
ret.cdf[i] = sum;
|
ret.cdf[i] = sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ int findMatch(int val, const std::vector<int> &cdf, int j)
|
|||||||
void mappingToCurve(const std::vector<int> &mapping, std::vector<double> &curve)
|
void mappingToCurve(const std::vector<int> &mapping, std::vector<double> &curve)
|
||||||
{
|
{
|
||||||
curve.clear();
|
curve.clear();
|
||||||
|
|
||||||
int idx = 15;
|
int idx = 15;
|
||||||
for (; idx < int(mapping.size()); ++idx) {
|
for (; idx < int(mapping.size()); ++idx) {
|
||||||
if (mapping[idx] >= idx) {
|
if (mapping[idx] >= idx) {
|
||||||
@@ -160,7 +160,7 @@ void mappingToCurve(const std::vector<int> &mapping, std::vector<double> &curve)
|
|||||||
doit(start, idx, idx > step ? step : idx / 2, true);
|
doit(start, idx, idx > step ? step : idx / 2, true);
|
||||||
doit(idx, end, step, idx - step > step / 2 && std::abs(curve[curve.size()-2] - coord(idx)) > 0.01);
|
doit(idx, end, step, idx - step > step / 2 && std::abs(curve[curve.size()-2] - coord(idx)) > 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curve.size() > 2 && (1 - curve[curve.size()-2] <= coord(step) / 3)) {
|
if (curve.size() > 2 && (1 - curve[curve.size()-2] <= coord(step) / 3)) {
|
||||||
curve.pop_back();
|
curve.pop_back();
|
||||||
curve.pop_back();
|
curve.pop_back();
|
||||||
@@ -179,7 +179,7 @@ void mappingToCurve(const std::vector<int> &mapping, std::vector<double> &curve)
|
|||||||
return (x - xa) / (xb - xa) * (yb - ya) + ya;
|
return (x - xa) / (xb - xa) * (yb - ya) + ya;
|
||||||
};
|
};
|
||||||
idx = -1;
|
idx = -1;
|
||||||
for (size_t i = curve.size()-1; i > 0; i -= 2) {
|
for (ssize_t i = curve.size()-1; i > 0; i -= 2) {
|
||||||
if (curve[i] <= 0.f) {
|
if (curve[i] <= 0.f) {
|
||||||
idx = i+1;
|
idx = i+1;
|
||||||
break;
|
break;
|
||||||
@@ -207,7 +207,7 @@ void mappingToCurve(const std::vector<int> &mapping, std::vector<double> &curve)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curve.size() < 4) {
|
if (curve.size() < 4) {
|
||||||
curve = { DCT_Linear }; // not enough points, fall back to linear
|
curve = { DCT_Linear }; // not enough points, fall back to linear
|
||||||
} else {
|
} else {
|
||||||
@@ -233,7 +233,7 @@ void mappingToCurve(const std::vector<int> &mapping, std::vector<double> &curve)
|
|||||||
void RawImageSource::getAutoMatchedToneCurve(const ColorManagementParams &cp, std::vector<double> &outCurve)
|
void RawImageSource::getAutoMatchedToneCurve(const ColorManagementParams &cp, std::vector<double> &outCurve)
|
||||||
{
|
{
|
||||||
BENCHFUN
|
BENCHFUN
|
||||||
|
|
||||||
if (settings->verbose) {
|
if (settings->verbose) {
|
||||||
std::cout << "performing histogram matching for " << getFileName() << " on the embedded thumbnail" << std::endl;
|
std::cout << "performing histogram matching for " << getFileName() << " on the embedded thumbnail" << std::endl;
|
||||||
}
|
}
|
||||||
@@ -275,7 +275,7 @@ void RawImageSource::getAutoMatchedToneCurve(const ColorManagementParams &cp, st
|
|||||||
neutral.raw.bayersensor.method = RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::FAST);
|
neutral.raw.bayersensor.method = RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::FAST);
|
||||||
neutral.raw.xtranssensor.method = RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::FAST);
|
neutral.raw.xtranssensor.method = RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::FAST);
|
||||||
neutral.icm.outputProfile = ColorManagementParams::NoICMString;
|
neutral.icm.outputProfile = ColorManagementParams::NoICMString;
|
||||||
|
|
||||||
std::unique_ptr<IImage8> source;
|
std::unique_ptr<IImage8> source;
|
||||||
{
|
{
|
||||||
RawMetaDataLocation rml;
|
RawMetaDataLocation rml;
|
||||||
@@ -307,7 +307,7 @@ void RawImageSource::getAutoMatchedToneCurve(const ColorManagementParams &cp, st
|
|||||||
std::cout << "histogram matching: extracted embedded thumbnail" << std::endl;
|
std::cout << "histogram matching: extracted embedded thumbnail" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<IImage8> target;
|
std::unique_ptr<IImage8> target;
|
||||||
{
|
{
|
||||||
RawMetaDataLocation rml;
|
RawMetaDataLocation rml;
|
||||||
|
Reference in New Issue
Block a user