matlab用圆形填满矩形,【matlab】计算连通域的面积、周长、圆形度、矩形度以及长宽比...

clear,clc

RGB = imread('pillsetc.png');

figure,imshow(RGB);

I = rgb2gray(RGB);

threshold = graythresh(I);

bw = im2bw(I,threshold);

figure,imshow(bw)

% remove all object containing fewer than 30 pixels

bw = bwareaopen(bw,30);

% fill a gap in the pen's cap

se = strel('disk',2);

bw = imclose(bw,se);

% fill any holes, so that regionprops can be used to estimate

% the area enclosed by each of the boundaries

bw = imfill(bw,'holes');

figure,imshow(bw)

ed=edge(bw);

figure,imshow(ed)

%%%%%以上是图像二值化 上面制作二值化图像L = bwlabel(bw);

L1 = bwlabel(ed);

Ar=zeros(1,max(L(:)));

perimeter=zeros(1,max(L1(:)));

metric=zeros(1,max(L1(:)));

Pwl=zeros(1,max(L1(:)));

Pr=zeros(1,max(L1(:)));

for i=1:max(L(:))

Ar(i)=sum(bw(L==i));

perimeter(i)=sum(ed(L==i));

metric(i) = 4*pi*Ar(i)/perimeter(i)^2;

[y,x]=find(L==i);

x0=min(x(:));

x1=max(x(:));

y0=min(y(:));

y1=max(y(:));

hold on

rectangle('Position',[x0,y0,x1-x0,y1-y0],'edgeColor','g','LineWidth',1)

if x1-x0>=y1-y0

Pwl(i)=(x1-x0)/(y1-y0);

else

Pwl(i)=(y1-y0)/(x1-x0);

end

Pr(i)=Ar(i)/((y1-y0)*(x1-x0));

end

Ar

perimeter

metric

Pwl

Pr

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值