>> 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);
使用Sobel检测器提取边缘
>> f = imread('Fig1006(a)(building).tif');
>> [gv, t] = edge(f,'sobel','vertical');
>> imshow(gv);
>> imshow(f);
>> figure,imshow(gv);
>> t
t =
0.0516
>> gv = edge(f,'sobel',0.15,'vertical');
>> figure,imshow(gv);
>> gboth = edge(f,'sobel',0.15);
>> figure,imshow(gv);
从稀疏矩阵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{:});
很难受)
>> 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;
end
Tnext =
98.5539
Tnext =
100.4909
Tnext =
101.1440
Tnext =
101.4717
>> imshow(f);figure,imshow(g);
用T处理经行阈值处理的结果