MATLAB: Change pixel colour / intensity from black to white, white remains white, and from other colour to black

codesdigital image processingImage Processing Toolboxintensitypixel values

hi there. I need to segment the stroke in the ct scan image of the brain below. what i need to do before the segmentation is change the stroke color to the only black intensity in the image. the command in written form is
if pixel value = 0, change to 1, if pixel value = 1, maintain to be 1, if pixel value not 0 and 1, change to 0.
the problem is, i do not know how to write the matlab code represents them. please anyone, help me.. thank you in advance.
note: the image is in RGB. do we need to change to gray..?

Best Answer

YourRGBImage = imread(....); %or dicomread() as appropriate
GrayImage = rgb2gray( im2double( YourRGBImage ) );
BWImage = (GrayImage == 0 || GrayImage == 1);