MATLAB:Image Processing Toolbox工具箱入门实战(1),超详细讲解

I = imread(“1.jpg”);
whos I % 使用 whos 命令,检查 imread 函数如何在工作区中存储图像数据。
% 调用 imhist 函数创建直方图。
% 请在调用 imhist 之前使用 figure 命令,这样直方图就不会覆盖当前图窗窗口中显示的图像 I。
imhist(I)
I2 = histeq(I); % 使用 histeq 函数提高图像的对比度
imshow(I2)
imwrite(I2, ‘2.jpg’); % 使用 imwrite 函数,将刚刚经过调整的图像 I2 写入磁盘文件
imfinfo(‘2.jpg’) % imfinfo 函数返回文件中图像的相关信息


![](https://img-blog.csdnimg.cn/direct/5ee7be33c41d44c7b05d2996d136f141.png)


#### 2.实战项目一:利用imfindcircles()函数检测和测量图像中的圆形目标


[Detect and Measure Circular Objects in an Image- MATLAB & Simulink ExampleThis example shows how to automatically detect circular objects in an image and visualize the detected circles.![icon-default.png?t=N7T8](https://csdnimg.cn/release/blog_editor_html/release2.3.6/ckeditor/plugins/CsdnLink/icons/icon-default.png?t=N7T8)https://www.mathworks.com/help/releases/R2021b/images/detect-and-measure-circular-objects-in-an-image.html](https://www.mathworks.com/help/releases/R2021b/images/detect-and-measure-circular-objects-in-an-image.html "Detect and Measure Circular Objects in an Image- MATLAB & Simulink Example")imfindcircles()使用基于圆形 Hough 变换 (CHT) 的算法在图像中寻找圆形。之所以使用这种方法,是因为当存在噪声、遮挡和变化的光照条件时该方法表现稳健。


有关imfindcircles()的详细信息,请参阅帮助文档:


[Find circles using circular Hough transform - MATLAB imfindcirclesThis MATLAB function finds the circles in image A whose radii are approximately equal to radius.![icon-default.png?t=N7T8](https://csdnimg.cn/release/blog_editor_html/release2.3.6/ckeditor/plugins/CsdnLink/icons/icon-default.png?t=N7T8)https://www.mathworks.com/help/releases/R2021b/images/ref/imfindcircles.html](https://www.mathworks.com/help/releases/R2021b/images/ref/imfindcircles.html "Find circles using circular Hough transform - MATLAB imfindcircles")本项目旨在演示调参来寻求圆目标的过程。


![](https://img-blog.csdnimg.cn/direct/7feb7f0d4db64bcfb7aa0e5a7fa3e7e9.png)



rgb = imread(‘coloredChips.png’);
imshow(rgb)

% 此段代码是为了清楚对象是比背景亮还是比背景暗,输出灰度图片看一看
% gray_image = rgb2gray(rgb);
% imshow(gray_image)

% 此段代码用来确定imfindcircles函数里的radiusRange,测出来应该是[25 30]
% d = drawline; % 画一条线,大致画出圆的直径
% pos = d.Position % 线的位置
% diffPos = diff(pos); % 各行之间的一阶差分,也就是delta x和delta y
% diameter = hypot(diffPos(1),diffPos(2)) % 平方和的平方根(斜边)

% 这里开始找圆,用的是imfindcircles()函数
% 背景相当亮,大多数塑料片比背景暗,将参数 ‘ObjectPolarity’ 设置为 ‘dark’ 以搜索较暗的圆。
% imfindcircles 有两种不同寻找圆的方法:默认方法(称为相位编码方法)/两阶段方法,这里指定使用两阶段方法
% 两种方法都能准确找到部分可见(遮挡)塑料片的中心和半径。
[centers,radii] = imfindcircles(rgb,[25 30],‘ObjectPolarity’,‘dark’, …
‘Sensitivity’,0.92,‘Method’,‘twostage’);

% 注意到黄色圆都没有被检测到
% 与背景相比,黄色塑料片的强度几乎相同,甚至更亮。因此,要检测黄色塑料片,‘ObjectPolarity’ 改为 ‘bright’。
% [centersBright,radiiBright] = imfindcircles(rgb,[25 30], …
% ‘ObjectPolarity’,‘bright’,‘Sensitivity’,0.95)
% 找到了三个原先未检测到的黄色塑料片&#

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值