Developing afre_dehaze

Not feeling like working on making it ready for release this week.

In the meantime, post images you would like to see afre_dehazed. It will be a fun way to pass time and test the filter. I prefer it to be your own images since we don’t want to get into licensing trouble.

1 Like

You may want to listen to that’s life by frank sinatra. I concur.

What about this image (Turin - Italy):

In the background, to the very left of the “IPERCOOP” red billboard, there is a tiny skyscraper. Currently, it is hardly visible because of the haze.
With the DCP dehaze filter applied this skyscraper stands out better in my image. I have simply changed the “strength” parameter of this filter.

P.S: do not worry about next release of G’MIC. Usually, over time, there are so many following G’MIC releases that you are never late for the party :slight_smile:

afre_dehaze by itself will darken the image.

gmic ENVY_PARK.jpg afre_dehaze 37 round o ENVY_NOT.jpg

Once you have recovered the stats to approx. the same as the input image, you get a better comparison.

Here is the original so that you may flip between the two.

Hello afre,

Thanks a lot for your efforts on this image :slight_smile:
Looking forward to test your G’MIC dehaze filter as soon as it is available.

EDIT: just for fine I have tested a web application which allows to dehaze your images (https://www341.lunapic.com/editor/?action=dehaze).
To make it short, I have uplodaed my image and I have clicked on the Menu > Adjust > DeHaze.
The result is quite similar to your G’MIC filter. In essence, my image is much darker.

Here is the output from LunaPic (DeHaze filter):

Intro to our (tentative) parameters.

Patch radius
– This is the main parameter of the filter.
– Small radii prevent halos :+1: but may end up over-saturated :-1: and overdone :-1:.
– Large radii cause halos :-1: but may have realistic colour :+1:, though diminish dehazing :-1: .
– Default radii is calculated. User may double or halve that amount. (To Do: make smart GUI.)

Depth recovery
– Most images require this to look realistic.
– A complete dehaze removes the sense of depth, which is important for landscape photos.
– Default value is 5%.

Brightness (Optional, To Do)
– To prevent the notable darkening, I will provide a elegant way to lift the dark and mid-tones.

Colour shift (Optional, To Do)
– Not necessary in most cases. It is a “break glass in case of an emergency”.
– This gives the user a chance to reduce colour shifting if the filter overdoes it; or the opposite.

PS
Variables
– The filter and its sub-commands also have variables that I have set as constants.
– For the devs and the inquisitive. Maybe some images require other values to be set.

1 Like

Update

1 Revisiting the morphology and transmission parts. Unsatisfied with the algorithm. My current method of overcoming its weaknesses is insufficient to me. It is okay, as you can see from my sample runs above and in my PlayRaws, but there is room for improvement.

2 Unsure about adding the Brightness and Colour shift parameters, as they would add heft and maintenance to the filter. → Should I leave the post processing to the user? Or include them but make them optional? Thoughts?

The more I ponder abour your question, the more I am uncertain about the best way to go. Both options have pros (keep the filter simple) and cons (getting your final image darker)…

In essence, as long as your filter is well documented by well explaining each of its settings it should be enough whatever option you choose, IMHO.

From my personal experience, I find the G’MIC filters lacking in two ways:

  • lack of proper documentation (e.g. no “F1” shorcut help-button to reach the documentation for every filter: HTML manual, YouTube videos and so on);
  • slow with big images (due to the lack of the GPU leveraging, maybe?). My Pc has an I7 Intel Cpu and 8 gb of Ram btw.

Therefore, if your filter has a good, not too technical, documentation (with maybe even an image as sample to test it) and it is not terribly slow with big images it should be fine as far as I am concerned :slight_smile:

EDIT: as far as the documentation is concerned the worst part regards the G’MIC filters in the Testing group. By and large, right now, there is no way to understand what they are supposed to achieve. This defeats their purpose, which is testing them thoroughly , I suppose :slight_smile:

There is the approach of adding info into filter, but it’s a little too much when other languages are considered. Not to mention that it takes some work when creating filter for g’mic can be a lot of work, and especially when new features or bugs are discovered. I totally get why filter developer don’t add info to every of their filters.

Yep. Unfortunately, the lack of written documentation is a a problem for most of the open source softwares I work with. This is for a reason, since it takes a LOT of time to write and test it. Time is money :slight_smile:

Hello @afre

Just out of curiosity, is it possible do “dehaze” this picture?

Take a look at the sky, that is the very uppermost part of the image. There is a “haze” due to the lamps illumination.
I am wondering whether your upcoming filter takes into account this kind of “problem”…

With Kolor Dehazer plugin lost in the Gopro parrallel universe
No other processing
About 20s to adjust parameters.

Hello @gaaned92

Wow! Nice result indeed!

I have googled a bit and I am wondering whether you have used a plugin for Photoshop (“Kolor Dehazer plugin”).
Since it is a jpeg image, quite compressed in order to post it in this blog, I suppose you didn’t work with RawTherapee or Gimp (as far as this plugin in concerned).

@Silvio_Grosso I use now this 8bf plugin with xnview. It’s not ideal.
If you or @afre want the plugin, I can upload it in a zip. The GUI is very simple as the parameters permit to modulate the depth mask.
I hope @afre will get a better result than this plugin. :crazy_face:

same processing as above

@gaaned92 I don’t actually see a difference once I do post-lightening, which I listed as a To Do.

So, in a sense, you are sharing your opinion on:

Sure, why not? As aforementioned, I am still making this filter in isolation and prefer it that way. Seeing how much I can push myself. (I have still some math to understand though, so it may be time to ask the coding and math adept members again.) But it would be great to see how the plugin does its GUI. IrfanView should be able to use 8bf.

@afre

The post processing is an interesting idea. As you have inside the plugin the depth mask, you can apply brightness and color shift modulated by the mask.
Regarding color shift, the main problem is the blue cast caused by Rayleigh scattering (but there are other cast due to pollution for instance). These casts increase with the distance of viewed object.
If not included in the plugin, a way to export the mask would be valuable.

You could be interested by some images in https://keybase.pub/gaaned92/haze/
Regarding blue cast, DSC_3445.NEF could interest you.

You will find the plugin in the same location.

1 Like

Hello @gaaned92

Since we are talking about dehaze options…

By any chance, do you know some good tutorials regarding RawTherapee and its Retinex tool [1]?

From what I have gathered it should be another additional option to dehaze your pictures…
I have looked on YouTube but I am unable to find anything regarding the Retinex option. Only thing I have read by other users is: this tool should be difficult to use… :slight_smile:
Here is a discussion on this Retinex workflow:

[1] Retinex - RawPedia

In any operation, I find that pre and post processing are important. Finding the right balance isn’t easy. I don’t want to decide for the user; but at the same time, I don’t want to alienate them.

Yes, that would be a good thing to remember. I am wondering what you had in mind specifically. Would like to consider that.

It covers colour cast and depth. It becomes a problem when it encounters situations where the assumptions no longer hold; e.g., multiple casts or transmission and depth discontinuities. My re-investigation of transmission has to do with the latter.

Thanks. I am already using a good data set for testing. More won’t hurt.

To my understanding, RT has a few implementations. The one described in RawPedia is @jdc’s, which is way too advanced for me. I am too scared to try it. In fact, I don’t really use any dehaze tools in my workflow. He is a vet though. :stuck_out_tongue:

Another one is by @agriggio, which is based on the same original He et al. paper I am basing my filter on.

Just saw your edit. Retinex and dehaze are indeed related. Recently, there has been research combining the two, which is interesting but beyond my understanding. Anyway, these topics are still being studied because although we have made much progress we are still not doing that well. We, as in, scientists, not me. :stuck_out_tongue:

Another really hazy file to test:

http://rawtherapee.com/shared/test_images/dehaze2.nef

Edit: left without RT dehaze, right with RT dehaze at max. settings. Please ignore the dust spots :wink:

Edit: what looks like dust spots wasn’t dust. It were water drops on the lens caused by really heavy irish mist.

2 Likes