dehaze: added lumimance mode from ART, #5456, thanks to @agriggio
This commit is contained in:
parent
7d5ec6c067
commit
7ff3192cc9
@ -744,6 +744,7 @@ HISTORY_MSG_COLORTONING_LABREGION_SHOWMASK;CT - region show mask
|
||||
HISTORY_MSG_COLORTONING_LABREGION_SLOPE;CT - region slope
|
||||
HISTORY_MSG_DEHAZE_DEPTH;Dehaze - Depth
|
||||
HISTORY_MSG_DEHAZE_ENABLED;Haze Removal
|
||||
HISTORY_MSG_DEHAZE_LUMINANCE;Dehaze - Luminance only
|
||||
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
|
||||
@ -1538,6 +1539,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_SHOW_DEPTH_MAP;Show depth map
|
||||
TP_DEHAZE_STRENGTH;Strength
|
||||
TP_DIRPYRDENOISE_CHROMINANCE_AMZ;Auto multi-zones
|
||||
|
@ -210,6 +210,11 @@ public:
|
||||
return r * workingspace[1][0] + g * workingspace[1][1] + b * workingspace[1][2];
|
||||
}
|
||||
|
||||
static vfloat rgbLuminance(vfloat r, vfloat g, vfloat b, const vfloat workingspace[3])
|
||||
{
|
||||
return r * workingspace[0] + g * workingspace[1] + b * workingspace[2];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert red/green/blue to L*a*b
|
||||
* @brief Convert red/green/blue to hue/saturation/luminance
|
||||
|
@ -276,6 +276,13 @@ BENCHFUN
|
||||
const float depth = -float(params->dehaze.depth) / 100.f;
|
||||
const float t0 = max(1e-3f, std::exp(depth * max_t));
|
||||
const float teps = 1e-3f;
|
||||
|
||||
const bool luminance = params->dehaze.luminance;
|
||||
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])};
|
||||
#endif
|
||||
const float ambientY = Color::rgbLuminance(ambient[0], ambient[1], ambient[2], ws);
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for if (multiThread)
|
||||
#endif
|
||||
@ -286,6 +293,8 @@ BENCHFUN
|
||||
const vfloat ambient0v = F2V(ambient[0]);
|
||||
const vfloat ambient1v = F2V(ambient[1]);
|
||||
const vfloat ambient2v = F2V(ambient[2]);
|
||||
const vfloat ambientYv = F2V(ambientY);
|
||||
const vfloat epsYv = F2V(1e-5f);
|
||||
const vfloat t0v = F2V(t0);
|
||||
const vfloat tepsv = F2V(teps);
|
||||
const vfloat c65535v = F2V(65535.f);
|
||||
@ -297,14 +306,14 @@ BENCHFUN
|
||||
// ... t >= tl to avoid negative values
|
||||
const vfloat tlv = onev - vminf(r / ambient0v, vminf(g / ambient1v, b / ambient2v));
|
||||
// ... t >= tu to avoid values > 1
|
||||
r -= ambient0v;
|
||||
g -= ambient1v;
|
||||
b -= ambient2v;
|
||||
// r -= ambient0v;
|
||||
// g -= ambient1v;
|
||||
// b -= ambient2v;
|
||||
|
||||
vfloat tuv = t0v - tepsv;
|
||||
tuv = vself(vmaskf_lt(ambient0v, onev), vmaxf(tuv, r / (onev - ambient0v)), tuv);
|
||||
tuv = vself(vmaskf_lt(ambient1v, onev), vmaxf(tuv, g / (onev - ambient1v)), tuv);
|
||||
tuv = vself(vmaskf_lt(ambient2v, onev), vmaxf(tuv, b / (onev - ambient2v)), tuv);
|
||||
tuv = vself(vmaskf_lt(ambient0v, onev), vmaxf(tuv, (r - ambient0v) / (onev - ambient0v)), tuv);
|
||||
tuv = vself(vmaskf_lt(ambient1v, onev), vmaxf(tuv, (g - ambient1v) / (onev - ambient1v)), tuv);
|
||||
tuv = vself(vmaskf_lt(ambient2v, onev), vmaxf(tuv, (b - ambient2v) / (onev - ambient2v)), tuv);
|
||||
|
||||
const vfloat mtv = vmaxf(LVFU(dark[y][x]), vmaxf(tlv, tuv) + tepsv);
|
||||
if (params->dehaze.showDepthMap) {
|
||||
@ -312,10 +321,17 @@ BENCHFUN
|
||||
STVFU(img->r(y, x), valv);
|
||||
STVFU(img->g(y, x), valv);
|
||||
STVFU(img->b(y, x), valv);
|
||||
} else if (luminance) {
|
||||
const vfloat Yv = Color::rgbLuminance(r, g, b, wsv);
|
||||
const vfloat YYv = (Yv - ambientYv) / mtv + ambientYv;
|
||||
const vfloat fv = vself(vmaskf_gt(Yv, epsYv), c65535v * YYv / Yv, c65535v);
|
||||
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 / mtv + ambient0v) * c65535v);
|
||||
STVFU(img->g(y, x), (g / mtv + ambient1v) * c65535v);
|
||||
STVFU(img->b(y, x), (b / mtv + ambient2v) * c65535v);
|
||||
STVFU(img->r(y, x), ((r - ambient0v) / mtv + ambient0v) * c65535v);
|
||||
STVFU(img->g(y, x), ((g - ambient1v) / mtv + ambient1v) * c65535v);
|
||||
STVFU(img->b(y, x), ((b - ambient2v) / mtv + ambient2v) * c65535v);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -339,6 +355,15 @@ BENCHFUN
|
||||
const float mt = max(dark[y][x], tl + teps, tu + teps);
|
||||
if (params->dehaze.showDepthMap) {
|
||||
img->r(y, x) = img->g(y, x) = img->b(y, x) = LIM01(1.f - mt) * 65535.f;
|
||||
} else if (luminance) {
|
||||
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;
|
||||
if (Y > 1e-5f) {
|
||||
const float f = 65535.f * YY / Y;
|
||||
img->r(y, x) *= f;
|
||||
img->g(y, x) *= f;
|
||||
img->b(y, x) *= f;
|
||||
}
|
||||
} else {
|
||||
img->r(y, x) = (r / mt + ambient[0]) * 65535.f;
|
||||
img->g(y, x) = (g / mt + ambient[1]) * 65535.f;
|
||||
|
@ -2517,7 +2517,8 @@ DehazeParams::DehazeParams() :
|
||||
enabled(false),
|
||||
strength(50),
|
||||
showDepthMap(false),
|
||||
depth(25)
|
||||
depth(25),
|
||||
luminance(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -2527,7 +2528,8 @@ bool DehazeParams::operator ==(const DehazeParams& other) const
|
||||
enabled == other.enabled
|
||||
&& strength == other.strength
|
||||
&& showDepthMap == other.showDepthMap
|
||||
&& depth == other.depth;
|
||||
&& depth == other.depth
|
||||
&& luminance == other.luminance;
|
||||
}
|
||||
|
||||
bool DehazeParams::operator !=(const DehazeParams& other) const
|
||||
@ -3238,7 +3240,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);
|
||||
// Directional pyramid denoising
|
||||
saveToKeyfile(!pedited || pedited->dirpyrDenoise.enabled, "Directional Pyramid Denoising", "Enabled", dirpyrDenoise.enabled, keyFile);
|
||||
saveToKeyfile(!pedited || pedited->dirpyrDenoise.enhance, "Directional Pyramid Denoising", "Enhance", dirpyrDenoise.enhance, keyFile);
|
||||
@ -4878,6 +4880,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);
|
||||
}
|
||||
|
||||
if (keyFile.has_group("Film Simulation")) {
|
||||
|
@ -1342,7 +1342,7 @@ struct DehazeParams {
|
||||
int strength;
|
||||
bool showDepthMap;
|
||||
int depth;
|
||||
|
||||
bool luminance;
|
||||
DehazeParams();
|
||||
|
||||
bool operator==(const DehazeParams &other) const;
|
||||
|
@ -36,6 +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");
|
||||
|
||||
strength = Gtk::manage(new Adjuster(M("TP_DEHAZE_STRENGTH"), 0., 100., 1., 50.));
|
||||
strength->setAdjusterListener(this);
|
||||
@ -45,12 +46,17 @@ 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();
|
||||
|
||||
showDepthMap = Gtk::manage(new Gtk::CheckButton(M("TP_DEHAZE_SHOW_DEPTH_MAP")));
|
||||
showDepthMap->signal_toggled().connect(sigc::mem_fun(*this, &Dehaze::showDepthMapChanged));
|
||||
showDepthMap->show();
|
||||
|
||||
pack_start(*strength);
|
||||
pack_start(*depth);
|
||||
pack_start(*luminance);
|
||||
pack_start(*showDepthMap);
|
||||
}
|
||||
|
||||
@ -64,12 +70,14 @@ void Dehaze::read(const ProcParams *pp, const ParamsEdited *pedited)
|
||||
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);
|
||||
depth->setValue(pp->dehaze.depth);
|
||||
showDepthMap->set_active(pp->dehaze.showDepthMap);
|
||||
luminance->set_active(pp->dehaze.luminance);
|
||||
|
||||
enableListener();
|
||||
}
|
||||
@ -81,12 +89,14 @@ void Dehaze::write(ProcParams *pp, ParamsEdited *pedited)
|
||||
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.depth = depth->getEditedState();
|
||||
pedited->dehaze.enabled = !get_inconsistent();
|
||||
pedited->dehaze.showDepthMap = !showDepthMap->get_inconsistent();
|
||||
pedited->dehaze.luminance = !luminance->get_inconsistent();
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,6 +148,12 @@ 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)
|
||||
{
|
||||
|
@ -28,12 +28,14 @@ class Dehaze: public ToolParamBlock, public AdjusterListener, public FoldableToo
|
||||
private:
|
||||
Adjuster *strength;
|
||||
Adjuster *depth;
|
||||
Gtk::CheckButton *showDepthMap;
|
||||
Gtk::CheckButton *showDepthMap;
|
||||
Gtk::CheckButton *luminance;
|
||||
|
||||
rtengine::ProcEvent EvDehazeEnabled;
|
||||
rtengine::ProcEvent EvDehazeStrength;
|
||||
rtengine::ProcEvent EvDehazeDepth;
|
||||
rtengine::ProcEvent EvDehazeShowDepthMap;
|
||||
rtengine::ProcEvent EvDehazeLuminance;
|
||||
|
||||
public:
|
||||
|
||||
@ -47,6 +49,7 @@ public:
|
||||
void adjusterChanged(Adjuster *a, double newval) override;
|
||||
void enabledChanged() override;
|
||||
void showDepthMapChanged();
|
||||
void luminanceChanged();
|
||||
void setAdjusterBehavior(bool strengthAdd);
|
||||
};
|
||||
|
||||
|
@ -587,6 +587,7 @@ void ParamsEdited::set(bool v)
|
||||
dehaze.strength = v;
|
||||
dehaze.showDepthMap = v;
|
||||
dehaze.depth = v;
|
||||
dehaze.luminance = v;
|
||||
metadata.mode = v;
|
||||
filmNegative.enabled = v;
|
||||
filmNegative.redRatio = v;
|
||||
@ -1158,6 +1159,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;
|
||||
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;
|
||||
@ -3224,6 +3226,10 @@ 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 (metadata.mode) {
|
||||
toEdit.metadata.mode = mods.metadata.mode;
|
||||
}
|
||||
|
@ -596,6 +596,7 @@ struct DehazeParamsEdited {
|
||||
bool strength;
|
||||
bool showDepthMap;
|
||||
bool depth;
|
||||
bool luminance;
|
||||
};
|
||||
|
||||
struct RAWParamsEdited {
|
||||
|
Loading…
x
Reference in New Issue
Block a user