Cody

Problem 929. Rearrange coefficients after block based DCT transform.

Two dimensional block-based discrete cosine transform (DCT-II) is a widely used spatio-frequency image representation for image and video compression.

If we use same-size blocks we can group coefficients into frequency bands.

For example, consider a following 8x8 image:

    1 1 1 1 0 0 0 0
    1 1 1 1 0 0 0 0
    1 1 1 1 0 0 0 0
    1 1 1 1 0 0 0 0
    0 0 0 0 1 1 1 1
    0 0 0 0 1 1 1 1
    0 0 0 0 1 1 1 1
    0 0 0 0 1 1 1 1

If we split it into four 4x4 blocks we have DCTs of zero-blocks equal to zero-blocks and:

 dct2([ 1 1 1 1
        1 1 1 1
        1 1 1 1 
        1 1 1 1]) =
  4 0 0 0
  0 0 0 0
  0 0 0 0
  0 0 0 0

with the only non-zero element representing DC component and zeros representing AC components. We want to rearrange coefficients so corresponding components from different blocks are grouped together.

The result will be:

    4 0 0 0 0 0 0 0
    0 4 0 0 0 0 0 0
    0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0

For a grayscale image (matrix) of size NxM and block size nxm (it is guaranteed that an image can be divided into blocks of this size) return NxM matrix grouped by frequencies (with DC components inside N/n x M/m block in the most top-left corner).

Solution Stats

21.43% Correct | 78.57% Incorrect
Last solution submitted on Jan 12, 2016
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Join the 15-year community celebration.

Play games and win prizes!

Learn more