We were wondering if it was possible to do something like the attached pictures.
We have a live weather radar on our website, projected on a google maps page with an update cycle of 5 minutes.
What is the idea?
We want to detect the "heavy" storms for our visitors and highlight them with a square box or something. If it is possible we want to make this system in PHP. I think the best way is to detect colors or something?
Attached the images as example we have drawn with Photoshop:
We hope someone can help us out so we can started with something!
I just discovered that
ImageMagick
can do Connected Components Analysis so I can now provide an even simpler solution that does not rely on my C coding.Here it is:
Here is the resulting image:
and here are the labelled objects from file
baddies.png
Here are some notes on the code...
-fuzz 50% allows some degree of variation in the detected shades of red
-fill white +opaque red - changes all red pixels to white
-fill black -opaque red - changes all non-red pixels to black
-define connected-components:verbose=true - causes diagnoatic output so I can get the bounding boxes it finds
-define connected-components:area-threshold=100 - says I am only interested in red areas of 100 pixels in size or greater
-connected-components 8 - says red dots can be joined to their 8-neighbours (i.e. diagonally joined, rather than square-joined)
-auto-level baddies.png - contrast stretches the labelled storm objects and saves them in a file called
baddies.png
The
awk
stuff is just like theawk
stuff in my other answer.Just for other people to see the output of ImageMagick's Connected Component Analysis in the first stage, it looks like this:
The parameters to the final
convert
command look like this:I would isolated the red cells by using the -fx operator.
The
p.r > p.b
remove white colors, and thep.r > 0.9
checks the current pixel against a threshold of0.9
.This approach requires some extra CPU time, but does give you the ability to adjust the degree of severity.
The proper way to do that would probably be using some kind of Blob Analysis to extract the red areas and do bounding boxes around them. It's not that hard, but in starting that approach, I can do something much simpler, yet quite effective, with a single line of ImageMagick. It is free and available at the command line and with PHP, Perl, Python and other bindings.
So, I was going to convert all the red areas to white, and all the non-red areas to black, then run a Blob Analysis and draw red bounding boxes around the white blobs. But on the way, I thought about maybe making the non-red areas of the image semi-transparent and then red areas fully transparent, so the focus of attention is on the red stuff and all the other stuff is really pale. That can be done in a single ImageMagick command like this:
The result is like this:
The numbers can obviously be tweaked if you like the approach...
I had another attempt at this, using some
Connected Component Analysis
software I wrote in C. It is readily compiled on any OS X/Linux/Windows machine.So, here is the script:
The file
weather.pgm
comes out like this:Partial output of
cca
programThe final
convert
command in the script gets called like this:And the result is like this:
The
cca.c
program is like this: