I want to dehaze a photo with Retinex

You can find my example here. It is a D80 NEF file. As PP3, I use standard.
My aim is not to find the optimal result but only how to dehaze with Retinex, getting an acceptable starting point.

My first step is so to enable Retinex : terrible result with a pink sky.
second step : I try to display the transmission map. This map should be a kind of representation of atmosphere thickness as the mask provided in same link above (not in same dimension as the photo)
To display it in Retinex, I click on “process” and I have the choice between two transmission masks. The two of them seem weird.

  • What are they representing?
  • Why as I just want to display an existing mask, the processing pipeline is replayed?
  • why the transmission mask are colorful?
  • why there are halos?

In order to obtain the desired dehaze effect, the transmission mask
should be modified with a luminance curve ( S shape for example) to
increase or decrease foreground and background.

  • where is the luminance curve which modulates the transmission mask?

So Ideally the only parameter needed is a luminance curve or cursors to modulate the density of the transmission mask.

I surely missed something even after reading the french rawpedia.

Your help and explanation will be welcome (particularly @jdc)
Please stick on the subject of dehazing.
I am not asking for processing advice (the photo is not worth this kind of effort)

1 Like

Difficult to answer with a very overexposed image :slightly_smiling:

Because of the position in the process, just after “demosaicing” in order to work on the whole image.
This has the consequence that White-balance, HighLight, RGB conversion, etc. are after.
I think this image cannot (or bad) threat with Retinex.

Generally to treat or reduce artifacts:

  1. before “Retinex” : a) gamma (for magenta, you can used “Free gamma” with gamma < 1), b) histogram equalizer.
    Note that this gamma is reversed at the end of treatment Retinex and therefore concerns only the Retinex process

  2. in Retinex, before generation of Transmission-map : Mask method (Gaussian mask or Sharp-mask), generaly very effective

  3. inside Retinex: action on “Transmission map”…

Tansmission-map is the heart of Retinex. It corresponds to the Gaussian logarithmic treatment mask.
We can schematically divide the processing Transmission-map in 2 parts.
a) file generation
b) operations

In other Retinex algorithms that I know, there is in general

  • for a) 2 settings : radius, and scale (we asked me to remove in RT)
  • for b) contrast (variance: I have renamed it because one asked me) and in rare cases : gain and offset (here brightness)

for b) I have add some enhancements to improve threatment - they are not in principal menu (to avoid complexity ??)

  • ability to see the file “Transmission map”, , or at least a representation
  • ability to edit this file (Transmission map curve).

But what is it ?:

  • it corresponds to the image of the distribution of the logarithmic transformation:
    ** average values at around 0, standard deviation low 3-15, maximum and minimum at about + 30 to -30 according to the images

  • This is the file that after various multiplication operation (gain) and shift (offset), truncation (contrast “variance”, threshold) can be subtracted from the original file

  • it took a lot of imagination to give a vision of this file … Note that it is far from reality. I offer two different visions to taste.

  • give the opportunity to have an insight, lets see artifacts as close, and so can try to reduce

  • in Rawpedia, I put in 2 patterns that give an overview of the actions on “Transmission map”

note: final strength is a function which assembles the restored file and the original and has no Retinex Action

1 Like

Last year on the old forum,a user suggested that file as an example to Dehaze

Madeira to dehaze

It’s a very difficult image, with with significant haze, and many local contrast

1 Like

@jdc

  1. Only the sky in this image is overexposed. This day was very hot with a sky uniformly white, very luminous with no detail inside. In this case taking a photo is a desperate case.
    The haze is thus so important that the details on the background are obfuscated.
    I hoped dehaze could restore some detail.

  2. despite your indications, I could get no improvement. So I will try on an other photo with normal sky.

  3. you provide an explanation of transmission map in algorithmic term. As I understand it from use of dark channel prior soft, it is a representation of athmosphere thickness between object and camera. If you have a look at the mask provided in the link, you will see in black the location of foregroud, in white the background and grey intermediate locations. I cannot understand how to dehaze if first you dont generate this kind of mask.
    remark : as for a luminance mask there is no detail in it. That mask is a transmission mask.

  4. the construction of the transmission mask should require no parameter adjustment from user (automatic generation). After that the mask could be modulated by a luminance curve and perhaps some strength parameter applied for the processing itself.

  5. If there are parameters required due to the (bad?) location of Retinex in the pipeline, they should be identified and gathered in the GUI.

  6. I just have a look at paper “automatic Image Haze removal…” cited by you. Is it what you implemented?

Thank you for your answers.

@gaaned92

  • “automatic Image Haze removal…” is the first contact I have had with Retinex, this was the starting base : with the parameters by default you have and automatic process…

  • the construction of the transmission mask is automatic…but depends from parameters upstream (nature of the image, sigma (radius), type of method [low, high…], scale…)…it was only after that we can work on it (contrast, threshold, curve…)

  • you ask me how it works…So I answer

5 - I don’t understand what you want…RT is made like this, and touch the internal pipeline undermines everything. To date the only process we did escape this rule is Retinex. All that is “removed”, according to the images, may play a role (White balance, Highlights, RGB conversion (gamut), exposure, RGB threatment,…)

1 Like

Hello, just for information. I saw that strong pink cast as well when using the ‘normal’ Retinex tool under the Exposure tab in RT. But then I tried the new retinex tool in the wavelet section (that’s in the newwavelets (development) branch) and that gave the following result. Not bad as a starting point, isn’t it?

Thank you for the tip.
It seems effectively much better with an effective dehaze on th backgroud.

But it is not a true dehazer as there is also an effect on the foreground (see the trees at bottom left).
As we know the haze is due to the thicknes of athmosphere, there should be no effect on foregroud object. This modulation of effect is performed through the so called transmission mask : it is a kind of alpha mask

My attempt, using the normal Retinex tool. I don’t know what is expected of the result, can other software do better?


(I had my monitor profile applied so it might look weird on your end)

PP3: http://filebin.net/88ddc41c5f

What are we trying to do here, are we trying to see more features or to make the photo look good? I don’t think it makes much sense to test Retinex on this photo. It suffers not just from haze but also from terrible light, lens flare, etc. It’s the kind of photo I would delete. You can use software to make details more visible but it won’t ever look as good as if it was simply taken during a better time of day.

Thank you for your proposal
As I wrote in my first post, I didn’nt want either to test retinex, to make the photo look good or to compare rawtherapee with other SW.
The modest objective I have is only to understand how to use Retinex to dehaze a photo and to have an acceptable parameter set for that.
Reminder : this fonction was the origin for implementation of retinex by Jacques.

In those conditions, I think the quality of photo is not very important (flare, distortion or other defects), but perhaps I am wrong. I took this photo as a first mean as it had a distinctive foreground and background.
The principal effect of dehazing is to modify luminance depending on the distance of object.
It is thus possible to dehaze the background without modifying the foreground.
That doesn’t seem possibe: in your trial, the foliage is quite modified, becoming weird, though of course there is no haze here.
I am going to study your proposal, but now I think the dehaze function is not completely implemented, even if Retinex is fully functional.
Thanks again

@gganed92, How did you create this mask?

@paulmatth, What’s behind those New Wavelets?
Are those from Dark Table?

@Royi, with newwavelets I was referring to a development branch of RawTherapee. In the main branch (the software you can download left and right) there is already a tool called wavelets.
Have a look at my site if you like (more articles on this in the menu on top, RawTherapee - Wavelets).

Wavelet processing in RawTherapee

@paulmatth, Is there a place to read about the “New Wavelets” (Is there a Forum dedicated to the development)?
I see the current are based on classic Wavelets.

I’d like to play with math of Wavelets a little bit.

Thank You.

@Royi Wavelet Unsharp-Mask and Clarity - newwavelet branch · Issue #2982 · Beep6581/RawTherapee · GitHub

Hello, tryong to respond by phone. Yes, you can read a bit about the newwavelet development via the link given above to github. Pose your questions directly to Jacques Desmis, who made the wavelet tool.

Second. No, there’s no forum dedicated to newwavelets, nor documentation for the moment. See for yourself if it works for you, if yes, consider writing a little manual.

One more thing. Current wavelets are not classic wavelets but current wavelets. The new one offer some extra things, that’s all.

Royi noreply@discuss.pixls.us a écrit :

This transmission mask is made with a dehazer plugin from Kolor based on dark channel prior algorithm. I sometimes use it with xnview to create the mask and export it in GIMP. You can then make corrections on background (luminance, blue cast, sharpening) without risk to destroy foreground.

You can find “newwavelet” win32 build at RT WIN32 builds

@gaaned92,
How do you know it is based on Dark Channel Prior algorithm?

Thank You.

Any idea where I can find the dehazer plug-in?

http://www.kolor.com/neutralhazer/

Thanks Morgan. Much appreciated.