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, http://www.fmwconcepts.com/imagemagick/retinex/. 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, https://en.wikipedia.org/wiki/Color_constancy#Retinex_theory. 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, http://www.russellcottrell.com/RCFilters/Retinex.asp. In it, this photo was demonstrated which I used as well, https://en.wikipedia.org/wiki/South_Solon,_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, https://fortress.wa.gov/ecy/enviwa/. In addition to that site, the EPA also provides air quality for the nation, https://www.airnow.gov/. The image on the landing page is updated daily so I think I’ll scrape it and compile a video, https://files.airnowtech.org/airnow/today/cur_aqi_usa.jpg. One other site that was specific to smoke polution in the state of Washington was this site, http://wasmoke.blogspot.com/. It provided a link to view current conditions on a map, https://tools.airfire.org/airtools/v1/pnw-smoke.html?lat=47.3&lng=-119.5&zoom=6. But wait, there is more, http://rammb-slider.cira.colostate.edu/?sat=goes-17&sec=full_disk&x=6600&y=2272&z=5&im=12&ts=1&st=20180905200032&et=20180905210032&speed=130&motion=loop&map=1&lat=0&p%5B0%5D=16&opacity%5B0%5D=1&hidden%5B0%5D=0&pause=0&slider=-1&hide_controls=0&mouse_draw=0&s=rammb-slider. The data sets these sites provide are fairly extensive, I may take another pass at them with Cacti graphs, maybe another time.