资源描述:
《同态滤波处理光照不均匀图像Matlab代码.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、clearall;%装载图片,将yourimage换成你要处理的图片img=imread('无标.png');%img=img0(:,:,1);%显示这个图片J=rgb2gray(img);figure,imshow(J);title('灰度图');figure,imhist(J);figure,imshow(img);title('OriginalImage');%构造一个高斯滤波器f_high=1.0;f_low=0.4;%得到一个高斯低通滤波器gauss_low_filter=fspecial('gaussian',[77],1.414);matsize=size(gauss_low_
2、filter);%由于同态滤波是要滤出高频部分,%所以我们得把这个低通滤波器转换成一个高通滤波器.%f_high和f_low是控制这个高通滤波器形态的参数.gauss_high_filter=zeros(matsize);gauss_high_filter(ceil(matsize(1,1)/2),ceil(matsize(1,2)/2))=1.0;gauss_high_filter=f_high*gauss_high_filter-(f_high-f_low)*gauss_low_filter;%显示高通滤波期的频率响应figure,freqz2(gauss_high_filter);co
3、lormap(jet(64));%利用对数变换将入射光和反射光部分分开log_img=log(double(img));%将高斯高通滤波器与对数转换后的图象卷积high_log_part=imfilter(log_img,gauss_high_filter,'symmetric','conv');%显示卷积后的图象figure,imshow(uint8(255*((high_log_part-1.5)/(2.4-1.5))),[]);title('巴特沃斯高通滤波结果');%由于被处理的图象是经过对数变换的,我们再用幂变换将图象恢复过来high_part=exp(high_log_part)
4、;minv=min(min(high_part));maxv=max(max(high_part));rimg(:,:,1)=(high_part(:,:,1)-minv(1,1,1))/(maxv(1,1,1)-minv(1,1,1));rimg(:,:,2)=(high_part(:,:,2)-minv(1,1,2))/(maxv(1,1,2)-minv(1,1,2));rimg(:,:,3)=(high_part(:,:,3)-minv(1,1,3))/(maxv(1,1,3)-minv(1,1,3));%得到的结果图象figure,imshow(uint8(255*rimg));ti
5、tle('同态滤波结果');h=rgb2gray(uint8(255*rimg));figure,imhist(h);H=medfilt2(J);%中值滤波figure,imshow(H);title('中值滤波处理');%显示中值滤波后的图像