资源简介
包含二值化、canny算子边缘检测、感兴趣区域提取、自动多阈值分割等程序,及分水岭分割和连通域字符识别两篇文章。
代码片段和文件信息
% Canny边缘检测的函数
% Input:
% a: input image
% sigma: Gaussian的均方差
function e=canny_edge(asigma)
a = double(a); % 将图像像素数据转换为double类型
[mn] = size(a)
e = repmat(logical(uint8(0))mn); % 生成初始矩阵
GaussianDieOff = .0001;
PercentOfPixelsNotEdges = .7; % Used for selecting thresholds
ThresholdRatio = .4; % Low thresh is this fraction of the high.
% Design the filters - a gaussian and its derivative
pw = 1:30; % possible widths
ssq = sigma^2;
width = find(exp(-(pw.*pw)/(2*ssq))>GaussianDieOff1‘last‘);
if isempty(width)
width = 1; % the user entered a really small sigma
end
t = (-width:width);
gau = exp(-(t.*t)/(2*ssq))/(2*pi*ssq); % the gaussian 1D filter
% Find the directional derivative of 2D Gaussian (along X-axis)
% Since the result is symmetric along X we can get the derivative along
% Y-axis simply by transposing the result for X direction.
[xy]=meshgrid(-width:width-width:width);
dgau2D=-x.*exp(-(x.*x+y.*y)/(2*ssq))/(pi*ssq);
% Convolve the filters with the image in each direction
% The canny edge detector first requires convolution with
% 2D gaussian and then with the derivitave of a gaussian.
% Since gaussian filter is separable for smoothing we can use
% two 1D convolutions in order to achieve the effect of convolving
% with 2D Gaussian. We convolve along rows and then columns.
%smooth the image out
aSmooth=imfilter(agau‘conv‘‘replicate‘); % run the filter accross rows
aSmooth=imfilter(aSmoothgau‘‘conv‘‘replicate‘); % and then accross columns
%apply directional derivatives
ax = imfilter(aSmooth dgau2D ‘conv‘‘replicate‘);
ay = imfilter(aSmooth dgau2D‘ ‘conv‘‘replicate‘);
mag = sqrt((ax.*ax)+(ay.*ay)); % 每个像素点的梯度强度
magmax = max(mag(:));
if magmax>0
mag = mag/magmax; % 归一化
end
%[countsx] = imhist(mag64); % 直方图统计
%high = min(find(cumsum(counts)>Perc*m*n))/64;
%low = Th*high;
high=0.1;
low=0.04;
thresh = [low high]; % 根据直方图统计确定上下限
% Nonmax-suppression
idxStrong = [];
for dir = 1:4
Localmax = Findlocalmax(diraxaymag);
idxWeak = Localmax(mag(Localmax)>low);
e(idxWeak) = 1;
idxStrong = [idxStrong; idxWeak(mag(idxWeak)>high)];
end
rstrong = rem(idxStrong-1m)+1;
cstrong = floor((idxStrong-1)/m)+1;
e = bwselect(ecstrongrstrong8); %
e = bwmorph(e‘thin‘1); % 使用形态学的方法把边缘变细
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2013-05-22 10:22 DIP\canny\
文件 2517 2013-05-22 10:21 DIP\canny\canny_edge.m
文件 361879 2003-06-28 23:55 DIP\canny\Fig1006(a)(building).tif
文件 1339 2008-12-12 16:17 DIP\canny\Findlocalmax.m
文件 195 2013-05-22 10:22 DIP\canny\seg_canny_edge.m
目录 0 2013-05-22 10:59 DIP\ROI\
文件 371691 2013-05-22 10:27 DIP\ROI\ID2.jpg
文件 789 2009-07-12 20:28 DIP\ROI\iteration.m
文件 786488 2013-04-12 10:59 DIP\ROI\Lena.bmp
文件 1074 2013-05-22 10:59 DIP\ROI\mca.jpg
文件 1339 2013-05-22 10:59 DIP\ROI\mcaa.m
文件 931 2009-07-12 20:26 DIP\ROI\zbthresh.m
文件 5056124 2011-03-27 18:02 DIP\标记分水岭分割算法.pdf
目录 0 2013-05-22 17:00 DIP\二值化\
文件 643 2013-05-22 17:00 DIP\二值化\erzhihua.m
文件 1183 2013-05-22 16:59 DIP\二值化\imagebw.m
文件 572 2013-05-22 17:00 DIP\二值化\mainx.m
目录 0 2011-12-30 13:58 DIP\感兴趣区域提取\
文件 3121 2011-12-30 13:59 DIP\感兴趣区域提取\a.m
文件 11501 2011-12-30 13:55 DIP\感兴趣区域提取\go.asv
文件 9803 2012-05-30 20:10 DIP\感兴趣区域提取\go.fig
文件 11510 2013-05-22 10:49 DIP\感兴趣区域提取\go.m
目录 0 2011-12-30 13:58 DIP\感兴趣区域提取\imag\
文件 17147 2011-12-20 21:26 DIP\感兴趣区域提取\imag\213.jpg
文件 16560 2011-12-20 21:26 DIP\感兴趣区域提取\imag\220.jpg
文件 21274 2011-12-20 21:26 DIP\感兴趣区域提取\imag\242.jpg
文件 9144 2011-11-20 22:53 DIP\感兴趣区域提取\imag\b.jpg
文件 33500 2011-11-20 22:54 DIP\感兴趣区域提取\imag\c.jpg
文件 94577 2011-11-20 22:53 DIP\感兴趣区域提取\imag\d.jpg
文件 23930 2011-11-20 22:55 DIP\感兴趣区域提取\imag\e.jpg
文件 1446 2011-12-30 13:55 DIP\感兴趣区域提取\loadimage.asv
............此处省略9个文件信息
- 上一篇:歪斜的图像校正成正视图
- 下一篇:雷达对目标的跟踪
评论
共有 条评论