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.
Asked
Active
Viewed 729 times
0
-
3How do you define non-gray pixels or even gray pixels in a RGB image that has only black and white squares? – Divakar May 11 '14 at 14:17
2 Answers
0
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.

Arjun Chaudhary
- 2,373
- 2
- 19
- 36
-
-
http://www.mathworks.in/matlabcentral/answers/25368-selecting-and-removing-all-grey-pixels-in-an-rgb-image follow this link u will get your exact answer. Do opposite of what they are saying – Arjun Chaudhary May 11 '14 at 13:28
-
however above code will also work but i havent tested just let me know if error is there – Arjun Chaudhary May 11 '14 at 13:34
0
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

Community
- 1
- 1

Santhan Salai
- 3,888
- 19
- 29