700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 数字图像处理之空间域图像增强

数字图像处理之空间域图像增强

时间:2022-03-31 02:45:09

相关推荐

数字图像处理之空间域图像增强

滤波过程就是在图像f(x,y)中逐点移动模板(即滤波器),使模板中心和点(x,y)重合,滤波器在每一点的响应是根据模板的具体内容并通过预先定义的关系计算的。

将图像的模板在图像中逐像素移动,并对每个像素进行指定数量的计算的过程就是卷积过程。

包括图像的平滑和锐化。平滑用于去除噪声,锐化用于加强边缘。

在平滑处理中平滑的对象是噪声而不是边缘,在锐化处理中锐化的对象是边缘而不是噪声。

包括平滑滤波器(低通滤波器)和锐化滤波器(高通滤波器) p171

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

5.3图像平滑

imfilter滤波

>> help imfilterIMFILTER Multidimensional image filtering.B = IMFILTER(A,H) filters the multidimensional array A with themultidimensional filter H. A can be logical or it can be a nonsparse numeric array of any class and dimension. The result, B, has the same size and class as A.Each element of the output, B, is computed using double-precisionfloating point. If A is an integer or logical array, then output elements that exceed the range of the given type are truncated, and fractional values are rounded.B = IMFILTER(A,H,OPTION1,OPTION2,...) performs multidimensionalfiltering according to the specified options. Option arguments canhave the following values:- Boundary optionsX Input array values outside the bounds of the arrayare implicitly assumed to have the value X. When noboundary option is specified, IMFILTER uses X = 0.'symmetric' Input array values outside the bounds of the arrayare computed by mirror-reflecting the array acrossthe array border.'replicate' Input array values outside the bounds of the arrayare assumed to equal the nearest array bordervalue.'circular' Input array values outside the bounds of the arrayare computed by implicitly assuming the input arrayis periodic.- Output size options(Output size options for IMFILTER are analogous to the SHAPE optionin the functions CONV2 and FILTER2.)'same' The output array is the same size as the inputarray. This is the default behavior when no outputsize options are specified.'full' The output array is the full filtered result, and sois larger than the input array.- Correlation and convolution'corr' IMFILTER performs multidimensional filtering usingcorrelation, which is the same way that FILTER2performs filtering. When no correlation orconvolution option is specified, IMFILTER usescorrelation.'conv' IMFILTER performs multidimensional filtering usingconvolution.Example -------------rgb = imread('flowers.tif'); h = fspecial('motion',50,45); rgb2 = imfilter(rgb,h); imshow(rgb), title('Original') figure, imshow(rgb2), title('Filtered') rgb3 = imfilter(rgb,h,'replicate'); figure, imshow(rgb3), title('Filtered with boundary replication')See also CONV2, CONVN, FILTER2.

平均模板滤波器

I=imread('baby_noise.bmp'); subplot(1,4,1);;imshow(I);title('source'); h=fspecial('average',3);%3x3模板 I3=imfilter(I,h,'corr','replicate');%执行滤波,replicate重复 subplot(1,4,2);;imshow(I3);title('3'); h=fspecial('average',5);%5x5模板 I5=imfilter(I,h,'corr','replicate'); subplot(1,4,3);;imshow(I5);title('5'); h=fspecial('average',7);%7x7模板 I7=imfilter(I,h,'corr','replicate'); subplot(1,4,4);;imshow(I7);title('7');

高斯模板:由于平均模板对邻域内的像素一视同仁,为了减少平滑处理中的模糊,得到更自然的平滑效果,则会很自然的想到适当加大模板中点的权重,随着远离中心点,权重迅速减少,从而可以确保中心点看起来更接近与他距离更近的点,基于这种考虑的模板是高斯模板。

高斯模板的名字由来是二维高斯函数,即二维正态分布函数。方差是sigma。

sigma过小,偏离中心的所有像素的权重将会非常小,相当于没有滤波效果。反之相反。

I=imread('baby_noise.bmp'); subplot(1,4,1);imshow(I);title('source'); h=fspecial('gaussian',3,0.5);%3是板数0.5是sigma I3_5=imfilter(I,h); subplot(1,4,2);imshow(I3_5);title('3_5'); h=fspecial('gaussian',3,0.8); I3_8=imfilter(I,h); subplot(1,4,3);imshow(I3_8);title('3_8'); h=fspecial('gaussian',5,0.8); I5_8=imfilter(I,h); subplot(1,4,4);imshow(I5_8);title('5_8');

中值滤波

I=imread('lena.gif');%灰度图像 subplot(1,4,1);imshow(I3);title('I'); J=imnoise(I,'salt & pepper');%添加椒盐噪声。黑点同胡椒,白点同盐粒。subplot(1,4,2);imshow(J);title('J'); h=fspecial('average',3);%3x3模板 I3=imfilter(I,h,'corr','replicate');%执行滤波,replicate重复 subplot(1,4,3);imshow(I3);title('3X3平均'); J=medfilt2(J,[3,3]);%中值滤波subplot(1,4,4);imshow(I3);title('medfilt2');

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

5.5图像锐化

图像锐化主要用于增强图像中的灰度跳变部分,这一点与图像平滑对灰度跳变的抑制作用刚好相反。事实上从平滑与锐化的两种运算算子上也能看出,线性平滑都是基于对图像邻域的加权求和或积分运算,而锐化则是其逆运算导数(梯度)或有限差分来实现。

噪声和边缘都会使图像产生灰度跳变,需要将噪声和边缘区分。

在平滑处理中平滑的对象是噪声而不是边缘,在锐化处理中锐化的对象是边缘而不是噪声。

5.5.2.基于一阶导数的图像增强--梯度算子

1.robert交叉梯度--需要两次滤波,然后求和

i=imread('bacteria.BMP'); subplot(1,4,1);imshow(i); title('source') ;i=double(i); w1=[-1,0;0,1]; %对正45度方向的边缘有较强响应,从图g1可以看出w2=[0,-1;1,0]; %对负45度方向的边缘有较强响应,从图g2可以看出g1=imfilter(i,w1,'corr','replicate');%正45度滤波 g2=imfilter(i,w2,'corr','replicate');%负45度滤波g=abs(g1)+abs(g2); subplot(1,4,2);imshow(abs(g1),[]);title('g1') ;subplot(1,4,3);imshow(abs(g2),[]);title('g2');subplot(1,4,4);imshow(g,[]);title('g') ;

2.sobel梯度

5.5.3.基于2阶微分的图像增强--拉普拉斯算子。由于各向同性,所以只需一次滤波。

I=imread('bacteria.BMP'); subplot(1,4,1);imshow(I); title('source') ; I=double(I);w1=[0 -1 0;-1 4 -1;0 -1 0];L1=imfilter(I,w1,'corr','replicate');subplot(1,4,2);imshow(abs(L1),[]); title('w1模板') ; w2=[-1 -1 -1;-1 8 -1;-1 -1 -1];L2=imfilter(I,w2,'corr','replicate');subplot(1,4,3);imshow(abs(L2),[]); title('w2模板') ; w3=[1 4 1;4 -20 4;1 4 1];%加权模板L3=imfilter(I,w3,'corr','replicate');subplot(1,4,4);imshow(abs(L3),[]); title('w3模板') ;

5.5.5高频提升滤波机器实现

无论是基于一阶微分的robert还是基于二阶微分的拉普拉斯的模板,其中各系数和均为0。这说明算子在灰度恒定的区域响应为0,即在锐化处理后的图像中,源图像的平滑区近乎于黑色,而原图中所有的边缘,细节,和灰度跳变点都在黑背景中显示出来。在基于锐化的图像增强中,我们常常希望在增强边缘和细节的同时,仍然保留原图像中的信息,而不是将平滑区域的灰度信息丢失。因此可以将源图像加上锐化后的图像以得到比较理想的图像。p171

5.5.6高斯-拉普拉斯变换 LoG

I=imread('lena.gif'); subplot(1,4,1);imshow(I); title('source') ; I_double=double(I); %滤波前转化为双精度 h_lap=[-1 -1 -1;-1 8 -1;-1 -1 -1];%拉普拉斯算子I_lap=imfilter(I_double,h_lap,'corr','replicate');%拉普拉斯锐化subplot(1,4,2);imshow(uint8(abs(I_lap)),[]); title('lap');h_log=fspecial('log',5,0.5);%log模板,sigma=0.5I_log=imfilter(I_double,h_log,'corr','replicate');%log滤波subplot(1,4,3);imshow(uint8(abs(I_lap)),[]); title('log 0.5') ;h_log=fspecial('log',5,2);%log模板,sigma=2I_log=imfilter(I_double,h_log,'corr','replicate');%log滤波subplot(1,4,4);imshow(uint8(abs(I_lap)),[]); title('log 2') ;

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。