Domanda

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.

È stato utile?

Soluzione

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.

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top