How to extract a particular colour from an RGB image?
73 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
SUKUMAR NAGINENI
el 3 de Jun. de 2021
Comentada: Rupika
el 17 de Nov. de 2023
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/641320/image.png)
0 comentarios
Respuesta aceptada
Walter Roberson
el 5 de Jun. de 2021
Editada: Walter Roberson
el 5 de Jun. de 2021
Not perfect, but it will give you a starting point.
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/641315/f00167.png';
rgb = imread(filename);
HSV = rgb2hsv(rgb);
mask1 = HSV(:,:,1) < 0.2;
mask2 = HSV(:,:,2) > 0.3 & HSV(:,:,2) < 0.7;
mask3 = HSV(:,:,3) > 0.2 & HSV(:,:,3) < 0.6;
mask = mask1 & mask2 & mask3;
BW = bwareafilt(mask,[30 inf]);
filtered_RGB = rgb .* uint8(BW);
imshow(filtered_RGB)
9 comentarios
Rupika
el 17 de Nov. de 2023
Hi, I am doing something similar to this. After obtainig the filtered_RGB image, i want to blend only the colored parts to another image on a particular location. But when i tried it the backgound black region is also getting blended. Can you help me!!
Más respuestas (1)
Sulaymon Eshkabilov
el 4 de Jun. de 2021
(1) Image read: imread('traffic.png')
(2) Select and Find out the pixel value ranges of a red color, e.g.:
I = imread('traffic.png');
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
0 comentarios
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!