K
K
Kib90722021-05-08 22:01:34
OpenCV
Kib9072, 2021-05-08 22:01:34

How to implement the Discrete Cosine Transform image in Python yourself without resorting to a library?

Good afternoon, there was such a problem. I just can not implement the image DCT. There is no good material on the Internet explaining this moment. It is also not clear to take an 8x8 matrix from the original NxN image and perform operations on the entire matrix or on each pixel. Below is an explanation of the conversion algorithm

6096dfb8e9b6a202416772.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Wataru, 2021-05-08
@wataru

The transformation is defined over an NxN matrix. In the formulas in the tutorial, f(u,v) is the value of the pixel in the cell with indices u, v. You need to stupidly implement the formulas from the textbook (4 nested loops).
Whether you need to apply the transformation separately to each block of 8x8 pixels or not - this should be written in the task. In some jpeg, the transformation is applied separately to each piece of 8x8 pixels, and not to the entire image, because on a large scale the image is too irregular. And for regular patterns, the result of the discrete cosine transform compresses well (many zeros and small coefficients). Also, applying the transformation to the entire image will be slower.
But this does not apply to the transformation itself. This is a subtlety of the jpeg algorithm.

G
Griboks, 2021-05-08
@Griboks

https://docs.scipy.org/doc/scipy/reference/generat...
https://github.com/scipy/scipy/blob/v1.6.3/scipy/f...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question