|
| 1 | +# Matlab常用图像处理命令108例(三) |
| 2 | + |
| 3 | +## 26.edge |
| 4 | + |
| 5 | +功能:识别强度图像中的边界。 |
| 6 | + |
| 7 | +语法: |
| 8 | + |
| 9 | +```matlab |
| 10 | +BW = edge(I,'sobel') |
| 11 | +BW = edge(I,'sobel',thresh) |
| 12 | +BW = edge(I,'sobel',thresh,direction) |
| 13 | +[BW,thresh] = edge(I,'sobel',...) |
| 14 | +BW = edge(I,'prewitt') |
| 15 | +BW = edge(I,'prewitt',thresh) |
| 16 | +BW = edge(I,'prewitt',thresh,direction) |
| 17 | +[BW,thresh] = edge(I,'prewitt',...) |
| 18 | +BW = edge(I,'roberts') |
| 19 | +BW = edge(I,'roberts',thresh) |
| 20 | +[BW,thresh] = edge(I,'roberts',...) |
| 21 | +BW = edge(I,'log') |
| 22 | +BW = edge(I,'log',thresh) |
| 23 | +BW = edge(I,'log',thresh,sigma) |
| 24 | +[BW,threshold] = edge(I,'log',...) |
| 25 | +BW = edge(I,'zerocross',thresh,h) |
| 26 | +[BW,thresh] = edge(I,'zerocross',...) |
| 27 | +BW = edge(I,'canny') |
| 28 | +BW = edge(I,'canny',thresh) |
| 29 | +BW = edge(I,'canny',thresh,sigma) |
| 30 | +[BW,threshold] = edge(I,'canny',...) |
| 31 | +``` |
| 32 | + |
| 33 | +举例 |
| 34 | + |
| 35 | +```matlab |
| 36 | +I = imread('rice.tif'); |
| 37 | +BW1 = edge(I,'prewitt'); |
| 38 | +BW2 = edge(I,'canny'); |
| 39 | +imshow(BW1); |
| 40 | +figure, imshow(BW2) |
| 41 | +``` |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +## 27.erode |
| 46 | + |
| 47 | +功能:弱化二进制图像的边界。 |
| 48 | + |
| 49 | +语法: |
| 50 | + |
| 51 | +```matlab |
| 52 | +BW2 = erode(BW1,SE) |
| 53 | +BW2 = erode(BW1,SE,alg) |
| 54 | +BW2 = erode(BW1,SE,...,n) |
| 55 | +``` |
| 56 | + |
| 57 | +举例 |
| 58 | + |
| 59 | +```matlab |
| 60 | +BW1 = imread('text.tif'); |
| 61 | +SE = ones(3,1); |
| 62 | +BW2 = erode(BW1,SE); |
| 63 | +imshow(BW1) |
| 64 | +figure, imshow(BW2) |
| 65 | +``` |
| 66 | + |
| 67 | +相关命令: bwmorph, dilate |
| 68 | + |
| 69 | +## 28.fft2 |
| 70 | + |
| 71 | +功能:进行二维快速傅里叶变换。 |
| 72 | + |
| 73 | +语法: |
| 74 | + |
| 75 | +```matlab |
| 76 | +B = fft2(A) |
| 77 | +B = fft2(A,m,n) |
| 78 | +``` |
| 79 | + |
| 80 | +举例 |
| 81 | + |
| 82 | +```matlab |
| 83 | +load imdemos saturn2 |
| 84 | +imshow(saturn2) |
| 85 | +``` |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | +```matlab |
| 90 | +B = fftshift(fft2(saturn2)); |
| 91 | +imshow(log(abs(B)),[]), colormap(jet(64)), colorbar |
| 92 | +``` |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | +相关命令: |
| 97 | +dct2, fftshift, idct2, ifft2 |
| 98 | + |
| 99 | +## 29.fftn |
| 100 | + |
| 101 | +功能:进行n 维快速傅里叶变换。 |
| 102 | +语法: |
| 103 | + |
| 104 | +```matlab |
| 105 | +B = fftn(A) |
| 106 | +B = fftn(A,siz) 相关命令: fft2, ifftn |
| 107 | +``` |
| 108 | + |
| 109 | +## 30.fftshift |
| 110 | + |
| 111 | +功能:把快速傅里叶变换的DC 组件移到光谱中心。 |
| 112 | +语法: |
| 113 | + |
| 114 | +```matlab |
| 115 | +B = fftshift(A) |
| 116 | +``` |
| 117 | + |
| 118 | +举例 |
| 119 | + |
| 120 | +```matlab |
| 121 | +B = fftn(A); |
| 122 | +C = fftshift(B); |
| 123 | +``` |
| 124 | + |
| 125 | +相关命令: |
| 126 | +fft2, fftn, ifftshift |
| 127 | + |
| 128 | +## 31.filter2 |
| 129 | + |
| 130 | +功能:进行二维线性过滤操作。 |
| 131 | +语法: |
| 132 | + |
| 133 | +```matlab |
| 134 | +B = filter2(h,A) |
| 135 | +B = filter2(h,A,shape) |
| 136 | +``` |
| 137 | + |
| 138 | +举例 |
| 139 | + |
| 140 | +```matlab |
| 141 | +A = magic(6) |
| 142 | +A = |
| 143 | +35 1 6 26 19 24 |
| 144 | +3 32 7 21 23 25 |
| 145 | +31 9 2 22 27 20 |
| 146 | +8 28 33 17 10 15 |
| 147 | +30 5 34 12 14 16 |
| 148 | +4 36 29 13 18 11 |
| 149 | +h = fspecial('sobel') |
| 150 | +h = |
| 151 | +1 2 1 |
| 152 | +0 0 0 |
| 153 | +–1 –2 –1 |
| 154 | +B = filter2(h,A,'valid') |
| 155 | +B = |
| 156 | +–8 4 4 –8 |
| 157 | +–23 –44 –5 40 |
| 158 | +–23 –50 1 40 |
| 159 | +–8 4 4 –8 |
| 160 | +``` |
| 161 | + |
| 162 | +相关命令: |
| 163 | +conv2, roifilt2 |
| 164 | + |
| 165 | +## 32.freqspace |
| 166 | + |
| 167 | +功能:确定二维频率响应的频率空间。 |
| 168 | +语法: |
| 169 | + |
| 170 | +```matlab |
| 171 | +[f1,f2] = freqspace(n) |
| 172 | +[f1,f2] = freqspace([m n]) |
| 173 | +[x1,y1] = freqspace(...,'meshgrid') |
| 174 | +f = freqspace(N) |
| 175 | +f = freqspace(N,'whole') |
| 176 | +``` |
| 177 | + |
| 178 | +相关命令: |
| 179 | +fsamp2, fwind1, fwind2 |
| 180 | + |
| 181 | +## 33.freqz2 |
| 182 | + |
| 183 | +功能:计算二维频率响应。 |
| 184 | +语法: |
| 185 | + |
| 186 | +```matlab |
| 187 | +[H,f1,f2] = freqz2(h,n1,n2) |
| 188 | +[H,f1,f2] = freqz2(h,[n2 n1]) |
| 189 | +[H,f1,f2] = freqz2(h,f1,f2) |
| 190 | +[H,f1,f2] = freqz2(h) |
| 191 | +[...] = freqz2(h,...,[dx dy]) |
| 192 | +[...] = freqz2(h,...,dx) |
| 193 | +freqz2(...) |
| 194 | +``` |
| 195 | + |
| 196 | +举例 |
| 197 | + |
| 198 | +```matlab |
| 199 | +Hd = zeros(16,16); |
| 200 | +Hd(5:12,5:12) = 1; |
| 201 | +Hd(7:10,7:10) = 0; |
| 202 | +h = fwind1(Hd,bartlett(16)); |
| 203 | +colormap(jet(64)) |
| 204 | +freqz2(h,[32 32]); |
| 205 | +axis ([–1 1 –1 1 0 1]) |
| 206 | +``` |
| 207 | + |
| 208 | + |
| 209 | + |
| 210 | +## 34.fsamp2 |
| 211 | + |
| 212 | +功能:用频率采样法设计二维FIR 过滤器。 |
| 213 | +语法: |
| 214 | + |
| 215 | +```matlab |
| 216 | +h = fsamp2(Hd) |
| 217 | +h = fsamp2(f1,f2,Hd,[m n]) |
| 218 | +``` |
| 219 | + |
| 220 | +举例 |
| 221 | + |
| 222 | +```matlab |
| 223 | +[f1,f2] = freqspace(21,'meshgrid'); |
| 224 | +Hd = ones(21); |
| 225 | +r = sqrt(f1.^2 + f2.^2); |
| 226 | +Hd((r<0.1)|(r>0.5)) = 0; |
| 227 | +colormap(jet(64)) |
| 228 | +mesh(f1,f2,Hd) |
| 229 | +``` |
| 230 | + |
| 231 | +相关命令: |
| 232 | +conv2, filter2, freqspace, ftrans2, fwind1, fwind2 |
| 233 | + |
| 234 | +## 35.fspecial |
| 235 | + |
| 236 | +功能:创建预定义过滤器。 |
| 237 | +语法: |
| 238 | + |
| 239 | +```matlab |
| 240 | +h = fspecial(type) |
| 241 | +h = fspecial(type,parameters) |
| 242 | +``` |
| 243 | + |
| 244 | +举例 |
| 245 | + |
| 246 | +```matlab |
| 247 | +I = imread('saturn.tif'); |
| 248 | +h = fspecial('unsharp',0.5); |
| 249 | +I2 = filter2(h,I)/255; |
| 250 | +imshow(I) |
| 251 | +figure, imshow(I2) |
| 252 | +``` |
| 253 | + |
| 254 | + |
| 255 | + |
| 256 | +相关命令: |
| 257 | +conv2, edge, filter2, fsamp2, fwind1, fwind2 |
| 258 | + |
| 259 | +## 36.ftrans2 |
| 260 | + |
| 261 | +功能:通过频率转换设计二维FIR 过滤器。 |
| 262 | + |
| 263 | +语法: |
| 264 | + |
| 265 | +```matlab |
| 266 | +h = ftrans2(b,t) h = ftrans2(b) |
| 267 | +``` |
| 268 | + |
| 269 | +举例 |
| 270 | + |
| 271 | +```matlab |
| 272 | +colormap(jet(64)) |
| 273 | +b = remez(10,[0 0.05 0.15 0.55 0.65 1],[0 0 1 1 0 0]); |
| 274 | +[H,w] = freqz(b,1,128,'whole'); |
| 275 | +plot(w/pi–1,fftshift(abs(H))) |
| 276 | +``` |
| 277 | + |
| 278 | +相关命令: |
| 279 | + |
| 280 | +conv2, filter2, fsamp2, fwind1, fwind2 |
| 281 | + |
| 282 | +参考文献: |
| 283 | + |
| 284 | +[1] [Rafael C. Gonzalez, Richard E. Woods, and Steven L. Eddins. 2003. Digital Image Processing Using MATLAB. Prentice-Hall, Inc., USA.](https://github.com/timerring/digital-image-processing-matlab/blob/main/reference/Digital_Image_Processing_Using_Matlab.pdf) |
| 285 | + |
| 286 | +[2] [阮秋琦. 数字图像处理(MATLAB版)[M]. 北京:电子工业出版社, 2014.](https://github.com/timerring/digital-image-processing-matlab/blob/main/reference/Digital_Image_Processing_(MATLAB_version).pdf) |
| 287 | + |
| 288 | +[3] [冈萨雷斯. 数字图像处理(第三版)[M]. 北京:电子工业出版社, 2011.](https://github.com/timerring/digital-image-processing-matlab/blob/main/reference/Digital_Image_Processing_(Third_Edition).pdf) |
| 289 | + |
| 290 | + |
| 291 | + |
| 292 | +[返回首页](https://github.com/timerring/digital-image-processing-matlab) |
0 commit comments