I have to convert all non-red colors in an image to black, and then convert the red color to white. I am completely lost. Could anybody lead me in a direction? Thank you!

1 Kommentar

Voss
Voss am 5 Jul. 2020
If you have this image stored as an image file, the first thing to do would be to read the file into a variable, e.g., using the imread function.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

jonas
jonas am 5 Jul. 2020
Bearbeitet: jonas am 5 Jul. 2020

0 Stimmen

Load image
RGB = imread('image.png');
Image is stored as a nxmx3 matrix, where the 3 layers are red, green and blue pixel intensity and nxm is the resolution. Find pure red colors by finding the indices with strong red channels (1st layer close to 255) and weak green/blue channels (2nd and 3rd channels clsoe to zero).
mask = RGB(:,:,1)>230 & RGB(:,:,2)<1 & RGB(:,:,3)<1;
then you can use this mask to change the colors of your image
RGB(repmat(~mask,1,1,3)) = 0;
RGB(repmat(mask,1,1,3)) = 255;
imshow(RGB)

Weitere Antworten (0)

Kategorien

Mehr zu Convert Image Type finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 5 Jul. 2020

Bearbeitet:

am 5 Jul. 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by