using histogram to determine colored object presence?

久未见 提交于 2019-12-06 05:43:14

Another way to do it that would be more insensitive to lighting would be to look for red hues after converting to HSV colorspace. But since red has the same 0 hue as black/gray/white, I would invert the image so that red becomes cyan. So histogram the hue channel after inverting and converting to HSV and look for values at cyan hue near 180 degrees or its equivalent of 50% gray or 128 in the range of 0 to 255. In imagemagick, you would do

convert XqG0F.png -negate -colorspace HSV -channel red -separate +channel -define histogram:unique-colors=false histogram:without_hist.png

convert x5hWF.png -negate -colorspace HSV -channel red -separate +channel -define histogram:unique-colors=false histogram:with_hist.png

So you can see in the second image (for the red bar), there is a substantial broad peak near mid-way i.e., 50% (horizontally), but none in the first image in that region.

You could do an FFT to get the spectrum of each image. The image with the striped bar has a repetitive pattern that should show up in the spectrum. Using ImageMagick:

Without the bar:

convert XqG0F.png -fft +delete -evaluate log 100000 without.png

With bar:

convert x5hWF.png -fft +delete -evaluate log 100000 with.png

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!