反转图像的离散余弦变换(DCT)

时间:2016-12-21 13:46:32

标签: matlab image-processing dct

我正在使用matlab中的一个函数计算图像上的逆DCT我不知道在执行后我的代码中有什么注意工作我得到一个黑色图像,我alredy做了DCT功能,它工作所有我现在需要的是反转DCT

任何想法都可以......

这是我的主要计划:

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');

这是我的DCT功能:

   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

现在这是我的逆向DCT功能,问题是:

      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 个答案:

没有答案