# Do the DCT coefficients correspond to particular pixels?

Getting the DCT coefficient based on what I've read, is usually done through a matrix, usually 8x8 or 16x16 using these formulas:

B_{pq}=\alpha_p\alpha_q\sum_{m=0}^{M-1}\sum_{n=0}^{N-1}A_{mn}\cos\left(\frac{\pi(2m+1)p}{2M}\right)\cos\left(\frac{\pi(2n+1)q}{2N}\right),\quad \begin{align} &0\leq p\leq M-1\\ &0\leq q\leq N-1 \end{align}

$$\alpha_p=\left\{ \begin{array}{ll} 1/\sqrt{M},& p=0\\ \sqrt{2/M}, & 1\leq p\leq M-1 \end{array}\right. \quad \alpha_q=\left\{ \begin{array}{ll} 1/\sqrt{N},& q=0\\ \sqrt{2/N}, & 1\leq q\leq N-1 \end{array}\right.$$

However, I would like to know if it is possible to determine the corresponding DCT coefficient of a pixel or of the edges of an image? Is there a way to detect edges through DCT coefficients?

• I'm not sure what you're asking. Are you looking for a way to associate a single pixel with a set of DCT coefficients? That's not really possible in any useful way. The DCT is a transform that maps an $N$-dimensional signal into an equally-sized $N$-dimensional signal. So, if you want an 8-by-8 matrix of DCT coefficients, you need an 8-by-8 matrix of pixel values to generate them. – Jason R Jan 18 '12 at 14:50
• What I'm planning to do is to apply edge detection to obtain the locations/indices of the pixels and then get their corresponding DCT Coefficient. – Frank Smith Jan 18 '12 at 21:25
• What I was trying to tell you with my previous comment is that there isn't a one-to-one mapping between a pixel and a DCT coefficient. An 8-by-8 DCT matrix, for example, is a function of each of the pixels in the 8-by-8 block that it was generated from. – Jason R Jan 18 '12 at 21:44

What I'm planning to do is to apply edge detection to obtain the locations/indices of the pixels and then get their corresponding DCT Coefficient

As others stated in the comment - any pixel in the given block is related to all co-efficient in the block and vice-versa.

However, understand that Edge detection is a process of finding the gradient. Linear convolution essentially does the job. What you can do is to apply equivalent of that convolution in the DCT domain which will give you an idea about the edge orientation in the DCT block domain.

While, this is relatively narrow area - there are papers which allows you to find edges in DCT blocks. See the references below:

One can get the presence of an edge in a given DCT block. It is easier to compute the First order and second order moments from the given DCT coefficients. Variance in a small region is an approximation of the gradient at the center (x0,y0) of the block. The Variance in a block can be estimated from the DCT coefficients as summation of squares of the AC coefficients. It might not be possible to know the exact coordinates in the block containing the edge.

• Thanks pv. Can you explain a bit more about finding first and second order moments from the dct coefficients? This seems like a very useful technique. – user391339 Feb 11 '15 at 18:43

Perhaps you can detect the presence of a sharp change in color/brightness by detecting high frequency components in the Y block. If there are non-zero coefficients in the high frequency end of the DCT block, that indicates a sharp edge. You won't know its exact position in the block without doing the transform, but you can know if there is a sharp line/dot.

you can´t. As you can see from the formula you posted, each DCT coefficient is a function of all the pixels in the block you are considering. Same holds for edges: if you extract the edges from an image, and then apply DCT using 8x8 blocks, each DCT coefficient depends on the value of the 64 pixels in the block