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 1If 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 0with 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 0For 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
Solution Comments
Show commentsProblem Recent Solvers4
Suggested Problems
-
Given an unsigned integer x, find the largest y by rearranging the bits in x
2055 Solvers
-
What is the distance from point P(x,y) to the line Ax + By + C = 0?
560 Solvers
-
Longest run of consecutive numbers
6634 Solvers
-
107 Solvers
-
Sum the elements in either diagonal of a square matrix
222 Solvers
More from this Author4
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!