MATLAB Answers

How can I compare two separate images (before and after) and count how many pixels are in a particular spectrum?

8 views (last 30 days)
Aizad Dasti
Aizad Dasti on 26 May 2020
Answered: Walter Roberson on 2 Jun 2020
I would like to quantify the number of pixels that are in a particular color range (glowing) in an image. There are two images below. I am interested in knowing how many pixels are flourescing on the subject's body. Image #1 should have zero (or close to zero) pixels glowing. Image #2 should have a great deal more.

  1 Comment

Walter Roberson
Walter Roberson on 26 May 2020
I would tend to think of converting to HSV, selecting a range of hue, in combination with a minimum saturation.
My second thought was that you might be able to threshold on brightness, but then I looked again and saw that their are a couple of lights that might turn out to be bright even though they are not the color you are looking for, so I think my first thought of HSV would be a better approach.

Sign in to comment.

Answers (2)


Walter Roberson
Walter Roberson on 2 Jun 2020
Example:
RGB=imread('image.jpeg');
figure(1)
imshow(RGB)
HSV = rgb2hsv(RGB);
H = HSV(:,:,1);
R = RGB(:,:,1); G = RGB(:,:,2); B = RGB(:,:,3);
maskH = H < 0.4 | H > 0.6;
R(maskH) = 0; G(maskH) = 0; B(maskH) = 0;
rec = cat(3,R,G,B);
figure(2);
imshow(rec)
This might not be good enough for your purposes, as it misses some of the streaks on the floor. But the 0.4 and 0.6 were chosen arbitrarily so there is room to tune them. If you
figure(3)
imshow(HSV);
then you can use a data cursor to explore the HSV values of the pixels of interest.

  0 Comments

Sign in to comment.