Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
394 views
in Technique[技术] by (71.8m points)

php - Color detection on GIF or PNG image

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!

original image heavy storms highlighted with square boxes

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:

convert http://i.stack.imgur.com/qqein.png               
    ( +clone                                            
       -fuzz 30%                                         
       -fill "#222222" +opaque red                        
       -fill "#ffffff" -opaque red -colorspace gray )   
    -compose copy-opacity -composite out.png

The result is like this:

enter image description here

The numbers can obviously be tweaked if you like the approach...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...