retinex相关代码汇总

 

混合方法 SSR.m

matlab代码,本来是RGB,改成了处理灰度图像的。

%%%%%%%%%%%%%%%RGB normalisation%%%%%%%%%%%%%%%%%%%%%%  
%its cascaded implementain of 1 section of paper "A FAST SKIN REGION DETECTOR" by  
%Phil Chen, Dr.Christos Greecos  
%and  
%section 2.1 of paper "Simple and accurate face detection in color images" by  
%YUI TING PAI et al  
% Coding by Madhava.S.Bhat, Dept of Electronics an communication  
%Dr.Ambedkar Institute of Technology, Bangalore  
%madhava.s@dr-ait.org  
function[]= SSR(IMG)
IMG=rgb2gray(IMG);
figure,imshow(IMG)  
title('original')  
R=double(IMG);  
[H,W]=size(R);  
% minR=0;  
% minG=0;  
% minB=0;  
% [srow,scol]=find(R==0 & G==0 & B==0);  
% if(isempty(srow) && isempty(scol))  
    minR=min(min(R)); 
% end  
R=R-minR;  
  
S=zeros(H,W);  
[srow,scol]=find(R==0);  
[sm,sn]=size(srow);  
  
for i=1:sm  
     S(srow(i),scol(i))=1;  
end  
mstd=sum(sum(S))  
Nstd=(H*W)-mstd;  
  
Cst=0;  
Cst=double(Cst);  
for i=1:H  
    for j=1:W  
         a=R(i,j);  
         b=R(i,j);    
         Cst=a+b+Cst;            
    end  
end  
%%%%sum of black pixels%%%%%%%%%%%  
blacksumR=0;  
for i=1:sm  
    blacksumR=blacksumR+R(srow(i),scol(i));  
end  
Cstd = Cst/(2*Nstd)  
CavgR=sum(sum(R))./(H*W)  
Rsc=Cstd./CavgR   
R=R.*Rsc;  
C=R;  
C=C/255;   
Y=C;
figure,imshow(C)  
title('aft 1st stage of compensation')  
%normalize Y  
minY=min(min(Y));  
maxY=max(max(Y));  
Y=255.0*(Y-minY)./(maxY-minY);  
YEye=Y;  
Yavg=sum(sum(Y))/(W*H)  
  
T=1;  
if (Yavg<64)  
    T=1.4  
elseif (Yavg>192)  
    T=0.6  
end  
T    
if (T~=1)  
    RI=R.^T;  
else  
    RI=R;  
end  
  
Cfinal=uint8(RI);  
figure,imshow(Cfinal)  
title('Light intensity compensated')  
  
clc; 
clear all; 
%%%%%%sourceImage%%%%%%%%% 
sourceImage = imread('F:\Users\*****\Desktop\**图像\test.bmp'); 
%imshow(sourceImage); 

SSR(sourceImage);

效果不对,不知道哪有问题:

看灰度图的处理效果还可以。

 

 

【转载自】

图像增强算法四种,图示与源码,包括retinex(ssr、msr、msrcr)和一种混合算法 - onezeros的专栏 - CSDN博客 https://blog.csdn.net/onezeros/article/details/6342661

【其他】

SSR matlab实现单尺度retinex算法,实现图像增强。 联合开发网 - pudn.com http://www.pudn.com/Download/item/id/2776026.html

%retinex% 
clc; 
clear all; 
%%%%%%sourceImage%%%%%%%%% 
sourceImage = imread('C:\Users\huang\Desktop\����1.bmp'); 
imshow(sourceImage); 
 
%%%R,G,B%%%% 
image_r=sourceImage(:,:,1); 
image_g=sourceImage(:,:,2); 
image_b=sourceImage(:,:,3); 
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

r=100; 
cParam=200; 
block=2*r+1; 
sum=0.0; 
for i=1:block 
    for j=1:block 
        gauss(i,j)=exp((-((i-r-1)^2+(j-r-1)^2))/cParam^2); 
        sum=sum+gauss(i,j); 
    end 
end 
for i=1:block 
    for j=1:block 
        gauss(i,j)=gauss(i,j)/sum; 
    end 
end 
 
%%%%%%%%%%%R%%%%%%%%%%%%% 
Img = double(image_r); 
K=imfilter(Img,gauss,'replicate','conv');   
G=log(Img+1)-log(K+1);  
 
mi=min(min(G)); 
ma=max(max(G)); 
destImage_r=(G-mi)*255/(ma-mi);  
        
%%%%%%%%%%%%%%G%%%%%%%%%%%%% 
Img = double(image_g); 
K=imfilter(Img,gauss,'replicate','conv');   
G=log(Img+1)-log(K+1); 
    
mi=min(min(G)); 
ma=max(max(G)); 
destImage_g=(G-mi)*255/(ma-mi); 
%%%%%%%%%%%%%B%%%%%%%%%%%%%%%%%% 
Img = double(image_b); 
K=imfilter(Img,gauss,'replicate','conv');   
G=log(Img+1)-log(K+1); 
    
mi=min(min(G)); 
ma=max(max(G)); 
destImage_b=(G-mi)*255/(ma-mi); 
%%%%%%%%%%%%%%%%%% 
destImageSSR=cat(3,destImage_r,destImage_g,destImage_b); 
figure; 
imshow(uint8(destImageSSR)); 
 
%etinex
clc 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
r=100; 
cParam1=30; 
cParam2=100; 
cParam3=300; 
block=2*r+1; 
sum1=0.0; 
sum2=0.0; 
sum3=0.0; 
for i=1:block 
    for j=1:block 
        gauss1(i,j)=exp((-((i-r-1)^2+(j-r-1)^2))/cParam1^2); 
        sum1=sum1+gauss1(i,j); 
        gauss2(i,j)=exp((-((i-r-1)^2+(j-r-1)^2))/cParam2^2); 
        sum2=sum2+gauss2(i,j); 
        gauss3(i,j)=exp((-((i-r-1)^2+(j-r-1)^2))/cParam3^2); 
        sum3=sum3+gauss3(i,j); 
    end 
end 
for i=1:block 
    for j=1:block 
        gauss1(i,j)=gauss1(i,j)/sum1; 
        gauss2(i,j)=gauss2(i,j)/sum2; 
        gauss3(i,j)=gauss3(i,j)/sum3; 
    end 
end 
 
%%%%%%%%%%%R%%%%%%%%%%%%% 
Img = double(image_r); 
K1=imfilter(Img,gauss1,'replicate','conv'); 
K2=imfilter(Img,gauss2,'replicate','conv'); 
K3=imfilter(Img,gauss3,'replicate','conv'); 
 
G=log(Img+1)-(1/3)*(log(K1+1)+log(K2+1)+log(K3+1));  
 
mi=min(min(G)); 
ma=max(max(G)); 
destImage_r=(G-mi)*255/(ma-mi);  
        
%%%%%%%%%%%%%%G%%%%%%%%%%%%% 
Img = double(image_g); 
K1=imfilter(Img,gauss1,'replicate','conv'); 
K2=imfilter(Img,gauss2,'replicate','conv'); 
K3=imfilter(Img,gauss3,'replicate','conv'); 
 
G=log(Img+1)-(1/3)*(log(K1+1)+log(K2+1)+log(K3+1));  
    
mi=min(min(G)); 
ma=max(max(G)); 
destImage_g=(G-mi)*255/(ma-mi); 
%%%%%%%%%%%%%B%%%%%%%%%%%%%%%%%% 
Img = double(image_b); 
K1=imfilter(Img,gauss1,'replicate','conv'); 
K2=imfilter(Img,gauss2,'replicate','conv'); 
K3=imfilter(Img,gauss3,'replicate','conv'); 
 
G=log(Img+1)-(1/3)*(log(K1+1)+log(K2+1)+log(K3+1));  
    
mi=min(min(G)); 
ma=max(max(G)); 
destImage_b=(G-mi)*255/(ma-mi); 
 
%%%%%%%%%%%%%%%%%% 
destImageMSR=cat(3,destImage_r,destImage_g,destImage_b); 
figure; 
imshow(uint8(destImageMSR)); 
 
View Code

 

 【别人博客里的一些效果图】

retinex图像增强算法的研究 - zmshy2128 - 博客园 https://www.cnblogs.com/zmshy2128/p/6126987.html

关于Retinex图像增强算法的一些新学习。 - Imageshop - 博客园 https://www.cnblogs.com/Imageshop/p/3810402.html

Retinex图像增强算法代码 - liyingjiang22的博客 - CSDN博客 https://blog.csdn.net/liyingjiang22/article/details/52903127

图像增强处理之:同态滤波与Retinex算法(二)McCann Retinex和McCann99 Retinex迭代算法 - 满城风絮 - CSDN博客 https://blog.csdn.net/piaoxuezhong/article/details/78248219

posted @ 2019-02-18 19:34  ostartech  阅读(2098)  评论(0编辑  收藏  举报