0

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.

  • 3
    How 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 Answers2

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,163
  • 2
  • 14
  • 30
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

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

Community
  • 1
  • 1
Santhan Salai
  • 3,848
  • 17
  • 29