简体   繁体   中英

how to change the pixel values in a rgb image in matlab

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

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM