Adding a response text to a color detection code and another color to detect.

1 vue (au cours des 30 derniers jours)
Hello, so i have a color detection code which i learned from youtube
I=imread("RGBPlate.JPG");
subplot(2,2,1);
imshow(I);
G=rgb2gray(I);
subplot(2,2,2);
imshow(G);
A = I (:,:,1);
subplot (2,2,3);
imshow (A);
F=imsubtract(A,G);
F = im2bw(F, 0.18);
subplot(2,2,4);
imshow(F)
The photo (RGBPate.JPG)
The output of the code
my code can detect the color Red from the photo.
My question for this code are:
  1. how do i make it so when the code detects the color red, the command window will show a text that reads "Roses" same goes for other colors. When it detecs blue, the command window will show a text that reads "Anemone" and etc.
  2. From what i know
A = I (:,:,1);
can detect colors Red, Green, Blue from changing the numbers from 1,2,3 respectively. What is the proper code for detecting the color black?
I am currently using the lastest Matlab which is R2021b
Thank you for taking the time to read this post.
  1 commentaire
yanqi liu
yanqi liu le 11 Jan 2022
yes,sir,may be use rgb2hsv or rgb2lab and so on,to get color space change

Connectez-vous pour commenter.

Réponse acceptée

DGM
DGM le 11 Jan 2022
Modifié(e) : DGM le 11 Jan 2022
In order to be able to say that a color is (e.g.) "aquamarine" or "turquoise" or some particular name, you need to define explicitly what those words mean in some color space and then find the closest named color by minimizing some distance metric between the named colors and your color tuple of interest.
Or you could just use something like this to convert between RGB tuples and the color names defined by a selected palette.
colornames('css',parula(8))
ans =
8×1 cell array
{'MediumBlue' }
{'MediumSlateBlue' }
{'DodgerBlue' }
{'SkyBlue' }
{'MediumAquamarine'}
{'YellowGreen' }
{'Goldenrod' }
{'Yellow' }
colornames('natural',jet(8))
ans =
8×1 cell array
{'Blue' }
{'Blue' }
{'Green' }
{'Green' }
{'Yellow'}
{'Yellow'}
{'Red' }
{'Red' }
You'll have to read the documentation, as there are multiple palettes available and different ways of calculating color differences. See the included tool colornames_deltaE().
If you want to detect black using what you've already calculated, just perform a thresholding operation on the grayscale array itself. You'll have to decide what an appropriate threshold would be.
blackregions = G<thresholdvalue;

Plus de réponses (0)

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by