图像增强基于区域相似变换函数和蜻蜓算法的灰度图像增强

Posted MatlabQQ1575304183

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了图像增强基于区域相似变换函数和蜻蜓算法的灰度图像增强相关的知识,希望对你有一定的参考价值。

  图像增强是一种必要的和不可缺少的技术,增加数字的质量图像。的主要任务是生成一个新的图像中每个像素强度值使用转换函数在输入图像接收每个像素的强度值。拟议的传递函数研究被称为区域相似性传递函数(RSTF)认为密度分布相似相邻像素之间。蜻蜓算法(DA)直观的优化技术,这是首选工程应用中,已被用于优化提出了传递函数的参数值。
 


% Using the Regional Similarity Transformation Function and Dragonfly Algorithm. 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%THIS IS A DEMO FOR NOVEL IMAGE ENHANCEMENT USING GRAV脻TAT脻ONAL SEARCH ALGORITHM 
clc;
clear all;
close all;

%READ IMAGE
i=imread('test5.bmp');
i=imresize(i,1);  

%--------------------------------------------------------------------------
%GLOBAL MEAN
frekans=zeros(256,1);

% It records by counting how many times each pixel value is.

for k=1:size(i,1)
    for l=1:size(i,2)

        value=i(k,l);
       frekans(value+1)=frekans(value+1)+1; 

    end
end
deger=max(frekans);
for k=1:256
    if deger==frekans(k)
        D=k;
    end
end
D=double(D/255);
image = im2double(i);
global_mean = D;
%--------------------------------------------------------------------------
% LOCAL MEAN
Bmean = mean_n(image);
%--------------------------------------------------------------------------
%SIMILARITY
[S]=similarity(i);
B=double(S);
%--------------------------
C = std_n(image,Bmean);
im_size = size(image);
%-------------------------------------------------------------------------
%OPTIMIZATION PARAMETERS
N=15; % Agent number;
Max_iteration=15;
%-------------------------------------------------------------------------
%CALL FUNCTION 

[parameters Fbest BestChart MeanChart] = GSA_enhancement2(image,global_mean,B,C,im_size, N, Max_iteration);

enh = trans(i,image, B, C, global_mean, parameters(1),parameters(2),parameters(3),parameters(4) );

figure;
subplot(121)
imshow(image);
title('原图')
subplot(122)
imshow(enh);
   title('GSA增强后的灰度图')

function [S]= similarity(x)


[xlen ylen] =size(x);

S=zeros(xlen, ylen);

for i=2:1:xlen-1
    for j=2:1:ylen-1
        
            %--------------------------------------------------------
        %Getting the values in the mask
        maskGray=zeros(1,9) ;
        resim=zeros(1,9) ; 
          for b=1:9;
          [m]=ikomsu(b,i);
          [n]=jkomsu(b,j);
          [res]=resimdemi(m,n,xlen,ylen);
          resim(b)=res;
                        if(resim(b)==1)
                            gray= x(m,n); 
                            maskGray (b) =gray;
                        else
                            maskGray (b) =0;
                        end
          end
  % Distance and similarity are calculated between 9 pixels in the mask and the result is determined.
       DN=150;
       sim=0;
       sum=0;
      for b=1:9
                   sim (b)=similarity1(maskGray(b),maskGray(9),DN);
                   sum=sim(b)+sum;    
      end
         %---------------------------------------------------------
     
         
          S(i,j)=sum/9;
          
              
    end
end 


end
%------------------------------------------------------------------------
%FUNCTIONS
%-----------------------------------------------------------------------
function [ res ] = resimdemi(x,y,w,h )

 if(x<1 || x>w-1 || y<1 || y>h-1)
    res=0;
 else
    res=1;


 end
end
 function [x] = ikomsu( komsuno, i)


 if(komsuno ==1)
     x=i-1;
 elseif(komsuno ==2)
    x= i;
 elseif(komsuno ==3)
    x= i+1;
 elseif(komsuno ==4)
    x= i-1;
 elseif(komsuno ==5)
    x= i+1;
 elseif(komsuno ==6)
   x= i-1;
 elseif(komsuno ==7)
   x= i;
 elseif(komsuno ==8)
   x= i+1;
 elseif(komsuno ==9)
    x=i;
 else
 x=0;
 end


 end

 function [y] = jkomsu( komsuno, j )

 if(komsuno ==1)
    y= j-1;
 elseif(komsuno ==2)
    y= j-1;
 elseif(komsuno ==3)
   y= j-1;
 elseif(komsuno ==4)
   y= j;
 elseif(komsuno ==5)
   y= j;
 elseif(komsuno ==6)
   y= j+1;
 elseif(komsuno ==7)
   y= j+1;
 elseif(komsuno ==8)
   y= j+1;
 elseif(komsuno ==9)
    y= j;
 else
   y=0;
 end


 end

 
function [sim] = similarity1( k, o, DN)

 
 a=0;b=0;c=0;
 a=abs(k-o);
%  b=(abs(l-p))^2;
%  c=(abs(m-r))^2;
%  //Distance calculation based on the Euclidean relation
 dist=a;

% %  //Calculation of similarity based on linear function
 arahes=dist/DN;
 sim=1 - arahes;
%  sim=exp(-dist/DN);


end




完整代码添加QQ1575304183

 

以上是关于图像增强基于区域相似变换函数和蜻蜓算法的灰度图像增强的主要内容,如果未能解决你的问题,请参考以下文章

图像分割

图像分割

图像增强基于matlab同态增晰图像增强含Matlab源码 962期

数字图像处理

图像亮度调节--幂次变换

图像增强基于模糊集的图像增强matlab源码