# Facing problem in plotting histogram of DCT coefficient of an image

In digital image forensic, it is assumed that the histogram of DCT coefficients of the un-compressed natural image has the smooth histogram. However, the histogram of DCT coefficients of the compressed natural image has peaks and gap in it. One such problem is discussed in this work. see this image for a better understanding .

I am using the following MATLAB code to plot the histogram of DCT coefficients of uncompressed and compressed images.

x_axis = -1000:0.01:1000;

subplot(2,2,1), imshow(img_1), title('Image');
subplot(2,2,2), imshow(img_2), title('Compressed Image');
subplot(2,2,3), plot(x_axis, histogram(dct2(double(img_1)))), title('Image');
subplot(2,2,4), plot(x_axis, histogram(dct2(double(img_2)))), title('Compressed Image');


but I am unable to get the results in the desired manner. see this figure below .

Can anyone please explain? what is the correct way of plotting the histogram of DCT coefficient of an image so that I may get the correct results?

• Try with a more evenly bright input image. Aug 9 '18 at 12:57
• Sir, I have tried this code for more than 20 images of all types, but I am still facing the same problem. Aug 10 '18 at 5:18
• I just recommended that because your input image's histogram was extremely concentrated Aug 10 '18 at 6:47
• Hope this will be helpful ： y = dct(double(Img)) Jul 15 '19 at 3:16
• Any more answers required? Aug 15 '19 at 18:20

My guess is that the assertion

"the histogram of DCT coefficients of the un-compressed natural image has the smooth histogram ... However, the histogram of DCT coefficients of the compressed natural image has peaks and gap in it."

is valid when one uses a compression method that uses a DCT (Discrete Cosine Transform), and quantizes (sufficiently) its coefficients. This might not happen for compression methods that differ from JPEG/MPEG principles, that use a 2D DCT. Moreover, JPEG applies DCT2 on $$8\times 8$$ blocks, and the DC coefficient undergoes a predictive compression scheme different than that of the other AC coefficients.

So I am not surprised that you don't observe quantization when you apply the DCT on the whole image instead of blocks (I obtained the same results).

What could be more successful would be to compare the DCT coefficient histograms (DC coefficient removed) on each of the $$8\times 8$$ blocks, raw and compressed, and then combining the coefficients of all the blocks. Here is an attempt, in Matlab.

As you can see, you now have holes in the right-side histograms, due to quantization.

nBin = 512;
dctCoeffLimit = 80;

% Compute block DCT with mean removed
funDCT2 = @(block_struct) dct2(block_struct.data-mean(mean((block_struct.data))));
img_1DCT= (blockproc(img_1,[8 8],funDCT2));
img_2DCT= (blockproc(img_2,[8 8],funDCT2));

% Set DC coefficients to NaN
img_1DCT(1:8:end,1:8:end) = nan;
img_2DCT(1:8:end,1:8:end) = nan;

% Convert 2D to 1D
img_1DCTflat = img_1DCT(:);
img_2DCTflat = img_2DCT(:);

% Remove DC (NaN) values
img_1DCTflat(isnan(img_1DCTflat)) = [];
img_2DCTflat(isnan(img_2DCTflat)) = [];

subplot(1,2,1)
histogram(img_1DCTflat,nBin);axis([-dctCoeffLimit dctCoeffLimit 0 Inf]);
subplot(1,2,2)
histogram(img_2DCTflat,nBin);axis([-dctCoeffLimit dctCoeffLimit 0 Inf]);