对图像采集的图像进行预处理,滤波,去噪。

  • 虫虫123456
    了解作者
  • matlab
    开发工具
  • 4.9KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 5 积分
    下载积分
  • 0
    下载次数
  • 2022-06-27 21:13
    上传日期
对图像采集的图像进行预处理,滤波,去噪。
032061677yuchuli (1).zip
  • 图像预处理.txt
    14KB
  • www.imdn.cn.html
    66B
  • www.imdn.cn.txt
    366B
内容介绍
% Validation of arguments if ndims(img) ~= 2 || ~isnumeric(img), error('CircularHough_Grd: ''img'' has to be 2 dimensional'); end if ~all(size(img) >= 32), error('CircularHough_Grd: ''img'' has to be larger than 32-by-32'); end if numel(radrange) ~= 2 || ~isnumeric(radrange), error(['CircularHough_Grd: ''radrange'' has to be ', ... 'a two-element vector']); end prm_r_range = sort(max( [0,0;radrange(1),radrange(2)] )); % Parameters (default values) prm_grdthres = 10; prm_fltrLM_R = 8; prm_multirad = 0.5; func_compu_cen = true; func_compu_radii = true; % Validation of arguments vap_grdthres = 1; if nargin > (1 + vap_grdthres), if isnumeric(varargin{vap_grdthres}) && ... varargin{vap_grdthres}(1) >= 0, prm_grdthres = varargin{vap_grdthres}(1); else error(['CircularHough_Grd: ''grdthres'' has to be ', ... 'a non-negative number']); end end vap_fltr4LM = 2; % filter for the search of local maxima if nargin > (1 + vap_fltr4LM), if isnumeric(varargin{vap_fltr4LM}) && varargin{vap_fltr4LM}(1) >= 3, prm_fltrLM_R = varargin{vap_fltr4LM}(1); else error(['CircularHough_Grd: ''fltr4LM_R'' has to be ', ... 'larger than or equal to 3']); end end vap_multirad = 3; if nargin > (1 + vap_multirad), if isnumeric(varargin{vap_multirad}) && ... varargin{vap_multirad}(1) >= 0.1 && ... varargin{vap_multirad}(1) <= 1, prm_multirad = varargin{vap_multirad}(1); else error(['CircularHough_Grd: ''multirad'' has to be ', ... 'within the range [0.1, 1]']); end end vap_fltr4accum = 4; % filter for smoothing the accumulation array if nargin > (1 + vap_fltr4accum), if isnumeric(varargin{vap_fltr4accum}) && ... ndims(varargin{vap_fltr4accum}) == 2 && ... all(size(varargin{vap_fltr4accum}) >= 3), fltr4accum = varargin{vap_fltr4accum}; else error(['CircularHough_Grd: ''fltr4accum'' has to be ', ... 'a 2-D matrix with a minimum size of 3-by-3']); end else % Default filter (5-by-5) fltr4accum = ones(5,5); fltr4accum(2:4,2:4) = 2; fltr4accum(3,3) = 6; end func_compu_cen = ( nargout > 1 ); func_compu_radii = ( nargout > 2 ); % Reserved parameters dbg_on = false; % debug information dbg_bfigno = 4; if nargout > 3, dbg_on = true; end %%%%%%%% Building accumulation array %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Convert the image to single if it is not of % class float (single or double) img_is_double = isa(img, 'double'); if ~(img_is_double || isa(img, 'single')), imgf = single(img); end % Compute the gradient and the magnitude of gradient if img_is_double, [grdx, grdy] = gradient(img); else [grdx, grdy] = gradient(imgf); end grdmag = sqrt(grdx.^2 + grdy.^2); % Get the linear indices, as well as the subscripts, of the pixels % whose gradient magnitudes are larger than the given threshold grdmasklin = find(grdmag > prm_grdthres); [grdmask_IdxI, grdmask_IdxJ] = ind2sub(size(grdmag), grdmasklin); % Compute the linear indices (as well as the subscripts) of % all the votings to the accumulation array. % The Matlab function 'accumarray' accepts only double variable, % so all indices are forced into double at this point. % A row in matrix 'lin2accum_aJ' contains the J indices (into the % accumulation array) of all the votings that are introduced by a % same pixel in the image. Similarly with matrix 'lin2accum_aI'. rr_4linaccum = double( prm_r_range ); linaccum_dr = [ (-rr_4linaccum(2) + 0.5) : -rr_4linaccum(1) , ... (rr_4linaccum(1) + 0.5) : rr_4linaccum(2) ]; lin2accum_aJ = floor( ... double(grdx(grdmasklin)./grdmag(grdmasklin)) * linaccum_dr + ... repmat( double(grdmask_IdxJ)+0.5 , [1,length(linaccum_dr)] ) ... ); lin2accum_aI = floor( ... double(grdy(grdmasklin)./grdmag(grdmasklin)) * linaccum_dr + ... repmat( double(grdmask_IdxI)+0.5 , [1,length(linaccum_dr)] ) ... ); % Clip the votings that are out of the accumulation array mask_valid_aJaI = ... lin2accum_aJ > 0 & lin2accum_aJ < (size(grdmag,2) + 1) & ... lin2accum_aI > 0 & lin2accum_aI < (size(grdmag,1) + 1); mask_valid_aJaI_reverse = ~ mask_valid_aJaI; lin2accum_aJ = lin2accum_aJ .* mask_valid_aJaI + mask_valid_aJaI_reverse; lin2accum_aI = lin2accum_aI .* mask_valid_aJaI + mask_valid_aJaI_reverse; clear mask_valid_aJaI_reverse; % Linear indices (of the votings) into the accumulation array lin2accum = sub2ind( size(grdmag), lin2accum_aI, lin2accum_aJ ); lin2accum_size = size( lin2accum ); lin2accum = reshape( lin2accum, [numel(lin2accum),1] ); clear lin2accum_aI lin2accum_aJ; % Weights of the votings, currently using the gradient maginitudes % but in fact any scheme can be used (application dependent) weight4accum = ... repmat( double(grdmag(grdmasklin)) , [lin2accum_size(2),1] ) .* ... mask_valid_aJaI(:); clear mask_valid_aJaI; % Build the accumulation array using Matlab function 'accumarray' accum = accumarray( lin2accum , weight4accum ); accum = [ accum ; zeros( numel(grdmag) - numel(accum) , 1 ) ]; accum = reshape( accum, size(grdmag) ); %%%%%%%% Locating local maxima in the accumulation array %%%%%%%%%%%% % Stop if no need to locate the center positions of circles if ~func_compu_cen, return; end clear lin2accum weight4accum; % Parameters to locate the local maxima in the accumulation array % -- Segmentation of 'accum' before locating LM prm_useaoi = true; prm_aoithres_s = 2; prm_aoiminsize = floor(min([ min(size(accum)) * 0.25, ... prm_r_range(2) * 1.5 ])); % -- Filter for searching for local maxima prm_fltrLM_s = 1.35; prm_fltrLM_r = ceil( prm_fltrLM_R * 0.6 ); prm_fltrLM_npix = max([ 6, ceil((prm_fltrLM_R/2)^1.8) ]); % -- Lower bound of the intensity of local maxima prm_LM_LoBndRa = 0.2; % minimum ratio of LM to the max of 'accum' % Smooth the accumulation array fltr4accum = fltr4accum / sum(fltr4accum(:)); accum = filter2( fltr4accum, accum ); % Select a number of Areas-Of-Interest from the accumulation array if prm_useaoi, % Threshold value for 'accum' prm_llm_thres1 = prm_grdthres * prm_aoithres_s; % Thresholding over the accumulation array accummask = ( accum > prm_llm_thres1 ); % Segmentation over the mask [accumlabel, accum_nRgn] = bwlabel( accummask, 8 ); % Select AOIs from segmented regions accumAOI = ones(0,4); for k = 1 : accum_nRgn, accumrgn_lin = find( accumlabel == k ); [accumrgn_IdxI, accumrgn_IdxJ] = ... ind2sub( size(accumlabel), accumrgn_lin ); rgn_top = min( accumrgn_IdxI ); rgn_bottom = max( accumrgn_IdxI ); rgn_left = min( accumrgn_IdxJ ); rgn_right = max( accumrgn_IdxJ ); % The AOIs selected must satisfy a minimum size if ( (rgn_right - rgn_left + 1) >= prm_aoiminsize && ... (rgn_bottom - rgn_top + 1) >= prm_aoiminsize ), accumAOI = [ accumAOI; ... rgn_top, rgn_bottom, rgn_left, rgn_right ]; end end else % Whole accumulation array as the one AOI accumAOI = [1, size(accum,1), 1, size(accum,2)]; end % Thresholding of 'accum' by a lower bound prm_LM_LoBnd = max(accum(:)) * prm_LM_LoBndRa; % Build the filter for searching for local maxima fltr4LM = zeros(2 * prm_fltrLM_R + 1); [mesh4fLM_x, mesh4fLM_y] = meshgrid(-prm_fltrLM_R : prm_fltrLM_R); mesh4fLM_r = sqrt( mesh4fLM_x.^2 + mesh4fLM_y.^2 ); fltr4LM_mask = ... ( mesh4fLM_r > prm_fltrLM_r & mesh4fLM_r <= prm_fltrLM_R ); fltr4LM = fltr4LM - ... fltr4LM_mask * (prm_fltrLM_s / sum(fltr4LM_mask(:))); if prm_fltrLM_R >= 4, fltr4LM_mask = ( mesh4fLM_r < (prm_fltrLM_r - 1) )
评论
    相关推荐