Hough变换圆检测matLab源码        [↓跳到下载地址]

## 源码简介

close all;
clear;

%%
C = cat(3, I, I, I);
thresh = [];
sigma = 2;
%The size of the filter is chosen automatically, based on SIGMA.
BW = edge(double(I),'canny',thresh,sigma);
imwrite(BW,'coins_bw.bmp')
[Accumulator, xdim, ydim] = houghcircle2(BW, radius);
imwrite(mat2gray(Accumulator),'Accumulator.bmp')
num = 4;
figure;imshow(BW);
hold on
theta=0 : pi/1000 : 2*pi;
for i=1 : num
[y1,col1]=max(Accumulator);
[y2,col]=max(y1);
row=col1(col);
%求出hough变换值最大值的坐标。
x = radius * cos(theta) + col - radius -1;
y = radius * sin(theta) + row - radius - 1;
plot(x, y); %半径为r的圆
for k = 1 : length(x)
C(round(y(k)), round(x(k)), :) = [255, 0, 0];
end
Accumulator(row,col)=0;
%为了避免重复计算，将计算过的点置0。
rhood=1;
chood=1;
top=max(row-rhood,1);
down=min(row+rhood,ydim);
left=max(col-chood,1);
right=min(col+chood,xdim);
Accumulator(top:down,left:right)=0;
end
imwrite(C,'HoughCircle.bmp')

function [Accumulator, xdim, ydim] = houghcircle2(Imbinary,r)

%同样需要自己知道待求取的圆半径
% Fast implementation of Circular HOUGH-Transform
%
% parameters:
%     Imbinary    ... a binary image (after applying an edge-detection algorithm)
%     r           ... the radius of circle to detect within the image
%     Accumulator ... result of the HOUGH-Transform - an image where all circles are accumulated
%                     the image is 2*r larger than the input image
%     xdim, ydim  ... dimensions of the Accumulator image
xdim = size(Imbinary, 2) + ceil(2*r);
ydim = size(Imbinary, 1) + ceil(2*r);
[circle_x, circle_y] = circle(r, r, r);
[edge_y, edge_x] = find(Imbinary);
clear Imbinary;
circlepoints = length(circle_x);
edgepoints = length(edge_x);
points = zeros((circlepoints*edgepoints),1);
pos = 1;
points = (ones(size(edge_x))*round(circle_x) + round(edge_x)*ones(size(circle_x))) * ydim + ...
(ones(size(edge_y))*round(circle_y) + round(edge_y)*ones(size(circle_y)));
clear circle_x;
clear circle_y;
clear edge_x;
clear edge_y;
points = reshape(points, 1, (size(points,1) * size(points,2)));
Accumulator = histc(points, (0:1:(max(points(:)))));
clear points;
Accumulator(1) = 0; % delete counts from zeros
if (length(Accumulator) < (xdim*ydim))
Accumulator = [Accumulator zeros(1, (xdim*ydim)-length(Accumulator))];
end;
Accumulator = reshape(Accumulator(1:(xdim*ydim)), ydim, xdim);

function [x,y] = circle(center_x, center_y, radius)
% returns a vector with all circle-corner points containing the correct number of points
theta = linspace(0,2*pi, numpoints);
rho = ones(1,numpoints) * radius;
[x,y] = pol2cart(theta, rho);
x = x+center_x;
y = y+center_y;

## 本站长期招聘程序代写高手，欢迎加入华南地区matlab团队 想创业却没有经验的人 无论你是否有过网上开店的经验，都可以随时联系在线客服，建立自己独立的网站 想开网店却不知道如何入手 淘宝创业成本低而且风险小，如果想开淘宝店的朋友可以联系在线客服。 想兼职创业，却不擅长交际与服务的人 在家创业月入5000元。网站程序+百套群发工具+网赚资料+域名+空间+本站终身代理资格，这样你网赚的条件全具备了。每天3小时管理、推广、收钱。 缺乏能快速赢利型产品的人 导入多种最新流行营销软件+网赚教程，让入驻者轻松加盟、复制有效成交技巧、快速赚钱。

## 源码评论评论内容只代表网友观点，与本站立场无关！

评论摘要(共 0 条，得分 0 分，平均 0 分) 查看完整评论

## 浏览说明

* 本站所有源码全部公开，随时随地浏览!
* MATLAB软件如用于商业用途，请购买正版!
* 如果您发现下载链接错误，请点击报告错误谢谢！
* 站内提供的所有软件包含破解及注册码均是由网上搜集，若侵犯了你的版权利益，敬请来信通知我们!