selecting and removing all grey pixels in an RGB image
32 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Titus Edelhofer
on 5 Jan 2012
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
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.
Sara
on 5 Jan 2012
1 Comment
Titus Edelhofer
on 5 Jan 2012
Hi Sara,
for sake of completeness: in your solution at least the most inner loop could be saved: inside the y-loop it would have been sufficient to write
if idx(x,y)==1
I2(x,y,:) = 0;
end
Titus
Titus Edelhofer
on 5 Jan 2012
Hi Sara,
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);
Titus
4 Comments
Image Analyst
on 8 Apr 2015
Abdoo, I think you missed my comment, between your two, about posting a new, separate question in a separate thread.
In the meantime, see my File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862. My demos there are very close to what you want to do.
Gebra maryam Alehegn
on 2 May 2017
How to read multiple image from folder and extract RGB color features????
See Also
Categories
Find more on Modify Image Colors in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!