Using Image Magick to measure "Cloudiness" of the Sky

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
AndrewDJohnson
Posts: 2
Joined: 2013-10-06T04:30:13-07:00
Authentication code: 6789

Using Image Magick to measure "Cloudiness" of the Sky

Post by AndrewDJohnson »

Hi,

I came across another thread viewtopic.php?f=3&t=12818 about analysing images, but I couldn't work out how to go from that to what I would like to do, which seems to be similar.

Basically, I want to take an image of the sky (only 640 x 480) and measure how "blue" it is - or how grey/cloudy. I have plenty of comparison images I could use and am not sure whether to try and use convolution or just some type of histogram.

Ideally, I'd like to come with a percentage figure which approximates to the "blueness" of the image.

Any thoughts/ideas or example commands/scripts would be wonderful.

Thanks for reading.

Andrew
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using Image Magick to measure "Cloudiness" of the Sky

Post by fmw42 »

This needs to be moved to the Users forum, not the Wizard's User forum.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Using Image Magick to measure "Cloudiness" of the Sky

Post by snibgo »

When we used black and white film cameras, we would put red filters over the lens to block the blue light from the sky, increasing the contrast between sky and cloud.

Code: Select all

convert %SRC% ^
  -auto-level ^
  ( +clone -modulate 100,0,100 -write c0.png +delete ) ^
  -separate ^
  -delete 1-2 ^
  cr.png
The Windows script above creates two b/w images. c0.png is ordinary monochrome. cr.png is just the red channel. Then we can subtract one from the other.

Code: Select all

convert ^
  c0.png c.png ^
  -compose MinusSrc -composite ^
  -threshold 3%% ^
  -negate ^
  -format %%[fx:mean] -write info: ^
  cd.png
cd.png is white where there are clouds and black where there is blue sky. It also writes a number, eg "0.642875", which represents how much of the image is cloud, on a scale of zero to one. It also creates cd.png for a visual check that it has correctly identified cloud and sky.

You may need to adjust "-threshold 3%%" for your sky and camera. The script is quite primitive. A more sophisticated script would establish the exact colour blue of the sky.

The two commands could be combined into one, of course.
snibgo's IM pages: im.snibgo.com
AndrewDJohnson
Posts: 2
Joined: 2013-10-06T04:30:13-07:00
Authentication code: 6789

Re: Using Image Magick to measure "Cloudiness" of the Sky

Post by AndrewDJohnson »

snibgo wrote:When we used black and white film cameras, we would put red filters over the lens to block the blue light from the sky, increasing the contrast between sky and cloud.

convert %SRC% ^
-auto-level ^
( +clone -modulate 100,0,100 -write c0.png +delete ) ^
-separate ^
-delete 1-2 ^
cr.png
The Windows script above creates two b/w images. c0.png is ordinary monochrome. cr.png is just the red channel. Then we can subtract one from the other.

convert ^
c0.png cr.png ^
-compose MinusSrc -composite ^
-threshold 3%% ^
-negate ^
-format %[fx:mean] -write info: ^
cd.png

cd.png is white where there are clouds and black where there is blue sky. It also writes a number, eg "0.642875", which represents how much of the image is cloud, on a scale of zero to one. It also creates cd.png for a visual check that it has correctly identified cloud and sky.

You may need to adjust "-threshold 3%%" for your sky and camera. The script is quite primitive. A more sophisticated script would establish the exact colour blue of the sky.

The two commands could be combined into one, of course.
Hey - thanks for this - I am now playing around with this method - but I had to make the corrections shown above to get it to produce a figure... I am also trying one based on one of "fred's tidbits" http://www.fmwconcepts.com/imagemagick/ ... #ave_color
I am not needing something especially precise - just a guide.

But thanks so much for taking the time!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Using Image Magick to measure "Cloudiness" of the Sky

Post by snibgo »

Yes, sorry, I'd forgotten I had renamed a file. The doubled % is needed only when in a command (batch) file.
snibgo's IM pages: im.snibgo.com
Post Reply