1
votes

I have a rgb image, I want to change the pixel values greater than (r:175,g:255,b:55) to Nan in matlab, How can I do that. Please let me know

1

1 Answers

3
votes

Find the locations

sel = bsxfun( @eq, I, permute( [175, 255, 55], [1 3 2] ) );

set to Nan

I( sel(:,:,[1 1 1]) ) = NaN;

Special care:
Your image I should be of floating point type (double or single) otherwise you will not be able to use NaN (NaN is defined only for floating point types). However, it is usually the case that for floating-point images the RGB value ranges between 0 and 1 (and not 255).
So, you might want to compare to [175 255 55]/255 instead...