Haze removal: Allow blend between normal and luminance mode, #5972

This commit is contained in:
Ingo Weyrich 2020-10-29 12:20:45 +01:00
parent aae90a0ad3
commit 31a9cf3fe0
9 changed files with 44 additions and 58 deletions

View File

@ -1191,7 +1191,7 @@ HISTORY_MSG_COMPLEX;Wavelet complexity
HISTORY_MSG_COMPLEXRETI;Retinex complexity
HISTORY_MSG_DEHAZE_DEPTH;Dehaze - Depth
HISTORY_MSG_DEHAZE_ENABLED;Haze Removal
HISTORY_MSG_DEHAZE_LUMINANCE;Dehaze - Luminance only
HISTORY_MSG_DEHAZE_SATURATION;Dehaze - Saturation
HISTORY_MSG_DEHAZE_SHOW_DEPTH_MAP;Dehaze - Show depth map
HISTORY_MSG_DEHAZE_STRENGTH;Dehaze - Strength
HISTORY_MSG_DUALDEMOSAIC_AUTO_CONTRAST;Dual demosaic - Auto threshold
@ -2080,7 +2080,7 @@ TP_DEFRINGE_RADIUS;Radius
TP_DEFRINGE_THRESHOLD;Threshold
TP_DEHAZE_DEPTH;Depth
TP_DEHAZE_LABEL;Haze Removal
TP_DEHAZE_LUMINANCE;Luminance only
TP_DEHAZE_SATURATION;Saturation
TP_DEHAZE_SHOW_DEPTH_MAP;Show depth map
TP_DEHAZE_STRENGTH;Strength
TP_DIRPYRDENOISE_CHROMINANCE_AMZ;Auto multi-zones

View File

@ -386,7 +386,7 @@ void ImProcFunctions::dehaze(Imagefloat *img, const DehazeParams &dehazeParams)
const float t0 = max(1e-3f, std::exp(depth * maxDistance));
const float teps = 1e-3f;
const bool luminance = dehazeParams.luminance;
const float satBlend = dehazeParams.saturation / 100.f;
const TMatrix ws = ICCStore::getInstance()->workingSpaceMatrix(params->icm.workingProfile);
#ifdef __SSE2__
const vfloat wsv[3] = {F2V(ws[1][0]), F2V(ws[1][1]),F2V(ws[1][2])};
@ -407,6 +407,7 @@ void ImProcFunctions::dehaze(Imagefloat *img, const DehazeParams &dehazeParams)
const vfloat t0v = F2V(t0);
const vfloat tepsv = F2V(teps);
const vfloat cmaxChannelv = F2V(maxChannel);
const vfloat satBlendv = F2V(satBlend);
for (; x < W - 3; x += 4) {
// ensure that the transmission is such that to avoid clipping...
const vfloat r = LVFU(img->r(y, x));
@ -420,17 +421,13 @@ void ImProcFunctions::dehaze(Imagefloat *img, const DehazeParams &dehazeParams)
STVFU(img->r(y, x), valv);
STVFU(img->g(y, x), valv);
STVFU(img->b(y, x), valv);
} else if (luminance) {
} else {
const vfloat Yv = Color::rgbLuminance(r, g, b, wsv);
const vfloat YYv = (Yv - ambientYv) / mtv + ambientYv;
const vfloat fv = vself(vmaskf_gt(Yv, epsYv), cmaxChannelv * YYv / Yv, cmaxChannelv);
STVFU(img->r(y, x), r * fv);
STVFU(img->g(y, x), g * fv);
STVFU(img->b(y, x), b * fv);
} else {
STVFU(img->r(y, x), ((r - ambient0v) / mtv + ambient0v) * cmaxChannelv);
STVFU(img->g(y, x), ((g - ambient1v) / mtv + ambient1v) * cmaxChannelv);
STVFU(img->b(y, x), ((b - ambient2v) / mtv + ambient2v) * cmaxChannelv);
STVFU(img->r(y, x), vintpf(satBlendv, ((r - ambient0v) / mtv + ambient0v) * cmaxChannelv, r * fv));
STVFU(img->g(y, x), vintpf(satBlendv, ((g - ambient1v) / mtv + ambient1v) * cmaxChannelv, g * fv));
STVFU(img->b(y, x), vintpf(satBlendv, ((b - ambient2v) / mtv + ambient2v) * cmaxChannelv, b * fv));
}
}
#endif
@ -444,17 +441,13 @@ void ImProcFunctions::dehaze(Imagefloat *img, const DehazeParams &dehazeParams)
const float mt = max(dark[y][x], t0, tl + teps);
if (dehazeParams.showDepthMap) {
img->r(y, x) = img->g(y, x) = img->b(y, x) = LIM01(1.f - mt) * maxChannel;
} else if (luminance) {
} else {
const float Y = Color::rgbLuminance(img->r(y, x), img->g(y, x), img->b(y, x), ws);
const float YY = (Y - ambientY) / mt + ambientY;
const float f = Y > 1e-5f ? maxChannel * YY / Y : maxChannel;
img->r(y, x) *= f;
img->g(y, x) *= f;
img->b(y, x) *= f;
} else {
img->r(y, x) = ((r - ambient[0]) / mt + ambient[0]) * maxChannel;
img->g(y, x) = ((g - ambient[1]) / mt + ambient[1]) * maxChannel;
img->b(y, x) = ((b - ambient[2]) / mt + ambient[2]) * maxChannel;
img->r(y, x) = intp(satBlend, ((r - ambient[0]) / mt + ambient[0]) * maxChannel, r * f);
img->g(y, x) = intp(satBlend, ((g - ambient[1]) / mt + ambient[1]) * maxChannel, g * f);
img->b(y, x) = intp(satBlend, ((b - ambient[2]) / mt + ambient[2]) * maxChannel, b * f);
}
}
}
@ -556,7 +549,8 @@ void ImProcFunctions::dehazeloc(Imagefloat *img, const DehazeParams &dehazeParam
const float teps = 1e-6f;
const float t0 = max(teps, std::exp(depth * maxDistance));
const bool luminance = dehazeParams.luminance;
// const bool luminance = dehazeParams.luminance;
const bool luminance = true;
const TMatrix ws = ICCStore::getInstance()->workingSpaceMatrix(params->icm.workingProfile);
const float ambientY = Color::rgbLuminance(ambient[0], ambient[1], ambient[2], ws);

View File

@ -11964,7 +11964,7 @@ void ImProcFunctions::Lab_Local(
dehazeParams.strength = lp.dehaze;
dehazeParams.showDepthMap = false;
dehazeParams.depth = lp.depth;
dehazeParams.luminance = params->locallab.spots.at(sp).lumonly;
// dehazeParams.luminance = true;
lab2rgb(*bufexpfin, *tmpImage.get(), params->icm.workingProfile);
dehazeloc(tmpImage.get(), dehazeParams);
rgb2lab(*tmpImage.get(), *bufexpfin, params->icm.workingProfile);

View File

@ -4598,9 +4598,9 @@ bool SoftLightParams::operator !=(const SoftLightParams& other) const
DehazeParams::DehazeParams() :
enabled(false),
strength(50),
saturation(50),
showDepthMap(false),
depth(25),
luminance(false)
depth(25)
{
}
@ -4611,7 +4611,7 @@ bool DehazeParams::operator ==(const DehazeParams& other) const
&& strength == other.strength
&& showDepthMap == other.showDepthMap
&& depth == other.depth
&& luminance == other.luminance;
&& saturation == other.saturation;
}
bool DehazeParams::operator !=(const DehazeParams& other) const
@ -5354,7 +5354,7 @@ int ProcParams::save(const Glib::ustring& fname, const Glib::ustring& fname2, bo
saveToKeyfile(!pedited || pedited->dehaze.strength, "Dehaze", "Strength", dehaze.strength, keyFile);
saveToKeyfile(!pedited || pedited->dehaze.showDepthMap, "Dehaze", "ShowDepthMap", dehaze.showDepthMap, keyFile);
saveToKeyfile(!pedited || pedited->dehaze.depth, "Dehaze", "Depth", dehaze.depth, keyFile);
saveToKeyfile(!pedited || pedited->dehaze.depth, "Dehaze", "Luminance", dehaze.luminance, keyFile);
saveToKeyfile(!pedited || pedited->dehaze.depth, "Dehaze", "Saturation", dehaze.saturation, keyFile);
// Directional pyramid denoising
saveToKeyfile(!pedited || pedited->dirpyrDenoise.enabled, "Directional Pyramid Denoising", "Enabled", dirpyrDenoise.enabled, keyFile);
@ -8324,7 +8324,7 @@ int ProcParams::load(const Glib::ustring& fname, ParamsEdited* pedited)
assignFromKeyfile(keyFile, "Dehaze", "Strength", pedited, dehaze.strength, pedited->dehaze.strength);
assignFromKeyfile(keyFile, "Dehaze", "ShowDepthMap", pedited, dehaze.showDepthMap, pedited->dehaze.showDepthMap);
assignFromKeyfile(keyFile, "Dehaze", "Depth", pedited, dehaze.depth, pedited->dehaze.depth);
assignFromKeyfile(keyFile, "Dehaze", "Luminance", pedited, dehaze.luminance, pedited->dehaze.luminance);
assignFromKeyfile(keyFile, "Dehaze", "Saturation", pedited, dehaze.saturation, pedited->dehaze.saturation);
}
if (keyFile.has_group("Film Simulation")) {

View File

@ -1955,9 +1955,9 @@ struct SoftLightParams {
struct DehazeParams {
bool enabled;
int strength;
int saturation;
bool showDepthMap;
int depth;
bool luminance;
DehazeParams();

View File

@ -36,7 +36,7 @@ Dehaze::Dehaze(): FoldableToolPanel(this, "dehaze", M("TP_DEHAZE_LABEL"), false,
EvDehazeStrength = m->newEvent(HDR, "HISTORY_MSG_DEHAZE_STRENGTH");
EvDehazeShowDepthMap = m->newEvent(HDR, "HISTORY_MSG_DEHAZE_SHOW_DEPTH_MAP");
EvDehazeDepth = m->newEvent(HDR, "HISTORY_MSG_DEHAZE_DEPTH");
EvDehazeLuminance = m->newEvent(HDR, "HISTORY_MSG_DEHAZE_LUMINANCE");
EvDehazeSaturation = m->newEvent(HDR, "HISTORY_MSG_DEHAZE_SATURATION");
strength = Gtk::manage(new Adjuster(M("TP_DEHAZE_STRENGTH"), 0., 100., 1., 50.));
strength->setAdjusterListener(this);
@ -46,9 +46,9 @@ Dehaze::Dehaze(): FoldableToolPanel(this, "dehaze", M("TP_DEHAZE_LABEL"), false,
depth->setAdjusterListener(this);
depth->show();
luminance = Gtk::manage(new Gtk::CheckButton(M("TP_DEHAZE_LUMINANCE")));
luminance->signal_toggled().connect(sigc::mem_fun(*this, &Dehaze::luminanceChanged));
luminance->show();
saturation = Gtk::manage(new Adjuster(M("TP_DEHAZE_SATURATION"), 0., 100., 1., 50.));
saturation->setAdjusterListener(this);
saturation->show();
showDepthMap = Gtk::manage(new Gtk::CheckButton(M("TP_DEHAZE_SHOW_DEPTH_MAP")));
showDepthMap->signal_toggled().connect(sigc::mem_fun(*this, &Dehaze::showDepthMapChanged));
@ -56,65 +56,65 @@ Dehaze::Dehaze(): FoldableToolPanel(this, "dehaze", M("TP_DEHAZE_LABEL"), false,
pack_start(*strength);
pack_start(*depth);
pack_start(*luminance);
pack_start(*saturation);
pack_start(*showDepthMap);
}
void Dehaze::read(const ProcParams *pp, const ParamsEdited *pedited)
{
disableListener();
if (pedited) {
strength->setEditedState(pedited->dehaze.strength ? Edited : UnEdited);
saturation->setEditedState(pedited->dehaze.saturation ? Edited : UnEdited);
depth->setEditedState(pedited->dehaze.depth ? Edited : UnEdited);
set_inconsistent(multiImage && !pedited->dehaze.enabled);
showDepthMap->set_inconsistent(!pedited->dehaze.showDepthMap);
luminance->set_inconsistent(!pedited->dehaze.luminance);
}
setEnabled(pp->dehaze.enabled);
strength->setValue(pp->dehaze.strength);
saturation->setValue(pp->dehaze.saturation);
depth->setValue(pp->dehaze.depth);
showDepthMap->set_active(pp->dehaze.showDepthMap);
luminance->set_active(pp->dehaze.luminance);
enableListener();
}
void Dehaze::write(ProcParams *pp, ParamsEdited *pedited)
{
pp->dehaze.strength = strength->getValue();
pp->dehaze.saturation = saturation->getValue();
pp->dehaze.depth = depth->getValue();
pp->dehaze.enabled = getEnabled();
pp->dehaze.showDepthMap = showDepthMap->get_active();
pp->dehaze.luminance = luminance->get_active();
if (pedited) {
pedited->dehaze.strength = strength->getEditedState();
pedited->dehaze.saturation = saturation->getEditedState();
pedited->dehaze.depth = depth->getEditedState();
pedited->dehaze.enabled = !get_inconsistent();
pedited->dehaze.showDepthMap = !showDepthMap->get_inconsistent();
pedited->dehaze.luminance = !luminance->get_inconsistent();
}
}
void Dehaze::setDefaults(const ProcParams *defParams, const ParamsEdited *pedited)
{
strength->setDefault(defParams->dehaze.strength);
saturation->setDefault(defParams->dehaze.saturation);
depth->setDefault(defParams->dehaze.depth);
if (pedited) {
saturation->setDefaultEditedState(pedited->dehaze.saturation ? Edited : UnEdited);
strength->setDefaultEditedState(pedited->dehaze.strength ? Edited : UnEdited);
depth->setDefaultEditedState(pedited->dehaze.depth ? Edited : UnEdited);
} else {
saturation->setDefaultEditedState(Irrelevant);
strength->setDefaultEditedState(Irrelevant);
depth->setDefaultEditedState(Irrelevant);
}
}
void Dehaze::adjusterChanged(Adjuster* a, double newval)
{
if (listener && getEnabled()) {
@ -122,11 +122,12 @@ void Dehaze::adjusterChanged(Adjuster* a, double newval)
listener->panelChanged(EvDehazeStrength, a->getTextValue());
} else if (a == depth) {
listener->panelChanged(EvDehazeDepth, a->getTextValue());
} else if (a == saturation) {
listener->panelChanged(EvDehazeSaturation, a->getTextValue());
}
}
}
void Dehaze::enabledChanged ()
{
if (listener) {
@ -140,7 +141,6 @@ void Dehaze::enabledChanged ()
}
}
void Dehaze::showDepthMapChanged()
{
if (listener) {
@ -148,13 +148,6 @@ void Dehaze::showDepthMapChanged()
}
}
void Dehaze::luminanceChanged()
{
if (listener) {
listener->panelChanged(EvDehazeLuminance, luminance->get_active() ? M("GENERAL_ENABLED") : M("GENERAL_DISABLED"));
}
}
void Dehaze::setBatchMode(bool batchMode)
{
ToolPanel::setBatchMode(batchMode);
@ -163,9 +156,7 @@ void Dehaze::setBatchMode(bool batchMode)
depth->showEditedCB();
}
void Dehaze::setAdjusterBehavior(bool strengthAdd)
{
strength->setAddMode(strengthAdd);
}

View File

@ -28,14 +28,15 @@ class Dehaze final : public ToolParamBlock, public AdjusterListener, public Fold
private:
Adjuster *strength;
Adjuster *depth;
Adjuster *saturation;
Gtk::CheckButton *showDepthMap;
Gtk::CheckButton *luminance;
// Gtk::CheckButton *luminance;
rtengine::ProcEvent EvDehazeEnabled;
rtengine::ProcEvent EvDehazeStrength;
rtengine::ProcEvent EvDehazeDepth;
rtengine::ProcEvent EvDehazeShowDepthMap;
rtengine::ProcEvent EvDehazeLuminance;
rtengine::ProcEvent EvDehazeSaturation;
public:
@ -49,7 +50,7 @@ public:
void adjusterChanged(Adjuster *a, double newval) override;
void enabledChanged() override;
void showDepthMapChanged();
void luminanceChanged();
// void luminanceChanged();
void setAdjusterBehavior(bool strengthAdd);
};

View File

@ -670,7 +670,7 @@ void ParamsEdited::set(bool v)
dehaze.strength = v;
dehaze.showDepthMap = v;
dehaze.depth = v;
dehaze.luminance = v;
dehaze.saturation = v;
metadata.mode = v;
filmNegative.enabled = v;
filmNegative.redRatio = v;
@ -1834,7 +1834,7 @@ void ParamsEdited::initFrom(const std::vector<rtengine::procparams::ProcParams>&
dehaze.strength = dehaze.strength && p.dehaze.strength == other.dehaze.strength;
dehaze.showDepthMap = dehaze.showDepthMap && p.dehaze.showDepthMap == other.dehaze.showDepthMap;
dehaze.depth = dehaze.depth && p.dehaze.depth == other.dehaze.depth;
dehaze.luminance = dehaze.luminance && p.dehaze.luminance == other.dehaze.luminance;
dehaze.saturation = dehaze.saturation && p.dehaze.saturation == other.dehaze.saturation;
metadata.mode = metadata.mode && p.metadata.mode == other.metadata.mode;
filmNegative.enabled = filmNegative.enabled && p.filmNegative.enabled == other.filmNegative.enabled;
filmNegative.redRatio = filmNegative.redRatio && p.filmNegative.redRatio == other.filmNegative.redRatio;
@ -6113,8 +6113,8 @@ void ParamsEdited::combine(rtengine::procparams::ProcParams& toEdit, const rteng
toEdit.dehaze.showDepthMap = mods.dehaze.showDepthMap;
}
if (dehaze.luminance) {
toEdit.dehaze.luminance = mods.dehaze.luminance;
if (dehaze.saturation) {
toEdit.dehaze.saturation = mods.dehaze.saturation;
}
if (metadata.mode) {

View File

@ -1183,7 +1183,7 @@ struct DehazeParamsEdited {
bool strength;
bool showDepthMap;
bool depth;
bool luminance;
bool saturation;
};
struct RAWParamsEdited {