Hi,
You can use ‘Color Thresholder’ app provided in the Image Acquisition Toolbox.
- After loading the image from a file/workspace, you can choose a color space for the image. Since you want to extract purple and yellow colours, I would recommend you to use YCbCr for purple colour and RGB space for the yellow colour.
- You would then see the image along with a set of controls for each colour component, depending on the colour space chosen. Adjust these controls to get the colour you want. And ‘Export Function’ for the resultant image.
- By exporting to function, you get Min and Max values for each channel for both the colours (yellow and Purple). You would also get a sliderBW matrix in each function. Use logical operator || to include both the matrices in your workspace and then set these pixels to white colour.
You can also refer to an example for purple colour from the documentation provided in the link. Below is the code for an image file named ‘peppers.png’ and may need to be changed in some cases -
I = RGB;
channel1Min = 53.000;
channel1Max = 178.000;
channel2Min = 55.000;
channel2Max = 153.000;
channel3Min = 37.000;
channel3Max = 142.000;
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
maskedRGBImage = RGB;
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;
Best Answer