求助,应如何进行hough变换圆检测之前的图像预处理

 我来答
匿名用户
2015-05-08
展开全部
代码如下:
function [accum, varargout] = CircularHough_Grd(img, radrange, varargin)
%Detect circular shapes in a grayscale image. Resolve their center
%positions and radii.
%
% [accum, circen, cirrad, dbg_LMmask] = CircularHough_Grd(
% img, radrange, grdthres, fltr4LM_R, multirad, fltr4accum)
% Circular Hough transform based on the gradient field of an image.
% NOTE: Operates on grayscale images, NOT B/W bitmaps.
% NO loops in the implementation of Circular Hough transform,
% which means faster operation but at the same time larger
% memory consumption.
%
%%%%%%%% INPUT: (img, radrange, grdthres, fltr4LM_R, multirad, fltr4accum)
%
% img: A 2-D grayscale image (NO B/W bitmap)
%
% radrange: The possible minimum and maximum radii of the circles
% to be searched, in the format of
% [minimum_radius , maximum_radius] (unit: pixels)
% **NOTE**: A smaller range saves computational time and
% memory.
%
% grdthres: (Optional, default is 10, must be non-negative)
% The algorithm is based on the gradient field of the
% input image. A thresholding on the gradient magnitude
% is performed before the voting process of the Circular
% Hough transform to remove the 'uniform intensity'
% (sort-of) image background from the voting process.
% In other words, pixels with gradient magnitudes smaller
% than 'grdthres' are NOT considered in the computation.
% **NOTE**: The default parameter value is chosen for
% images with a maximum intensity close to 255. For cases
% with dramatically different maximum intensities, e.g.
% 10-bit bitmaps in stead of the assumed 8-bit, the default
% value can NOT be used. A value of 4% to 10% of the maximum
% intensity may work for general cases.
%
% fltr4LM_R: (Optional, default is 8, minimum is 3)
% The radius of the filter used in the search of local
% maxima in the accumulation array. To detect circles whose
% shapes are less perfect, the radius of the filter needs
% to be set larger.
%
% multirad: (Optional, default is 0.5)
% In case of concentric circles, multiple radii may be
% detected corresponding to a single center position. This
% argument sets the tolerance of picking up the likely
% radii values. It ranges from 0.1 to 1, where 0.1
% corresponds to the largest tolerance, meaning more radii
% values will be detected, and 1 corresponds to the smallest
% tolerance, in which case only the "principal" radius will
% be picked up.
%
% fltr4accum: (Optional. A default filter will be used if not given)
% Filter used to smooth the accumulation array. Depending
% on the image and the parameter settings, the accumulation
% array built has different noise level and noise pattern
% (e.g. noise frequencies). The filter should be set to an
% appropriately size such that it's able to suppress the
% dominant noise frequency.
%
%%%%%%%% OUTPUT: [accum, circen, cirrad, dbg_LMmask]
%
% accum: The result accumulation array from the Circular Hough
% transform. The accumulation array has the same dimension
% as the input image.
%
% circen: (Optional)
% Center positions of the circles detected. Is a N-by-2
% matrix with each row contains the (x, y) positions
% of a circle. For concentric circles (with the same center
% position), say k of them, the same center position will
% appear k times in the matrix.
%
% cirrad: (Optional)
% Estimated radii of the circles detected. Is a N-by-1
% column vector with a one-to-one correspondance to the
% output 'circen'. A value 0 for the radius indicates a
% failed detection of the circle's radius.
%
% dbg_LMmask: (Optional, for debugging purpose)
% Mask from the search of local maxima in the accumulation
% array.
%
%%%%%%%%% EXAMPLE #0:
% rawimg = imread('TestImg_CHT_a2.bmp');
% tic;
% [accum, circen, cirrad] = CircularHough_Grd(rawimg, [15 60]);
% toc;
% figure(1); imagesc(accum); axis image;
% title('Accumulation Array from Circular Hough Transform');
% figure(2); imagesc(rawimg); colormap('gray'); axis image;
% hold on;
% plot(circen(:,1), circen(:,2), 'r+');
% for k = 1 : size(circen, 1),
% DrawCircle(circen(k,1), circen(k,2), cirrad(k), 32, 'b-');
% end
% hold off;
% title(['Raw Image with Circles Detected ', ...
% '(center positions and radii marked)']);
% figure(3); surf(accum, 'EdgeColor', 'none'); axis ij;
% title('3-D View of the Accumulation Array');
%
% COMMENTS ON EXAMPLE #0:
% Kind of an easy case to handle. To detect circles in the image whose
% radii range from 15 to 60. Default values for arguments 'grdthres',
% 'fltr4LM_R', 'multirad' and 'fltr4accum' are used.
%
%%%%%%%%% EXAMPLE #1:
% rawimg = imread('TestImg_CHT_a3.bmp');
% tic;
% [accum, circen, cirrad] = CircularHough_Grd(rawimg, [15 60], 10, 20);
% toc;
% figure(1); imagesc(accum); axis image;
% title('Accumulation Array from Circular Hough Transform');
% figure(2); imagesc(rawimg); colormap('gray'); axis image;
% hold on;
% plot(circen(:,1), circen(:,2), 'r+');
% for k = 1 : size(circen, 1),
% DrawCircle(circen(k,1), circen(k,2), cirrad(k), 32, 'b-');
% end
% hold off;
% title(['Raw Image with Circles Detected ', ...
% '(center positions and radii marked)']);
% figure(3); surf(accum, 'EdgeColor', 'none'); axis ij;
% title('3-D View of the Accumulation Array');
%
% COMMENTS ON EXAMPLE #1:
% The shapes in the raw image are not very good circles. As a result,
% the profile of the peaks in the accumulation array are kind of
% 'stumpy', which can be seen clearly from the 3-D view of the
% accumulation array. (As a comparison, please see the sharp peaks in
% the accumulation array in example #0) To extract the peak positions
% nicely, a value of 20 (default is 8) is used for argument 'fltr4LM_R',
% which is the radius of the filter used in the search of peaks.
%
%%%%%%%%% EXAMPLE #2:
% rawimg = imread('TestImg_CHT_b3.bmp');
% fltr4img = [1 1 1 1 1; 1 2 2 2 1; 1 2 4 2 1; 1 2 2 2 1; 1 1 1 1 1];
% fltr4img = fltr4img / sum(fltr4img(:));
% imgfltrd = filter2( fltr4img , rawimg );
% tic;
% [accum, circen, cirrad] = CircularHough_Grd(imgfltrd, [15 80], 8, 10);
% toc;
% figure(1); imagesc(accum); axis image;
% title('Accumulation Array from Circular Hough Transform');
% figure(2); imagesc(rawimg); colormap('gray'); axis image;
% hold on;
% plot(circen(:,1), circen(:,2), 'r+');
% for k = 1 : size(circen, 1),
% DrawCircle(circen(k,1), circen(k,2), cirrad(k), 32, 'b-');
% hold off;
% title(['Raw Image with Circles Detected ', ...
% '(center positions and radii marked)']);

后续完整请参阅ilovematlab.cn/thread-74414-1-1.htmlO(∩_∩)O谢谢
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式