How can I detect a color percentage in a picture?

16 Ansichten (letzte 30 Tage)
fatema ali
fatema ali am 20 Nov. 2019
Kommentiert: DGM am 17 Mai 2022
I have a picture with different colors, but I mainly need the precentage of three colors. how can I do that in matlab?
  2 Kommentare
fatema ali
fatema ali am 20 Nov. 2019
Bearbeitet: fatema ali am 20 Nov. 2019
yes exactly, like the precentage of red in a certain picture.
I want a broader sense of colors, like all shades of red are considered as one thing and so on.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Kavya Vuriti
Kavya Vuriti am 17 Feb. 2020
It would be better if you first determine the RGB triplet limits for a specific color and count the number of pixels lying in the above range. The sample code could look like this:
% Read image
I = imread('your_image');
% Define RGB limits
redLowerLimit = your_value;
redUpperLimit = your_value;
blueLowerLimit = your_value;
blueUpperLimit = your_value;
greenLowerLimit = your_value;
greenUpperLimit = your_value;
% Number of pixels of required colour
requiredColor = ( I(:,:,1) >= redLowerLimit & I(:,:,1) <= redUpperLimit ) & ...
( I(:,:,2) >= greenLowerLimit & I(:,:,2) <= greenUpperLimit ) & ( I(:,:,3) >= blueLowerLimit & I(:,:,3) <= blueUpperLimit );
% Percentage of colour in the image
percentColor = 100*(sum(sum(requiredColor))/(size(I,1)*size(I,2)));
Hope this helps.
  2 Kommentare
DGM am 17 Mai 2022
You need to define the variables. You need to specify an image and select threshold values that are appropriate for your own needs.

Melden Sie sich an, um zu kommentieren.


Mehr zu Images finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by