contras3

PURPOSE ^

CONTRAS3 transforms to contrast local DCT amplitudes

SYNOPSIS ^

function [dctf,Lm]=contras3(s,Ncuan,norm,To,DUmax,DVmax)

DESCRIPTION ^

 CONTRAS3 transforms to contrast local DCT amplitudes
 with Ncuan resolution in an YUV image.

 Ncuan resolution means blocks of size L_b = L/(2^Ncuan), where L is the image side size.


 CONTRAS3 allows three types of normalization:

 * Using the overall average image color (norm = 1)
 * Using the average color of each block (norm = 2)
 * Using color reference provided in To (in RGB NTSC) (norm = 3)
     For reference, the average color of the 19 analyzed images (in RGB NTSC
     uncalibrated) is To = [132 116 90] (which has a luminance of 118 cd/m2)


 The inverse is ICONTRAS3

 USE: [dctf,Lm]=contras3(dcti,Ncuan,Norm,To,DUmax,DVmax);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % CONTRAS3 transforms to contrast local DCT amplitudes
0002 % with Ncuan resolution in an YUV image.
0003 %
0004 % Ncuan resolution means blocks of size L_b = L/(2^Ncuan), where L is the image side size.
0005 %
0006 %
0007 % CONTRAS3 allows three types of normalization:
0008 %
0009 % * Using the overall average image color (norm = 1)
0010 % * Using the average color of each block (norm = 2)
0011 % * Using color reference provided in To (in RGB NTSC) (norm = 3)
0012 %     For reference, the average color of the 19 analyzed images (in RGB NTSC
0013 %     uncalibrated) is To = [132 116 90] (which has a luminance of 118 cd/m2)
0014 %
0015 %
0016 % The inverse is ICONTRAS3
0017 %
0018 % USE: [dctf,Lm]=contras3(dcti,Ncuan,Norm,To,DUmax,DVmax);
0019 %
0020 
0021 function [dctf,Lm]=contras3(s,Ncuan,norm,To,DUmax,DVmax)
0022 
0023    ss=s;
0024    tam=size(ss);
0025 
0026    if length(tam)==3
0027       capas=tam(3);
0028    else
0029       capas=1;
0030    end
0031    tam=tam(1);
0032 
0033    lados=[tam tam];
0034 
0035    dctf=zeros(tam,tam,capas);
0036 
0037    lcuan=tam/(2^Ncuan);
0038 
0039    posai=[tam tam]/2-round(tam/2);
0040    posbd=[tam tam]/2+round(tam/2);
0041    coorcuanai=floor([(posai(1)-1)/lcuan+1 (posai(2)-1)/lcuan+1]);
0042    coorcuanbd=floor([(posbd(1)-1)/lcuan+1 (posbd(2)-1)/lcuan+1]);
0043    if coorcuanai(1)<1
0044         coorcuanai(1)=1;
0045    end
0046    if coorcuanai(2)<1
0047         coorcuanai(2)=1;
0048    end
0049    if coorcuanbd(1)>(2^Ncuan)
0050         coorcuanbd(1)=2^Ncuan;
0051    end
0052    if coorcuanai(2)>(2^Ncuan)
0053         coorcuanbd(2)=2^Ncuan;
0054    end
0055 
0056    Mrgb_yuv =[0.2990    0.5870    0.1140;-0.1726   -0.3388    0.5114;0.5114   -0.4282   -0.0832];
0057    Myuv_rgb = inv(Mrgb_yuv);
0058 
0059 if norm==1
0060     DCT11=[0 0 0];
0061     Nbloques=0;
0062     for ii=coorcuanai(1):coorcuanbd(1)
0063         for jj=coorcuanai(2):coorcuanbd(2)
0064 
0065             iii=(ii-1)*lcuan+ceil(lcuan/2);
0066             jjj=(jj-1)*lcuan+ceil(lcuan/2);
0067 
0068             for i=1:capas
0069                 s=ss(:,:,i);
0070                 blo=sacasub(s,[iii jjj],[lcuan lcuan],0);
0071                 DCT11(i)=DCT11(i)+blo(1,1);
0072             end
0073             Nbloques=Nbloques+1;
0074 
0075         end
0076     end
0077     DCT11=DCT11/Nbloques;
0078     if capas==3
0079        To_yuv=DCT11/lcuan;
0080        To=(Myuv_rgb*To_yuv')';
0081     else
0082        To=DCT11/lcuan;
0083        To_yuv=To;
0084     end
0085 elseif norm==2
0086     To=0;
0087 else
0088     if capas==3
0089        To_yuv=(Mrgb_yuv*To')';
0090     else
0091        To_yuv=To;
0092     end
0093 end
0094 
0095 factores_DCT_discreta=2*ones(lcuan,lcuan)/lcuan;
0096 factores_DCT_discreta(1,:)=sqrt(2)*ones(1,lcuan)/lcuan;
0097 factores_DCT_discreta(:,1)=sqrt(2)*ones(lcuan,1)/lcuan;
0098 factores_DCT_discreta(1,1)=1/lcuan;
0099 
0100 dctf=ss;
0101 
0102 for i=1:capas
0103 
0104     s=ss(:,:,i);
0105     for ii=coorcuanai(1):coorcuanbd(1)
0106         for jj=coorcuanai(2):coorcuanbd(2)
0107 
0108             iii=(ii-1)*lcuan+ceil(lcuan/2);
0109             jjj=(jj-1)*lcuan+ceil(lcuan/2);
0110             blo=sacasub(s,[iii jjj],[lcuan lcuan],0);
0111 
0112             if i==1
0113                 if norm==1
0114                     deltaT=factores_DCT_discreta.*blo;
0115                     contraste=deltaT/To_yuv(1);
0116                     Lm(ii,jj,i)=deltaT(1,1);
0117                     contraste(1,1)=0;
0118                 elseif norm==2
0119                     deltaT=factores_DCT_discreta.*blo;
0120                     To=deltaT(1,1);
0121                     contraste=deltaT/To;
0122                     Lm(ii,jj,i)=deltaT(1,1);
0123                     contraste(1,1)=0;
0124                 else
0125                     deltaT=factores_DCT_discreta.*blo;
0126                     contraste=deltaT/To_yuv(1);
0127                     Lm(ii,jj,i)=deltaT(1,1);
0128                     contraste(1,1)=0;
0129                 end
0130             else
0131                 if norm==1
0132                     if i==2
0133                        W=To';
0134                        YW=To_yuv(1);
0135                        e1=(Myuv_rgb*[0;DUmax;0]+W)/YW;
0136                        e2=2*W/YW-e1;
0137                        div=Mrgb_yuv*(e1-e2);
0138                        div=div(2);
0139 
0140                     else
0141                        W=To';
0142                        YW=To_yuv(1);
0143                        e1=(Myuv_rgb*[0;0;DVmax]+W)/YW;
0144                        e2=2*W/YW-e1;
0145                        div=Mrgb_yuv*(e1-e2);
0146                        div=div(3);
0147 
0148                     end
0149                     deltaT=factores_DCT_discreta.*blo;
0150                     contraste=(2/YW)*deltaT/div;
0151 
0152                     Lm(ii,jj,i)=deltaT(1,1);
0153                     contraste(1,1)=0;
0154                 elseif norm==2
0155                     To_yuv=[0;0;0];
0156                     for lala=1:3
0157                         bobo=sacasub(ss(:,:,lala),[iii jjj],[lcuan lcuan],0);
0158                         To_yuv(lala)=bobo(1,1)/lcuan;
0159                     end
0160                     To=Myuv_rgb*To_yuv;
0161                     if i==2
0162                        W=To;
0163                        YW=To_yuv(1);
0164                        e1=(Myuv_rgb*[0;DUmax;0]+W)/YW;
0165                        e2=2*W/YW-e1;
0166                        div=Mrgb_yuv*(e1-e2);
0167                        div=div(2);
0168                     else
0169                        W=To;
0170                        YW=To_yuv(1);
0171                        e1=(Myuv_rgb*[0;0;DVmax]+W)/YW;
0172                        e2=2*W/YW-e1;
0173                        div=Mrgb_yuv*(e1-e2);
0174                        div=div(3);
0175                     end
0176                     deltaT=factores_DCT_discreta.*blo;
0177                     contraste=(2/YW)*deltaT/div;
0178                     Lm(ii,jj,i)=deltaT(1,1);
0179                     contraste(1,1)=0;
0180                 else
0181                     if i==2
0182                        W=To';
0183                        YW=To_yuv(1);
0184                        e1=(Myuv_rgb*[0;DUmax;0]+W)/YW;
0185                        e2=2*W/YW-e1;
0186                        div=Mrgb_yuv*(e1-e2);
0187                        div=div(2);
0188                     else
0189                        W=To';
0190                        YW=To_yuv(1);
0191                        e1=(Myuv_rgb*[0;0;DVmax]+W)/YW;
0192                        e2=2*W/YW-e1;
0193                        div=Mrgb_yuv*(e1-e2);
0194                        div=div(3);
0195                     end
0196                     deltaT=factores_DCT_discreta.*blo;
0197                     contraste=(2/YW)*deltaT/div;
0198                     Lm(ii,jj,i)=deltaT(1,1);
0199                     contraste(1,1)=0;
0200                 end
0201             end
0202             dctf(:,:,i)=metesub(dctf(:,:,i),[iii jjj],contraste);
0203         end
0204     end
0205 end
0206

Generated on Fri 07-Mar-2014 13:29:20 by m2html © 2005