I got an open question, but wasn't able to find any question exactly similar to mine so here I come.
I would like to know if some algorithm (/or existing plugin) might be able to detect the presence (image 1) or not(image 2) of the blue light in the middle of the image?
My main skills are PHP and Javascript, but I can also use Java if necessary, or even another language if there's no other way...
Any help even small for pointing me out in the right direction is appreciated.
You can do something pretty basic with ImageMagick straight from the command-line without needing any code. It is installed on most Linux distros and is available for OSX and Windows.
Basically, you would be looking for pixels where the Blue channel is much greater than either the Red or the Green channel and where the Saturation is high. You can do that like this:
convert on.jpg -fx "u.b>(u.g+0.2) && u.b>(u.r+0.2) && saturation>0.6" result.png
Whereas when you run that for the off
image:
convert off.jpg -fx "u.b>(u.g+0.2)&&u.b>(u.r+0.2)&&saturation>0.6" result.png
You can count the white pixels in the above images like this:
convert result.png -format "%[fx:mean*w*h]" info:
1227
so there are 1227 pixels identified as bright blue in the on
image and there are 26 identified in the off
image.
You can test both images without needing to create the intermediate output files I made above:
convert off.jpg -fx "u.b>(u.g+0.2)&&u.b>(u.r+0.2)&&saturation>0.6" -format "%[fx:mean*w*h]" info:
26
convert on.jpg -fx "u.b>(u.g+0.2)&&u.b>(u.r+0.2)&&saturation>0.6" -format "%[fx:mean*w*h]" info:
1227
Of course, you may want to diddle and experiment with the numbers I suggested.
Note also that there are C, C++, C#, PHP, Perl, Javascript, Ruby and other bindings for ImageMagick - so you can do all the above just the same in any language really. Or just exec()
or system()
the stuff above.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.