一、fspecial()函數基本調用格式
通過在matlab的命令行窗口輸入:help fspecial
,可以查看到以下說明:
fspecial - 創(chuàng)建預定義的二維濾波器
此 MATLAB 函數 創(chuàng)建具有指定 type 的二維濾波器 h。一些濾波器類型具有可選的附加參
數,如以下語法所示。fspecial 以相關性核形式返回 h,該形式適用于 imfilter。
h = fspecial(type)
h = fspecial('average',hsize)
h = fspecial('disk',radius)
h = fspecial('gaussian',hsize,sigma)
h = fspecial('laplacian',alpha)
h = fspecial('log',hsize,sigma)
h = fspecial('motion',len,theta)
h = fspecial('prewitt')
h = fspecial('sobel')
總結一下fspecial函數有三種語法格式:
(1)h=fspecial(type)
(2)h=fspecial(type,para)
(3)h=fspecial(type,para,sigma)
其中type用于指定濾波器種類,para用于對具體濾波器種類添加額外的參數信息,sigma用于表示濾波器的標準差,單位為像素且默認值為0.5。
二、濾波器種類type說明
1、‘average’
'average’表示均值濾波,h = fspecial(‘average’,hsize)生成均值濾波器,參數hsize代表模板尺寸默認為3*3。
2、‘disk’
'disk’表示圓形區(qū)域均值濾波,h = fspecial(‘disk’,radius)生成圓形區(qū)域均值濾波器,參數radius代表區(qū)域半徑默認為5。
3、‘gaussian’
'gaussian’表示高斯低通濾波, h = fspecial(‘gaussian’,hsize,sigma生成高斯低通濾波器,參數hsize代表模板尺寸默認為3*3,sigma用于表示濾波器的標準差,單位為像素且默認值為0.5。
4、‘laplacian’
'laplacian’表示拉普拉斯算子,h = fspecial(‘laplacian’,alpha)生成拉普拉斯濾波器,參數alpha用于控制算子形狀,取值范圍為[0 1],默認值為0.2。
5、‘log’
'log’表示拉普拉斯高斯算子,h = fspecial(‘log’,hsize,sigma)生成拉普拉斯高斯濾波器,參數hsize代表模板尺寸默認為3*3,sigma用于表示濾波器的標準差,單位為像素且默認值為0.5。
6、‘motion’
'motion’表示運動模糊算子,h = fspecial(‘motion’,len,theta)生成運動模糊濾波器,參數len和theta表示攝像物體逆時針方向以theta角度運動了len個像素,len的默認值為9,theta的默認值為0。
7、‘prewitt’
'prewitt’為prewitt算子,用于邊緣增強,無參數。
8、 ‘sobel’
'sobel’為sobel算子,用于邊緣提取,無參數。
三、fspecial()函數應用實例文章來源:http://www.zghlxwxcb.cn/news/detail-438072.html
img = imread('football.jpg');
I1=imfilter(img,fspecial('average'),'replicate','same');
I2=imfilter(img,fspecial('disk',5),'replicate','same');
I3=imfilter(img,fspecial('gaussian',5,0.5),'replicate','same');
I4=imfilter(img,fspecial('laplacian',0.2),'replicate','same');
I5=imfilter(img,fspecial('log',5,0.5),'replicate','same');
I6=imfilter(img,fspecial('motion',20,30),'replicate','same');
I7=imfilter(img,fspecial('prewitt'),'replicate','same');
I8=imfilter(img,fspecial('sobel'),'replicate','same');
figure(1);
imshow(img);
figure(2);
subplot(241),imshow(I1);
title('均值濾波');
subplot(242),imshow(I2);
title('圓形區(qū)域均值濾波');
subplot(243),imshow(I3);
title('高斯低通濾波');
subplot(244),imshow(I4);
title('拉普拉斯算子');
subplot(245),imshow(I5);
title('拉普拉斯高斯算子');
subplot(246),imshow(I6);
title('運動模糊算子');
subplot(247),imshow(I7);
title('prewitt算子');
subplot(248),imshow(I8);
title('sobel算子');
實現效果:
(1)原始圖像:
(2)通過各種濾波器處理過后的圖像文章來源地址http://www.zghlxwxcb.cn/news/detail-438072.html
到了這里,關于圖像處理之matlab中fspecial函數用法詳解的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!