网站后台如何做,seo的方法,制作一个html网页,晋城建设网站目录
1.基本图像导入、处理和导出
2.实战项目一#xff1a;利用imfindcircles()函数检测和测量图像中的圆形目标 1.基本图像导入、处理和导出
Basic Image Import, Processing, and Export- MATLAB SimulinkThis example shows how to read an image into the worksp…目录
1.基本图像导入、处理和导出
2.实战项目一利用imfindcircles()函数检测和测量图像中的圆形目标 1.基本图像导入、处理和导出
Basic Image Import, Processing, and Export- MATLAB SimulinkThis example shows how to read an image into the workspace, adjust the contrast in the image, and then write the adjusted image to a file.https://www.mathworks.com/help/releases/R2021b/images/image-import-and-export.html以下是输入的缺陷检测图片1.jpg左和经过histeq直方图均衡使强度值扩展分布到了图像的完整范围内函数提高对比度的2.jpg右。
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 函数返回文件中图像的相关信息 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.https://www.mathworks.com/help/releases/R2021b/images/detect-and-measure-circular-objects-in-an-image.htmlimfindcircles()使用基于圆形 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.https://www.mathworks.com/help/releases/R2021b/images/ref/imfindcircles.html本项目旨在演示调参来寻求圆目标的过程。 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)
% 找到了三个原先未检测到的黄色塑料片但仍有黄色塑料片未检测到% 要查找圆imfindcircles 仅使用图像中的边缘像素。这些边缘像素基本上是具有高梯度值的像素。
% EdgeThreshold 参数控制像素的梯度值必须有多高才能将其视为边缘像素并包含在计算中。
% 该参数的高值更接近 1只允许包含强边缘较高梯度值而低值更接近 0的宽容度更高可在计算中包含较弱的边缘较低梯度值。
% 对于检测不到黄色塑料片的情况是因为对比度低一些边界像素在塑料片的圆周上预期具有低梯度值。因此请降低 EdgeThreshold。
[centersBright,radiiBright,metricBright] imfindcircles(rgb,[25 30], ...ObjectPolarity,bright,Sensitivity,0.95,EdgeThreshold,0.1);imshow(rgb)
hBright viscircles(centersBright, radiiBright,Color,b); % 蓝色画出
h viscircles(centers,radii); % 红色画出1