# How to extract a particular colour from an RGB image?

84 views (last 30 days)
SUKUMAR NAGINENI on 3 Jun 2021
Commented: SUKUMAR NAGINENI on 12 Jun 2021
Dear all,
I want to extract a particular colour from an RGB image. If that specific colour is present in an image, I wish to replace it with a zero pixel intensity. In the figure below, the arrow points out the light red colour; here, I want to extract this particular light red colour from the image. If it is present in the image, I want to replace it with a zero intensity level with that particular colour.
How to make a logic to extract a particular colour from an image?

Walter Roberson on 5 Jun 2021
Edited: Walter Roberson on 5 Jun 2021
Not perfect, but it will give you a starting point.
HSV = rgb2hsv(rgb);
mask2 = HSV(:,:,2) > 0.3 & HSV(:,:,2) < 0.7;
mask3 = HSV(:,:,3) > 0.2 & HSV(:,:,3) < 0.6;
filtered_RGB = rgb .* uint8(BW);
imshow(filtered_RGB)
SUKUMAR NAGINENI on 12 Jun 2021
Sorry, I forgot to click on the accepted answer.

Sulaymon Eshkabilov on 4 Jun 2021
(2) Select and Find out the pixel value ranges of a red color, e.g.:
PXY = impixel(I); % Once done selecting enough number of pixel points, hit ENTER from keyboard
R = (PXY(:,1)); % G = (PXY(:,2)); B = (PXY(:,3)); % If interested in Green Or Blue
Rm=min(R); % Gm=min(G); Bm=min(B);
(3) Use logical indexing, e.g.:
RED = I(:,:,1);
GREEN = I(:,:,2);
BLUE = I(:,:,3);
RED(RED>=Rm)=0; % For RED color layer
GREEN(RED>=Rm)=0; % For GREEN color layer
BLUE(RED>=Rm)=0; % For BLUE color layer
NEW_Im(:,:,1) =RED;
NEW_Im(:,:,2) =GREEN;
NEW_Im(:,:,3) =BLUE;
imshow(NEW_Im), shg