I=imread('C:\Users\kasim\Desktop\temp\ss001.jpg');%读入图像
B=rgb2hsv(I);%将图像由RGB颜色空间转为HSV颜色空间
B=B(:, :, 2);%提取饱和度(Saturation)分量
Z=im2bw(B,0.5);%图像二值化
Z=imclose(Z, strel('disk',7));%创建圆形模版
D=imfill(Z, 'holes');%填充
A1=bwareaopen(D,200);%去除图像中的小目标物体
[B,L] = bwboundaries(A1,'noholes');
imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2)
end
stats = regionprops(L,'Area','Centroid');
threshold = 0.8;%圆的判断
% loop over the boundaries
for k = 1:length(B)
% obtain (X,Y) boundary coordinates corresponding to label 'k'
boundary = B{k};
% compute a simple estimate of the object's perimeter
delta_sq = diff(boundary).^2;
perimeter = sum(sqrt(sum(delta_sq,2)));
% obtain the area calculation corresponding to label 'k'
area = stats(k).Area;
disp(area);
% compute the roundness metric
metric = 4*pi*area/perimeter^2;
% display the results
metric_string = sprintf('%2.2f',metric);
% display the results
area_string = sprintf('%2.2f',area);
% mark objects above the threshold with a black circle
if metric > threshold
centroid = stats(k).Centroid;
plot(centroid(1),centroid(2),'ko');
end
text(boundary(1,2)-35,boundary(1,1)+13,area_string,'Color','y',...
'FontSize',14,'FontWeight','bold');
end
title(['Metrics closer to 1 indicate that ',...
'the object is approximately round']);
CW.rar_体积_气泡直径_气泡直径标记_起泡判断_边界处理
版权申诉
5星 · 超过95%的资源 38 浏览量
2022-07-14
18:26:20
上传
评论
收藏 176KB RAR 举报
小贝德罗
- 粉丝: 70
- 资源: 1万+
最新资源
- Python 程序语言设计模式思路-行为型模式:策略模式:将算法封装成独立的类,并使它们可以互相替换及支付模式数据压缩
- main.py
- Last Loaded Test.DBK
- Screenshot_20240520_163011.jpg
- ubuntu-python3-whisper-tornado docker镜像 Dockerfile
- ubuntu-python3-whisper-tornado docker镜像07
- 新录音 8.m4a
- ubuntu-python3-whisper-tornado docker镜像
- ubuntu-python3-whisper-tornado docker镜像
- ubuntu-python3-whisper-tornado docker镜像09
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈