selecting and removing all grey pixels in an RGB image
17 views (last 30 days)
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;
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?
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.
More Answers (4)
Image Analyst on 5 Jan 2012
You can't deal with the pseudocolored image. You need to obtain the actual grayscale infrared image. If that image is just one of the color planes and the optical image is in the other two color channels, then you're in luck. If not, you're going to have to find out how to obtain the thermal image by itself. I've dealt with thermal cameras so I know it can be done.
the trick is to change the image from NxMx3 to (N*M)x3:
% store the size
s = size(I);
% make I a matrix with 3 columns and 480*640 rows:
I = reshape(I, s(1)*s(2), 3);
% apply the "filter:
I(idx(:),:) = 0;
% restore the original size
I = reshape(I, s);