How to detect percentage of a color range inside an Image?
10 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
DGM
2022-1-19
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!