I have divided an image into 32x32 blocks. Now I want to combine these blocks to recover the original image. How can I do this using matlab?

This is the code I use to divide the image in to blocks:

C=imread('lena.jpg');
C = rgb2gray(C);
C=imread('D1.gif')
x2=im2double(x1);

    [m,n,k]=size(x2) % and m=n with 1 channel k=1
    ImageSize=m*n;
    BlockD=32; 
    BlockSize=BlockD*BlockD;
    NoOfBlock=ImageSize/BlockSize;
    SubB=zeros(BlockD,BlockD,NoOfBlock); %arrays of blocks.
    X=zeros(BlockD,BlockD,NoOfBlock);
%    important to convert uint8 to double when dialing with image. 
%     thats what ru asking for.
    k=1;
    for i=1:BlockD:m
      for j=1:BlockD:n
        x(:,:,k)=x2(i:i+BlockD-1,j:j+BlockD-1);
        k=k+1;

      end
    end

0 Answers