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. – Marcus Müller 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. – Mayank Tiwari Aug 10 '18 at 5:18
• I just recommended that because your input image's histogram was extremely concentrated – Marcus Müller Aug 10 '18 at 6:47
• Hope this will be helpful ： y = dct(double(Img)) – violet li Jul 15 at 3:16
• Looks like you have a very strong DC component that may mask the rest of the coefficients. Have you tried centerin it, i.e., subtracting the image's mean before the DCT2? You can also try to put the y-axis logarithmically, this will reveal the smaller coefficients more visibly. – Florian Jul 15 at 7:38

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 and quantizes (sufficiently) it coefficents. This might not happen for compression methods outside JPEG, that uses a DCT2. Moreover, JPEG applies DCT2 on $$8\times 8$$ blocks, and the DC coefficient overgoes a compression scheme different than that of the AC coefficients.

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

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

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]);