【发布时间】:2021-04-03 12:48:49
【问题描述】:
我需要红色圆圈白色,其余为黑色。完全像二进制图像。我可以只过滤掉红色,然后做一些事情,但如何只包括圆圈? 我尝试了很多东西,但它不起作用。我猜是因为 MATLAB 的不推荐使用的功能。因为其中许多主题至少已有 10 年的历史。我试过这些:
https://nl.mathworks.com/help/images/ref/bwareaopen.html
https://nl.mathworks.com/matlabcentral/answers/19507-remove-non-circle-objects-from-image
我只是用这个代码接近了,但它仍然留下了正方形和六边形。我想让他们走,但不知道怎么走。我尝试增加 minExtend 或减少,但它没有这样做。
I=imread('circlesColored.png');
% Get the image as a b&w indexed (non-rgb) image
R=I(:,:,1);
R=(R>35&R<255);
imshow(R);
bwareaopen(I, 50);
BW = gray2ind(R, 2);
%Calculate its connected regions
L = bwlabel(BW); % Not using bwconncomps() for older version users
stats = regionprops(L,'Extent','Area');
%Find the ones that are like a circle
minExtent = 0.75;
keepMask = [stats.Extent]>minExtent;
%Extract the image of circles only and display
BWcircles = ismember(L, find(keepMask));
BWnonCircles = BW & ~BWcircles;
%Show the circles
figure, imshow(BWcircles)
【问题讨论】:
标签: image matlab image-processing