Invert Discrete cosine transform (DCT) of an image

913 views Asked by At

i'm working on a function in matlab that calculates the inverse DCT on an image i dont know what is note working in my code after i execute i get a black image , I alredy did the DCT function and it works all i need now is the invert DCT

any ideas plz....

here is my main programme :

I=imread('illustration.JPG');
I=rgb2gray(I);
figure,
imshow(I);title('limage original en niveau de gris');
I=I(1:1600,1:1600);
figure,
imshow(I);title('coupure de limage utilisé pour que ces dimensions   sont    multiple de 8');
figure,
DCT=dct(I);
imshow(DCT);title('DCT1');%calcule de DCT avec la function predifinie dct
DCT2=DCTlocal(I);
figure,
imshow(DCT2);title('DCT2');%calcule de DCT avec l'algorithme données

figure,
Irec=idct(DCT);
imshow(Irec/255);title('Irec ');

figure,
Irec2=InvDCTLocale(DCT2);
imshow(Irec2);title('Irec2');

and here is my DCT function :

   function image_comp = DCTlocal( I )
   N=8;
   [n1,n2]=size(I);
    I=double(I)-128;
    block_dct = zeros(N);

    %loop true block
     for k=1:N:n1
     for l=1:N:n2
      %save true image
      current_block = I(k:k+N-1,l:l+N-1);
      %loop true cos(u,v)
       for u=0:N-1
        for v=0:N-1
          if u==0
            Cu = 1/sqrt(2);
          else
            Cu = 1;
          end
        if v==0
            Cv = 1/sqrt(2);
        else
            Cv = 1;
        end
        Res_sum = 0; %loop true pixel values
         for x=0:N-1
          for y=0:N-1
            Res_sum = Res_sum +      ((current_block(x+1,y+1))*cos(((2*x)+1)*u*pi/(2*N))*cos(((2*y)+1)*v*pi/(2*N)));  
          end
         end
         dct = 1/sqrt(2*N) * Cu * Cv * Res_sum; %calculate DCT
        block_dct(u+1,v+1) = dct;
      end
     end
     image_comp(k:k+N-1,l:l+N-1) = block_dct(u+1,v+1);
    end
     end
    end

and now here is my iverse DCT function where the problem is :

      function image_decomp = InvDCTLocale( DCT )

      N=8;
      [n1,n2]=size(DCT);
      block_idct = zeros(N);

      %loop true block
       for k=1:N:n1
      for l=1:N:n2
      %save true image
      current_block = DCT(k:k+N-1,l:l+N-1);
      %loop true cos(u,v)
      for u=0:N-1
      for v=0:N-1
          if u==0
            Cu = 1/sqrt(2);
          else
            Cu = 1;
          end
        if v==0
            Cv = 1/sqrt(2);
        else
            Cv = 1;
        end
        Res_sum = 0; %loop true pixel values
         for x=0:N-1
          for y=0:N-1
            Res_sum = Res_sum +Cu* Cv *   ((current_block(x+1,y+1))*cos(((2*x)+1)*u*pi/(2*N))*cos(((2*y)+1)*v*pi/(2*N)));  
          end
         end
         I = 1/sqrt(2*N)*Res_sum; 
        block_idct(u+1,v+1) = I;
      end
     end
     image_decomp(k:k+N-1,l:l+N-1) = block_idct(u+1,v+1);
 end
 end
 end
0

There are 0 answers