乐趣区

关于图像处理:Matlab常用图像处理命令108例三

文章和代码以及样例图片等相干资源,曾经归档至【Github 仓库:digital-image-processing-matlab】或者公众号【AIShareLab】回复 数字图像处理 也可获取。

26.edge

性能:辨认强度图像中的边界。

语法:

BW = edge(I,'sobel')
BW = edge(I,'sobel',thresh)
BW = edge(I,'sobel',thresh,direction) 
[BW,thresh] = edge(I,'sobel',...)
BW = edge(I,'prewitt')
BW = edge(I,'prewitt',thresh)
BW = edge(I,'prewitt',thresh,direction) 
[BW,thresh] = edge(I,'prewitt',...)
BW = edge(I,'roberts')
BW = edge(I,'roberts',thresh) 
[BW,thresh] = edge(I,'roberts',...) 
BW = edge(I,'log')
BW = edge(I,'log',thresh)
BW = edge(I,'log',thresh,sigma) 
[BW,threshold] = edge(I,'log',...) 
BW = edge(I,'zerocross',thresh,h) 
[BW,thresh] = edge(I,'zerocross',...) 
BW = edge(I,'canny')
BW = edge(I,'canny',thresh)
BW = edge(I,'canny',thresh,sigma) 
[BW,threshold] = edge(I,'canny',...) 

举例

I = imread('rice.tif');
BW1 = edge(I,'prewitt'); 
BW2 = edge(I,'canny'); 
imshow(BW1);
figure, imshow(BW2)

27.erode

性能:弱化二进制图像的边界。

语法:

BW2 = erode(BW1,SE)
BW2 = erode(BW1,SE,alg) 
BW2 = erode(BW1,SE,...,n)

举例

BW1 = imread('text.tif'); 
SE = ones(3,1);
BW2 = erode(BW1,SE);
imshow(BW1)
figure, imshow(BW2) 

相干命令:bwmorph, dilate

28.fft2

性能:进行二维疾速傅里叶变换。

语法:

B = fft2(A)
B = fft2(A,m,n)

举例

load imdemos saturn2 
imshow(saturn2)
B = fftshift(fft2(saturn2));
imshow(log(abs(B)),[]), colormap(jet(64)), colorbar

相干命令:
dct2, fftshift, idct2, ifft2

29.fftn

性能:进行 n 维疾速傅里叶变换。
语法:

B = fftn(A)
B = fftn(A,siz) 相干命令:fft2, ifftn

30.fftshift

性能:把疾速傅里叶变换的 DC 组件移到光谱核心。
语法:

B = fftshift(A)

举例

B = fftn(A);
C = fftshift(B);

相干命令:
fft2, fftn, ifftshift

31.filter2

性能:进行二维线性过滤操作。
语法:

B = filter2(h,A)
B = filter2(h,A,shape)

举例

A = magic(6) 
A =
35 1 6 26 19 24
3 32 7 21 23 25
31 9 2 22 27 20
8 28 33 17 10 15
30 5 34 12 14 16
4 36 29 13 18 11
h = fspecial('sobel') 
h =
1 2 1
0 0 0
–1 –2 –1
B = filter2(h,A,'valid') 
B =
–8 4 4 –8
–23 –44 –5 40
–23 –50 1 40
–8 4 4 –8

相干命令:
conv2, roifilt2

32.freqspace

性能:确定二维频率响应的频率空间。
语法:

[f1,f2] = freqspace(n) 
[f1,f2] = freqspace([m n])
[x1,y1] = freqspace(...,'meshgrid') 
f = freqspace(N)
f = freqspace(N,'whole')

相干命令:
fsamp2, fwind1, fwind2

33.freqz2

性能:计算二维频率响应。
语法:

[H,f1,f2] = freqz2(h,n1,n2)
[H,f1,f2] = freqz2(h,[n2 n1])
[H,f1,f2] = freqz2(h,f1,f2)
[H,f1,f2] = freqz2(h)
[...] = freqz2(h,...,[dx dy])
[...] = freqz2(h,...,dx) 
freqz2(...)

举例

Hd = zeros(16,16); 
Hd(5:12,5:12) = 1;
Hd(7:10,7:10) = 0;
h = fwind1(Hd,bartlett(16)); 
colormap(jet(64))
freqz2(h,[32 32]); 
axis ([–1 1 –1 1 0 1])

34.fsamp2

性能:用频率采样法设计二维 FIR 过滤器。
语法:

h = fsamp2(Hd)
h = fsamp2(f1,f2,Hd,[m n])

举例

[f1,f2] = freqspace(21,'meshgrid'); 
Hd = ones(21);
r = sqrt(f1.^2 + f2.^2); 
Hd((r<0.1)|(r>0.5)) = 0;
colormap(jet(64)) 
mesh(f1,f2,Hd)

相干命令:
conv2, filter2, freqspace, ftrans2, fwind1, fwind2

35.fspecial

性能:创立预约义过滤器。
语法:

h = fspecial(type)
h = fspecial(type,parameters)

举例

I = imread('saturn.tif');
h = fspecial('unsharp',0.5); 
I2 = filter2(h,I)/255; 
imshow(I)
figure, imshow(I2)

相干命令:
conv2, edge, filter2, fsamp2, fwind1, fwind2

36.ftrans2

性能:通过频率转换设计二维 FIR 过滤器。

语法:

h = ftrans2(b,t) h = ftrans2(b) 

举例

colormap(jet(64))
b = remez(10,[0 0.05 0.15 0.55 0.65 1],[0 0 1 1 0 0]);
[H,w] = freqz(b,1,128,'whole'); 
plot(w/pi–1,fftshift(abs(H)))

相干命令:

conv2, filter2, fsamp2, fwind1, fwind2

参考文献:

[1] Rafael C. Gonzalez, Richard E. Woods, and Steven L. Eddins. 2003. Digital Image Processing Using MATLAB. Prentice-Hall, Inc., USA.

[2] [阮秋琦. 数字图像处理(MATLAB 版)[M]. 北京:电子工业出版社, 2014.](https://github.com/timerring/digital-image-processing-matlab/blob/main/reference/Digital_Image_Processing_(MATLAB_version).pdf)

[3] [冈萨雷斯. 数字图像处理(第三版)[M]. 北京:电子工业出版社, 2011.](https://github.com/timerring/digital-image-processing-matlab/blob/main/reference/Digital_Image_Processing_(Third_Edition).pdf)

退出移动版