colfilt(image, [m n], ‘sliding’, fun) 非线性空间滤波, 传入图片,滤波区域,和函数句柄
t = colfilt(g, [5 5], 'sliding', fun);
t = gscale(t, 'full16');
fspecial(type, paramters) 线性空间滤波器,type值有9种情况,对应paramters也不同
type : ‘average’ ‘disk’ ‘gaussian’ ‘laplacian’ ‘log’ ‘motion’ ‘prewitt’ ‘sobel’ ‘unsharp’
paramters: [r c] r [r c], sig alpha [r c], sig len, theta null null alpha (与上面的一一对应,null为没有)
f = imread('moon.jpg');
f = rgb2gray(f);
figure, imshow(f);title('none');
g = imfilter(tofloat(f), fspecial('average')); figure, imshow(g); title('arverage 3*3');
g = imfilter(tofloat(f), fspecial('disk')); figure, imshow(g); title('disk 5');
g = imfilter(tofloat(f), fspecial('gaussian')); figure, imshow(g); title('gaussian 3*3 0.5');
g = imfilter(tofloat(f), fspecial('laplacian')); figure, imshow(tofloat(f) - g); title('laplacian 0.2');
g = imfilter(tofloat(f), fspecial('log')); figure, imshow(tofloat(f) - g); title('log 5*5 0.5');
g = imfilter(tofloat(f), fspecial('motion')); figure, imshow(g); title('motion 9 0');
g = imfilter(tofloat(f), fspecial('prewitt')); figure, imshow(tofloat(f) - g); title('prewitt');
g = imfilter(tofloat(f), fspecial('sobel')); figure, imshow(tofloat(f) - g); title('sobel');
g = imfilter(tofloat(f), fspecial('unsharp')); figure, imshow(g); title('unsharp 0.2');
% close all % 关闭所有窗口
参数的具体定义直接输入 doc fspecial 即可
(另存为moon.jpg)
medfilt2(image, [x y], padpot) 非线性滤波器 [x y]默认为3*3表示滤波区域, padpot表示滤波方式,分为三种
padpot: ‘zero’ ‘symmetric’ ‘indexed’
f = imread('头像.jpg');
f = rgb2gray(f);
g = imnoise(f, 'salt & pepper', 0.2);
imshow(g);
t = medfilt2(g); figure, imshow(t);title('none 3*3');
t = medfilt2(g, 'zero'); figure, imshow(t);title('zero 3*3');
t = medfilt2(g, 'symmetric'); figure, imshow(t);title('symmetric 3*3');
t = medfilt2(g, 'indexed'); figure, imshow(t);title('indexed 3*3');
t = medfilt2(g, [4 4]); figure, imshow(t);title('none 4*4');
t = medfilt2(g, [4 4], 'zero'); figure, imshow(t);title('zero 4*4');
t = medfilt2(g, [4 4], 'symmetric'); figure, imshow(t);title('symmetric 4*4');
t = medfilt2(g, [4 4], 'indexed'); figure, imshow(t);title('indexed 4*4');
% close all % 关闭所有窗口
去燥效果明显,但是具体参数的话,还是看出来太大的差别(滤波区域的设定还是很重要地)。