How to detect percentage of a color range inside an Image?
2 views (last 30 days)
Show older comments
Hello
I'm working on this coin detection project using matlab and I wanna know how to detect the color of the center of a coin.
I have these intervals that define the color I want : minvalue = [5 75 85], maxvalue = [50 255 255] and I wanna calculate the percentage of this interval inside an Image.
How can I do that? I did it using inrange with opencv but I couldn't figure it out on matlab.
0 Comments
Answers (1)
DGM
on 19 Jan 2022
Something like this:
A = imread('coloredChips.png'); % i just grabbed a picture that had some greens
imshow(A)
minvalue = [5 75 85];
maxvalue = [50 255 255];
mask = A(:,:,1)>=minvalue(1) & A(:,:,1)<=maxvalue(1) ...
& A(:,:,2)>=minvalue(2) & A(:,:,2)<=maxvalue(2) ...
& A(:,:,3)>=minvalue(3) & A(:,:,3)<=maxvalue(3);
imshow(mask)
% this is the fraction of the image that lies within
% the rectangular prism defined by the two corner points
maskcoverage = mean(mask,'all')
0 Comments
See Also
Categories
Find more on Feature Detection and Extraction in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
