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 histogram plot of DCT coefficients.

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;

img_1 = rgb2gray(imread('a.tif'));
img_2 = rgb2gray(imread('b.tif'));

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 results that I am getting.

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?

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

Histograms of DCT coefficients

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

nBin = 512;
dctCoeffLimit = 80;

img_1 = double(rgb2gray(imread('lena.bmp')));
img_2 = double(rgb2gray(imread('lena.jpg')));

% 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)) = [];

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.