Merge pull request #4356 from Beep6581/histmatching-input-profile

made histogram matching depend on the input profile
This commit is contained in:
Alberto Griggio
2018-02-03 19:09:47 +01:00
committed by GitHub
6 changed files with 27 additions and 9 deletions

View File

@@ -169,7 +169,7 @@ void mappingToCurve(const std::vector<int> &mapping, std::vector<double> &curve)
} // namespace
void RawImageSource::getAutoMatchedToneCurve(std::vector<double> &outCurve)
void RawImageSource::getAutoMatchedToneCurve(const ColorManagementParams &cp, std::vector<double> &outCurve)
{
BENCHFUN
@@ -177,7 +177,18 @@ void RawImageSource::getAutoMatchedToneCurve(std::vector<double> &outCurve)
std::cout << "performing histogram matching for " << getFileName() << " on the embedded thumbnail" << std::endl;
}
if (!histMatchingCache.empty()) {
const auto same_profile =
[](const ColorManagementParams &a, const ColorManagementParams &b) -> bool
{
return (a.input == b.input
&& a.toneCurve == b.toneCurve
&& a.applyLookTable == b.applyLookTable
&& a.applyBaselineExposureOffset == b.applyBaselineExposureOffset
&& a.applyHueSatMap == b.applyHueSatMap
&& a.dcpIlluminant == b.dcpIlluminant);
};
if (!histMatchingCache.empty() && same_profile(histMatchingParams, cp)) {
if (settings->verbose) {
std::cout << "tone curve found in cache" << std::endl;
}
@@ -196,9 +207,12 @@ void RawImageSource::getAutoMatchedToneCurve(std::vector<double> &outCurve)
}
ProcParams neutral;
neutral.icm = cp;
neutral.raw.bayersensor.method = RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::FAST);
neutral.raw.xtranssensor.method = RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::FAST);
neutral.icm.output = "sRGB";
neutral.icm.gamma = "default";
neutral.icm.freegamma = false;
std::unique_ptr<IImage8> source;
{
@@ -211,6 +225,7 @@ void RawImageSource::getAutoMatchedToneCurve(std::vector<double> &outCurve)
std::cout << "histogram matching: no thumbnail found, generating a neutral curve" << std::endl;
}
histMatchingCache = outCurve;
histMatchingParams = cp;
return;
}
skip = LIM(skip * fh / h, 6, 10); // adjust the skip factor -- the larger the thumbnail, the less we should skip to get a good match
@@ -233,6 +248,7 @@ void RawImageSource::getAutoMatchedToneCurve(std::vector<double> &outCurve)
std::cout << "histogram matching: raw decoding failed, generating a neutral curve" << std::endl;
}
histMatchingCache = outCurve;
histMatchingParams = cp;
return;
}
target.reset(thumb->processImage(neutral, sensor_type, fh / skip, TI_Nearest, getMetaData(), scale, false, true));
@@ -304,6 +320,7 @@ void RawImageSource::getAutoMatchedToneCurve(std::vector<double> &outCurve)
}
histMatchingCache = outCurve;
histMatchingParams = cp;
}
} // namespace rtengine

View File

@@ -139,7 +139,7 @@ public:
}
// for RAW files, compute a tone curve using histogram matching on the embedded thumbnail
virtual void getAutoMatchedToneCurve(std::vector<double> &outCurve)
virtual void getAutoMatchedToneCurve(const ColorManagementParams &cp, std::vector<double> &outCurve)
{
outCurve = { 0.0 };
}

View File

@@ -447,7 +447,7 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall)
params.toneCurve.black, params.toneCurve.hlcompr, params.toneCurve.hlcomprthresh, params.toneCurve.hrenabled);
}
if (params.toneCurve.histmatching) {
imgsrc->getAutoMatchedToneCurve(params.toneCurve.curve);
imgsrc->getAutoMatchedToneCurve(params.icm, params.toneCurve.curve);
if (params.toneCurve.autoexp) {
params.toneCurve.expcomp = 0.0;

View File

@@ -96,6 +96,7 @@ protected:
float psBlueBrightness[4];
std::vector<double> histMatchingCache;
ColorManagementParams histMatchingParams;
void hphd_vertical (float** hpmap, int col_from, int col_to);
void hphd_horizontal (float** hpmap, int row_from, int row_to);
@@ -186,7 +187,7 @@ public:
}
void getAutoExpHistogram (LUTu & histogram, int& histcompr);
void getRAWHistogram (LUTu & histRedRaw, LUTu & histGreenRaw, LUTu & histBlueRaw);
void getAutoMatchedToneCurve(std::vector<double> &outCurve);
void getAutoMatchedToneCurve(const ColorManagementParams &cp, std::vector<double> &outCurve);
DCPProfile *getDCP(const ColorManagementParams &cmp, DCPProfile::ApplyState &as);
void convertColorSpace(Imagefloat* image, const ColorManagementParams &cmp, const ColorTemp &wb);

View File

@@ -74,7 +74,7 @@ int refreshmap[rtengine::NUMOFEVENTS] = {
0, // EvLDNEdgeTolerance: obsolete,
0, // EvCDNEnabled:obsolete,
0, // free entry
RGBCURVE, // EvDCPToneCurve,
RGBCURVE|M_AUTOEXP, // EvDCPToneCurve,
ALLNORAW, // EvDCPIlluminant,
RETINEX, // EvSHEnabled,
RGBCURVE, // EvSHHighlights,
@@ -419,8 +419,8 @@ int refreshmap[rtengine::NUMOFEVENTS] = {
DIRPYREQUALIZER, // EvWavgreenlow
DIRPYREQUALIZER, // EvWavbluelow
DIRPYREQUALIZER, // EvWavNeutral
RGBCURVE, // EvDCPApplyLookTable,
RGBCURVE, // EvDCPApplyBaselineExposureOffset,
RGBCURVE|M_AUTOEXP, // EvDCPApplyLookTable,
RGBCURVE|M_AUTOEXP, // EvDCPApplyBaselineExposureOffset,
ALLNORAW, // EvDCPApplyHueSatMap
DIRPYREQUALIZER, // EvWavenacont
DIRPYREQUALIZER, // EvWavenachrom

View File

@@ -741,7 +741,7 @@ private:
ipf.getAutoExp (aehist, aehistcompr, params.toneCurve.clip, expcomp, bright, contr, black, hlcompr, hlcomprthresh);
}
if (params.toneCurve.histmatching) {
imgsrc->getAutoMatchedToneCurve(params.toneCurve.curve);
imgsrc->getAutoMatchedToneCurve(params.icm, params.toneCurve.curve);
if (params.toneCurve.autoexp) {
params.toneCurve.expcomp = 0.0;