clc;
clear all;
%%读取图像
F=imread('DSC00260_sub2.bmp'); %29_0.bmp delighting.bmp
FI=imfinfo('DSC00260_sub2.bmp');
height=FI.Height;
width=FI.Width;
Fd=double(F); %将uint8型数据变换为double型
% Fdd=im2double(Fd);
% imshow(Fdd,[]);
figure;
ll=fftshift(fft2(Fd(:,:,1)));
imshow(abs(ll),[0 255]);
mm=abs(ll);
%%对图像进行对数化处理
Fl=zeros(height,width,3);
Fl=log(Fd);
Fluint=uint8(Fl);
%imshow(Fl,[0 255]);
% tic;
%%对对数化的图像进行傅里叶变换
Fp=zeros(2*height,2*width,3); %zero-padding
for i=1:3
for h=1:height
for w=1:width
Fp(h,w,i)=Fl(h,w,i);
end
end
end
% Fz=zeros(2*height,2*width,3); %初始化中心化图像
% for i=1:3
% for h=1:2*height
% for w=1:2*width
% Fz(h,w,i)=(-1)^(h+w)*Fp(h,w,i);
% end
% end
% end
% % %imshow(Fz);
% % %imshow(Fp);
% % Ff=zeros(2*height,2*width,3); %初始化傅里叶变换实部、虚部、幅度
% % Ffr=zeros(2*height,2*width,3);
% % Ffi=zeros(2*height,2*width,3);
% % a=0;
% %for i=1:3
% % for h=1:2*height
% % for w=1:2*width
% % for hh=1:2*height
% % for ww=1:2*width
% % a=a+1;
% % Ffr(h,w,i)=Ffr(h,w,i)*cos(2*pi*(h*hh/(2*height)+w*ww/(2*width)))+Ffr(h,w,i);
% % Ffi(h,w,i)=(Ffi(h,w,i)*sin(2*pi*(h*hh/(2*height)+w*ww/(2*width)))+Ffi(h,w,i))*(-1);
% % end
% % end
% % Ff(h,w,i)=sqrt(Ffr(h,w,i)^2+Ffi(h,w,i)^2);
% % end
% % end
% %end
% % imshow(Ff);
% % t1=toc
Ff1=fftshift(fft2(Fd(:,:,1),2*height,2*width)); %2DFFT
Ff2=fftshift(fft2(Fd(:,:,2),2*height,2*width));
Ff3=fftshift(fft2(Fd(:,:,3),2*height,2*width));
%
% figure;
% imshow(Ff1);
% figure;
% imshow(Ff2);
% figure;
% imshow(Ff3);
Ff1u=uint8(abs(Ff1));
Ff2u=uint8(abs(Ff2));
Ff3u=uint8(abs(Ff3));
FF=cat(3,Ff1u,Ff2u,Ff3u);
figure;
imshow(FF,[0 255]);
%imshow(abs(Ff),[]);
% %Flog=log(1+abs(Ff));
% %mesh(Flog);
% % figure;
% % imshow(Flog,[]);
%
%
%%高通滤波
H=zeros(2*height,2*width);
rh=2;
% rh1=2;
% rh2=5;
% rh3=10;
rl=0.5;
c=10;
D0=10000;
for u=1:2*height
for v=1:2*width
D=(u-height)^2+(v-width)^2;
H(u,v)=(rh-rl)*(1-exp(-c*(D/D0)))+rl;
% H1(u,v)=(rh1-rl)*(1-exp(-c*(D/D0)))+rl;
% H2(u,v)=(rh2-rl)*(1-exp(-c*(D/D0)))+rl;
% H3(u,v)=(rh3-rl)*(1-exp(-c*(D/D0)))+rl;
end
end
%figure;
%mesh(H);
%title('rh=2,rl=0.5,c=10,D0=1000');
% figure;
% subplot(1,3,1)
% mesh(H1);
% title('rh=2');
% subplot(1,3,2)
% mesh(H2);
% title('rh=2');
% subplot(1,3,3)
% mesh(H3);
% title('rh=2');
%
%Gfc=zeros(2*height,2*width);
Gfc1=zeros(2*height,2*width);
Gfc2=zeros(2*height,2*width);
Gfc3=zeros(2*height,2*width);
Gfc1=H.*Ff1;
Gfc2=H.*Ff2;
Gfc3=H.*Ff3;
Gfcu1=uint8(abs(Gfc1));
Gfcu2=uint8(abs(Gfc2));
Gfcu3=uint8(abs(Gfc3));
Gfc=cat(3,Gfcu1,Gfcu2,Gfcu3);
figure;
imshow(Gfc);
title('同态滤波后的结果');
%mesh(Gfc);
%%反傅里叶变换
Gf1=ifftshift(Gfc1);
Gf2=ifftshift(Gfc2);
Gf3=ifftshift(Gfc3);
Gl1=real(ifft2(Gf1));
Gl2=real(ifft2(Gf2));
Gl3=real(ifft2(Gf3));
%
%
%%指数化
G1=exp(Gl1);
G2=exp(Gl2);
G3=exp(Gl3);
Gp=cat(3,G1,G2,G3);
G=Gp(1:height,1:width,:);
figure,imshow(G);
%mesh(G1)
%imwrite(G,'finger.bmp')
%
%
%
%
%
%
%
% %%图像显示
% figure;
% subplot(1,2,1)
% imshow(F);
% title('original image');
% subplot(1,2,2)
% imshow(Fluint);
% title('logarithmic image');
% imwrite(Fl,'logarithmicImage.bmp');
% %
% figure;
% Fll=uint8(Fl);
% subplot(1,2,1)
% imshow(Fll);
% title('logarithmic image');
% subplot(1,2,2)
% Fpp=uint8(Fp);
% imshow(Fpp);
% title('zero-padding image');
%imwrite(Fp,'zero-paddingImage.bmp');
%
% % figure;
% % subplot(1,2,1)
% % imshow(Fp);
% % title('zero-padding image');
% % subplot(1,2,2)
% % imshow(Fz);
% % title('centering image');
% % imwrite(Fz,'centeringImage.bmp');
homomophicFiltering.rar_matlab同态滤波_同态滤波 彩色_彩色同态滤波_彩色图片滤波_滤除光照
版权申诉
5星 · 超过95%的资源 97 浏览量
2022-07-15
10:11:16
上传
评论 1
收藏 1KB RAR 举报
寒泊
- 粉丝: 75
- 资源: 1万+