MATLAB: Black pixels to white

image processingrgb

Does anyone know a simple way to convert black pixels in a background to white in a jpg? The image is extremely simple with a solid black background and a solid red object. I just want to make the background white (other than doing it by hand in Photoshop since there will be many similar images).

Best Answer

%I is your image
M = repmat(all(~I,3),[1 1 3]); %mask black parts
I(M) = 255; %turn them white
This is only setting parts that are pure black to white, it could easily be modified to dark parts etc. with:
M = repmat(all(I<20,3),[1 1 3]); %mask values less than 20 in RGB
Related Question