count number of non gray pixels in RGB image in matlab

亡梦爱人 提交于 2019-12-25 02:29:28

问题


I have a RGB image which has only black and white squares. I want to count number to non gray pixels in this image. I am new to matlab. I want to check the quality of image as it should only contain black and white pixels.Actually I have undistorted this image due that some colored fringes are appeared.I want to know the how many color are introduced to check the quality of the image.


回答1:


using matlab to get counts of specific pixel values in an image.

Images are RGBA <512x512x4 uint8> when read into matlab (although we can disregard the alpha channel).

Something like this

count = sum(im(:, :, 1) == 255 & im(:, :, 3) == 255 & im(:, :, 3) == 255);

will give you the count of such pixels. Replace sum with find to get the indices of those pixels if you need that.




回答2:


A pixel is said to be gray if its R,G,B components are all same.

Using this logic

%// checking for equality of R,G,B values
B = any(diff(im,[],3),3);  %// selecting only non-gray pixels
count = sum(B(:));         %// Number of non-gray pixels

PS: This answer is tailored from this and this answer.



来源:https://stackoverflow.com/questions/23592837/count-number-of-non-gray-pixels-in-rgb-image-in-matlab

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