matlab - 查找图像中物体的直径
问题描述
我在使用 MATLAB 查找图像中物体的直径时遇到问题。下面是它的源代码。请帮助我的代码中缺少的内容。
obj=imread('C:\Users\Khan\Desktop\basebal.jpg');
imshow(obj);
red =obj(:,:,1);
green =obj(:,:,2);
blue =obj(:,:,3);
figure
subplot(2,3,1),imshow(obj);title('original image');
subplot(2,3,2),imshow(red);title('red ball');
subplot(2,3,3),imshow(green);title('green ball');
subplot(2,3,4),imshow(blue);title('blue ball');
figure
level =0.41;
bw2=im2bw(blue,level);
subplot(2,2,1),imshow(bw2);title('blue plane thresholded');
fill =imfill(bw2,'holes');
subplot(2,2,2),imshow(fill);title('holes filled');
clear = imclearborder(fill);
subplot(2,2,3),imshow(clear);title('remove blobs on border');
se=strel('disk',7);
open=imopen(fill,se);
subplot(2,2,4),imshow(open);title('remove small blobs');
diameter = regionprops(open,'MajorAxisLength');
figure
imshow(obj)
d=imdistline;
该代码用于显示斑点的直径并在线显示,但由于结果不准确而缺少某些内容。
下图显示了代码的输入和输出:
这是输入图像:
解决方案
根据您希望结果的准确性和自动化程度,您有几个机会。
最简单的是使用d = imdistline;
,这是一个交互式工具,它可以让您像尺子一样测量球。
imshow(obj)
d = imdistline;
或者,您可以使用该imfindcircles
功能,它允许您指定半径范围,然后找到具有此类半径的圆形对象。虽然,你必须发挥敏感性,我很容易发现以下工作
[centers,radii] = imfindcircles(obj,[100 150],'Sensitivity',0.95);
这给了我半径是109.6432
,因此直径是219.2864
。
您还可以绘制圆圈
imshow(obj)
viscircles(centers,radii);
这使
推荐阅读
- meteor - Apollo graphQL 多突变乐观优化
- docker - 将 docker 命令发送到 Azure App Service for Containers
- linux - 在命令行中将参数传递给 ksh 脚本时转义反引号 - 坟墓(`)
- java - Spring 与 Swing 集成失败,java.awt.HeadlessException,BeanCreationException,BeanInstantiationException .SPRING BOOT
- java - 听不同的客户(java)
- pandas - 连接条形图/烛台图上两点的线
- teradata - Teradata TPT 删除单引号的尾随句点或转义字符
- r - 如何计算互信息
- php - 使用 Laravel 5 订阅 Websocket API
- javascript - 从 Mysql DB 到 Javascript 计时器的日期