Cutting through the smoke with Retinex

Cutting through the smoke with Retinex

This year, most of August was unfit for bike riding due to wildfire smoke in the air. There was a 10 day stretch where the visibility scale reached zero. Standing on the shores at Shilshole, the smoke was so thick that land wasn’t visible across the Puget Sound. I wondered if land was still visible from a digital camera, even though I couldn’t see it. There is an imaging processing technique call Retinex that is used to enhance the dynamic range of images. I wondered if that process would reveal the obscured land across the sound.

Before I continue on, some background about Retinex would be helpful. I first became aware of Retinex processing from Fred Weinhaus’s website, It clearly demonstrated the technique which led me to try it for this application. The actual Retinex process is a complex set of mathematical functions based on even more complex theory of perceptual vision, referred to as color constancy, I won’t go into any further detail here about how Retinex works. Because of the example uses, I decided to use the technique.

Another reasoning was because of my experience with film photography. I started using film at an early age, which prompted my parents to give me photo developing equipment. Before that gift, I was sending my rolls out to be developed with disappointing results. Many of my shots were too dark or bright. Whether the developer was a human or a machine, the process used an average of what typical photos were like. The negatives were lit against photo paper at the same rate, so the shot suffered. After getting the black room setup, I was able to take my same negatives and adjust that light timing. Of course dark images loss some of their depth, but I was able to see the objects doing this. Fast forward to now, the digital camera does the film developing internally. I wondered if the smokey images I took had this same limitation and the objects were in fact being sensed by the camera.

Besides Fred’s Imagemagick Retinex script, GIMP also provides a Retinex function, so I used both processes. Russell Cottrell’s website also provided information about the Retinex plugin, In it, this photo was demonstrated which I used as well,,_Ohio#/media/File:South_Solon_from_the_south.jpg. His image was 400×298, the source image is 2576×1920, this is important to note because Retinex processing times are significant for larger images. Here is a comparison of how long the Retinex process took with each method on each sized image.

GIMP – Colors / Retinex / Uniform – Scale:240 – Scale division:3 – Dynamic:1.2
298p – 1 second
1920p – 10 seconds

FW_Retinex – ./retinex -m HSL -f 100 -s 200
298p – 5 seconds
1920p – 2 mintues

The larger resolution images took much more time to process. In addition to the required length of time, the GIMP method introduced artifacts on the results. The artifacts were not present on the IM results. Also, I found that the IM script needed to be followed by an enhance process to have it match the GIMP level of clarity.

convert -equalize South_Solon_from_the_south_001.jpg South_Solon_from_the_south_001_Equalized.jpg

The results of this process create an image that appears to have too much color saturation, so I ran this to bring it back down a bit.

convert -modulate 100,40 South_Solon_from_the_south_001_Equalized.jpg South_Solon_from_the_south_001_DeSaturate.jpg

It clears up the image, but many of the fine details are lost.

Anyway, the example image above had some differences from the images I wanted to process. I took my images from ground level versus from the air, as in the example above. It didn’t seem to me at the time this would be a factor, but it was.

./retinex -m HSL -f 100 -s 200 Source.jpeg Source_IM-Retinex.jpeg

The enhancement results were far less than I had expected. The blue colors were really low and the depth was missing. When I ran the same filter for the full image, too much dynamic range and blue color was lost. The results in GIMP do not have these artifacts.

./retinex -m HSL -f 100 -s 200 "Image 2 2018-08-20_20-54-44-701.jpeg" "Image 2 2018-08-20_20-54-44-701_IM-Retinex.jpeg"

So what about the ability to see land across the smoke covered sound? After several attempts at processing the image with different variables, I concluded that the camera’s sensor never received an land feature. The smoke absorbed the light before it reached my camera. I did not take photos with my near IR camera, so I’m not sure if that light spectrum would have passed through the smoke. Anyway, it was a worth taking another look at Retinex. While doing this I noticed that automating GIMP would be extremely helpful. Unfortunately, many attempts at doing so proved that I needed to dedicate more time than I had available, maybe another time.

One other item that was brought to my attention, because of the smoke, was that the Washington state provides air quality information online, In addition to that site, the EPA also provides air quality for the nation, The image on the landing page is updated daily so I think I’ll scrape it and compile a video, One other site that was specific to smoke polution in the state of Washington was this site, It provided a link to view current conditions on a map, But wait, there is more, The data sets these sites provide are fairly extensive, I may take another pass at them with Cacti graphs, maybe another time.

Comments are closed.