I have an image and I would like to turn all white pixels to red. How can I do this?
Thanks
No products are associated with this question.
Let me guess what your image is:
img = uint8(rand(640, 480, 3) * 255); R = img(:, :, 1); G = img(:, :, 2); B = img(:, :, 3); isWhite = R == 255 & B == 255 & G == 255; G(isWhite) = 0; B(isWhite) = 0; newImg = cat(3, R, G, B);
I do not like this solution. Is there an "inplace" method which does not duplicate the data?
Is (253,254,251) still white? (BTW, that's what my response was asking.) If so, you can alter the formula to use different thresholds. In that example, you'd use >= instead of == and the new threshold values:
isWhite = R >= 253 & G >= 254 & B >= 251;
Define the range of values that encompass white? Is it only (255,255,255) or could it be more of the possible 16.7 million colors?
2 Comments
Direct link to this comment:
http://www.mathworks.com/matlabcentral/answers/62310#comment_127252
"I have an image" is not clear. Is it an oilpainting, an indexed grayscale image as PNG, or an imported RGB array?
Direct link to this comment:
http://www.mathworks.com/matlabcentral/answers/62310#comment_127256
Is a RGB image.