图像处理 图像分割(部分)"/>
数字图像处理 图像分割(部分)
-
- 图像分割
- 点,线和边缘检测
- 点检测
- 线检测
- 使用edge函数的边缘检测
- 点,线和边缘检测
- 使用Hough变换的线检测
- 阈值处理
- 全局阈值处理
- 图像分割
图像分割
点,线和边缘检测
点检测
>> w = [-1 -1 -1; -1 8 -1; -1 -1 -1];
>> f = imread('Fig1002(a)(test_pattern_with_single_pixel).tif');
>> g = abs(imfilter(double(f),w));
>> T = max(g(:));
>> g = g >= T;
>> imshow(f);figure,imshow(g);
(我看不清成果…)
线检测
>> w = [2 -1 -1; -1 2 -1;-1 -1 2];
>> f = imread('Fig1004(a)(wirebond_mask).tif');
>> imshow(f);
>> g = imfilter(double(f),w);
>> figure,imshow(g,[]);
>> gtop = g(1:120, 1:120);
>> gtop = pixeldup(gtop, 4);
>> figure,imshow(gtop,[]);
>> gbot = g(end-119:end, end-119:end);
>> gbot = pixeldup(gbot, 4);
>> figure,imshow(gbot,[]);
>> g = abs(g);
>> figure,imshow(g,[]);
>> T = max(g(:));
>> g = g >= T;
>> figure,imshow(g);
- 原图
- 使用-45°检测器处理后的结果
- 2图左上角的放大图
- 2图右下角的放大图
- 2图的绝对值
- 值满足 g >= T的所有点(白色)
使用edge函数的边缘检测
使用Sobel检测器提取边缘
>> f = imread('Fig1006(a)(building).tif');
>> [gv, t] = edge(f,'sobel','vertical');
>> imshow(gv);
>> imshow(f);
>> figure,imshow(gv);
>> tt =0.0516>> gv = edge(f,'sobel',0.15,'vertical');
>> figure,imshow(gv);
>> gboth = edge(f,'sobel',0.15);
>> figure,imshow(gv);
- 原图
- 使用带有自动确定的阈值的一个垂直Sobel掩模后,函数edge导致的结果
- 使用指定阈值后的结果
- 使用指定阈值来决定绘制边缘和水平边缘的结果
使用Hough变换的线检测
从稀疏矩阵S获得完整矩阵用函数full:
A = full(s);
Hough 变换的说明
用一幅简单的二值图像来说明hough函数的用法
>> f = zeros(101,101);
>> f(1,1) = 1;f(101,1)=1;f(1,101) = 1;
>> f(101,101)=1;f(51,51)=1;
>> imshow(f);
>> H = hough(f);
>> imshow(H,[]);
>> imshow(f);
>> figure,imshow(H,[]);
>> [H, theta, rho] = hough(f);
>> imshow(H, [], 'XData', theta, 'YData', rho, 'InitialMagnification', 'fit');
>> axis on, axis normal
>> xlabel('\theta'), ylabel('\rho')
(用了书上的方法会报错,
>> imshow(theta ,rho, H, [], 'notruesize');
错误使用 images.internal.imageDisplayParsePVPairs (line 71)
imageDisplayParsePVPairs 无法识别参数 notruesize出错 images.internal.imageDisplayParseInputs (line 69)
[common_args,specific_args] = images.internal.imageDisplayParsePVPairs(varargin{:});出错 imshow (line 241)images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
很难受)
- 原图
- hough变换后
- 带有标度轴的hough变换
阈值处理
全局阈值处理
>> f = imread('Fig1013(a)(scanned-text-grayscale).tif');
>> T = 0.5*(double(min(f(:))) + double(max(f(:))));
>> done = false;
>> while ~done
g = f >= T;
Tnext = 0.5*(mean(f(g)) + mean(f(~g)))
done = abs(T - Tnext) < 0.5;
T = Tnext;
endTnext =98.5539Tnext =100.4909Tnext =101.1440Tnext =101.4717>> imshow(f);figure,imshow(g);
用T处理经行阈值处理的结果
更多推荐
数字图像处理 图像分割(部分)
发布评论