MATLAB: Selecting and removing all grey pixels in an RGB image

greyscaleimage analysisrgbthermal image

I have a set of fused optical and infrared images I need to analyse. The optical part of the image is visually greyscale and the infrared part is represented by colored blobs. The size, location, range and intensity of each blob changes with each image. Each image is an RGB 480 * 640 * 3 matrix of rgb values. I want to isolate the thermal section from each image and turn the optical portion to black.
Obviously, I can't apply a simple threshold to this because the "grey" part still ranges from 0:255. Edge detection and normal image techniques aren't working well because the grey part of the image is very noisy and grainy. I don't want to convert the whole image to grey because then I'd lose the colour mapping of the thermal portion.
I thought the best way would be masking out the grey images was to find where each pixel that is the same in each colour dimension.
for i = 0:255
A = im(:,:,1) & im(:,:,2) & im(:,:,3) == i;
end
That is obviously just for one image. I thought that if I could get a matrix of A which shows all the pixel locations where rgb is the same in all dimensions, for each value of i, I could use that to mask the non-thermal parts of my photo.
But the code above only identifies about 20 pixels, and not all of them are in the right locations. I'm not a programmer so none of this is obvious to me.
Where am I going wrong?

Best Answer

Hi,
what about looking for all pixels that are somewhat "greyish"? Instead of R, G and B exactly the same you could test
idx = abs(im(:,:,1)-im(:,:,2))<=tresh & abs(im(:,:,2)-im(:,:,3))<=thresh;
Thresh could be 1 or 2 (give it a try) so a pixel [50 51 50] would be considered grey as well.
Titus