Search code examples
matlabimage-processingvideo-processingdct

Matlab: How to combine blocks back to original matrix?


So I calculated the inverse dct of smaller blocks of 8x8. I need to combine them all into a matrix. How can I combine them? This is my intermediate code. Upon each iteration, i-dct of a block is calculated and stored in idctBlock.

for row=1:8
   for col=1:8
       chunk = X{row,col};
       dctCalculates = idct2(block)
       
    end
end

Any help please?


Solution

  • You can preallocate the matrix and insert the blocks into the right position:

    matrix = zeros(144, 176);
    for row=1:8
       for col=1:8
           block = X{row,col};
           idctBlock = idct2(block)
           matrix(8 * (row - 1) + (1:8), 8 * (col - 1) + (1:8)) = idctBlock;
        end
    end