⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mhzq.m

📁 用matlab 实现的图像模糊增强 在matlab 6.5 7.0sp1都可以用
💻 M
字号:
%%%%%%%%%%%%%%%%%%%%%%%%
%%  姓名:李玉虎        %%
%%  学号:JN03006001   %%
%%  日期:2005年3月26日 %%
%%%%%%%%%%%%%%%%%%%%% %%
%%%灰度图像的模糊增强
 X=0; %清空X.
 map=0;
[X,map]=imread('lena256x256x8.bmp');  %读取图像
%%%%%%%%%%%显示原始的图像
figure('Position',[0,390,330,330],'name','原始图像'),imshow(X,map)      
title('显示原始的图像');
%%%%%%
p=imfinfo('lena256x256x8.bmp');       %读取图像的属性
s=2^p.BitDepth-1;            %计算图像的最大深度,如8位图像为255.

%-------------------------------------------------------------------------
%简化的图像增强算法:简化Pmn及T变换的算法为:
Y=0; %清空Y.
A=0;%清空A.
Y=double(X)./s;            %计算P(m,n),相当于求G(x)
%简化的模糊增强算法,依据第三章3.3.2 相当于求T1(G(x))
for m=1:p.Height
   for n=1:p.Width
       if(Y(m,n)<0.5)
           A(m,n)=2*Y(m,n)^2;
       else
           A(m,n)=1-2*(1-Y(m,n))^2;
       end
   end
end
B=0; %清空B.
B=uint8(A*(2^p.BitDepth-1));   %相当于求逆G-1(x')

figure('Position',[340,390,330,330],'name','简化模糊增强'),imshow(B,map)      %显简化模糊增强变换后的图像
title('简化模糊增强变换后的图像');
%------------------------------------------------------------------------
%%%图像的模糊增强,完全依据第三章3.3.2,
%第一次增强:T1
%%第一步:求Pmn=G(Xmn) 取Fe=1,Fd=127.5或取Fe=2,Fd=307.8122
Fd=127.6;
Fe=1;
P=0; %清空P.
Z=0; %清空Z.
for m=1:p.Height
    for n=1:p.Width
        P(m,n)=1.0/((1.0+(s-double (X(m,n)))/Fd)^Fe);
    end
end
%%对最小数'0'进行调整
a=1.0/(1.0+s/Fd)^Fe;     %%
for m=1:p.Height
    for n=1:p.Width
        if P(m,n)==0
            P(m,n)=a;
        end
    end
end
%%第二步:求Tr
for m=1:p.Height
   for n=1:p.Width
       if(P(m,n)<0.5)
           T(m,n)=2*P(m,n)^2;
       else
           T(m,n)=1-2*(1-P(m,n))^2;
       end
   end
end
%%第三步:求G(Xmn)逆变换
for m=1:p.Height
   for n=1:p.Width
       Z(m,n)=uint8(s-Fd*(1.0/T(m,n)^(1/Fe)-1));
   end
end
figure('Position',[680,390,330,330],'name','第一次模糊增强'),imshow(Z,map); %显示模糊增强变换后的图像1
title('第一次模糊增强变换后的图像1');

%--------------------------------------------------------------------------
%图像平滑算法的实现:平均法.
%半径为Radius
Radius=1;
ZP=0; %清空ZP.
for m=1:p.Height
    for n=1:p.Width
       temp=0;
       count=0;
     for f=1:Radius
       for g=1:f
        if(m-g>0);
            temp=temp+double(Z(m-g,n));
            count=count+1;
        end
        if(n-g>0);
            temp=temp+double(Z(m,n-g));
            count=count+1;
        end
        if(m-g>0 && n-g>0);
            temp=temp+double(Z(m-g,n-g));
            count=count+1;
        end

        if(m-g>0 && n+g<=p.Width);
            temp=temp+double(Z(m-g,n+g));
            count=count+1;
        end
        
        if(n-g>0 && m+g<=p.Height)
          temp=temp + double(Z(m+g,n-g));
            count=count+1;
        end
         if(m+g<=p.Height)
          temp=temp+double(Z(m+g,n));
            count=count+1;
        end
         if(n+g<=p.Width)
          temp=temp + double(Z(m,n+g));
            count=count+1;
         end
         if(m+g<=p.Height && n+g<=p.Width)
          temp=temp+ double(Z(m+g,n+g));
            count=count+1;
        end
       
     
       end
     end
    
       if count==0
          ZP(m,n)=Z(m,n); 
       else
          ZP(m,n)=uint8(temp/count);
       end
   end
end

figure('Position',[0,0,330,330],'name','增强后平滑'),imshow(ZP,map); %显示模糊增强变换后进行平滑处理后的图像
title('图像增强平滑后的图像');


%--------------------------------------------------------------------------
%%图像的模糊增强,完全依据第三章3.3.2,
%第二次增强:T2
%%第一步:求Pmn=G(Xmn) 取fe=1,fd=127.5或取fe=2,fd=307.8122
Fd2=307.8122;
Fe2=2;
P2=0; %清空P2.
T2=0; %清空T2.
Z2=0; %清空Z2.
for m=1:p.Height
    for n=1:p.Width
        P2(m,n)=1.0/((1.0+(s-double (ZP(m,n)))/Fd2)^Fe2);
    end
end
%%对最小数'0'进行调整
a2=1/(1+s/Fd2)^Fe2;     %%
for m=1:p.Height
    for n=1:p.Width
        if P2(m,n)==0
            P2(m,n)=a;
        end
    end
end
%%第二步:求Tr
for m=1:p.Height
   for n=1:p.Width
       if(P2(m,n)<0.5)
           T2(m,n)=2.0*P2(m,n)^2;
       else
           T2(m,n)=1-2.0*(1-P2(m,n))^2;
       end
   end
end
%%第三步:求G(Xmn)逆变换
for m=1:p.Height
   for n=1:p.Width
       Z2(m,n)=uint8(s-Fd2*(1.0/T2(m,n)^(1/Fe2)-1));
   end
end
figure('Position',[340,0,330,330],'name','第二次模糊增强'),imshow(Z2,map); %显示模糊增强变换后的图像2
title('第二次模糊增强变换后的图像');

%--------------------------------------------------------------------------

figure('Position',[680,0,330,330],'name','matlab图像增强'),imshow(imadjust(X,[0.3,0.7],[]),map); %matlab自带图像处理函数
title('matlab自带图像处理函数');

%%%%%%%%%%%%%%%%%%%%%%%%
%%  姓名:李玉虎        %%
%%  学号:JN03006001   %%
%%  日期:2005年3月26日 %%
%%%%%%%%%%%%%%%%%%%%% %%

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -