本资源为原创Matlab代码包,用于高效地从图像中提取圆点中心坐标。circle.rar内含详细注释和示例文件,适合科研与教学使用。
感谢论坛上的资料分享让我少走了弯路。
文件名:circle.rar
测试图像描述:
背景为黑色,圆点为白色。
图像中有五个圆点。
功能简介:
提取每个圆点的中心坐标[X Y],
并在这些位置用红色“十”标记出来。
代码实现:
```matlab
function [X, Y]=circletest()
im = imread(test_image.png); % 读取原始图像
test_im_gray = rgb2gray(im); % 转换为灰度图
bw = zeros(size(test_im_gray));
for i=1:size(test_im_gray, 1)
for j=1:size(test_im_gray, 2)
if test_im_gray(i,j)>=250
bw(i,j)=1; % 图像二值化处理,阈值为250
end
end
end
L = bwlabel(bw); % 标记联通区域的标签图
s = regionprops(L, Centroid); % 提取每个连接域的中心坐标
centroids = cat(1, s.Centroid); % 将所有圆点的中心位置合并成一个矩阵
imshow(im);
hold on;
plot(centroids(:,2),centroids(:,1),r+);
hold off;
p=cell2mat(s.Centroid);
X=p(:, 2); Y=p(:, 1);
end
```
附图:results.jpg
该代码能够成功提取图像中的圆点中心坐标,并且在这些位置用红色“十”标记。