Method for detecting and localizing a falsified area in JPEG images
This disclosure relates to verifying the authenticity of images of documents. Embodiments increase the accuracy of determining the falsified area in the image. The method for detecting and localizing a falsified area in JPEG images is to consider, in the RGB color space, an image that was subjected to JPEG compression. The detection of a falsified area is based on a search for inconsistencies in the structure of the DCT coefficients. The DCT coefficients of the image are calculated with the preservation of information about the position of the corresponding 8×8 pixel blocks, and the quantization matrix is estimated by the calculated DCT coefficients, while the image is split into several blocks. The quantization step is estimated for each of the frequencies in each block, the position of the JPEG compression grid is searched, discrepancies between DCT coefficients and the quantization matrix are searched, and falsified areas are localized.
1 . A method comprising
capturing Joint Photographic Experts Group (JPEG) image;
using at least one hardware processor to:
receive the captured Joint Photographic Experts Group (JPEG) image;
compute discrete cosine transform (DCT) coefficients of the JPEG image;
save information about the position of the 8×8 pixel blocks corresponding to the coefficients;
wherein computing DCT coefficients of the JPEG image comprises:
complementing sides of the JPEG image up to a multiplicity with eight black pixels;
transforming the JPEG image from a red-green-blue (RGB) color space to a luma-blue-difference-chroma-red-difference-chroma (YCbCr) color space;
splitting a brightness channel in the YCbCr color space into a plurality of blocks of 8×8 pixels;
applying a discrete cosine transform to each of the plurality of blocks; and
discarding any of the plurality of blocks that contains pixels with saturated values;
estimate a quantization matrix of the JPEG image based on the computed DCT coefficients;
wherein estimating the quantization matrix of the JPEG image based on the computed DCT coefficients comprises, for each of 64 frequencies in each of the plurality of blocks:
calculating a factorial histogram h, wherein h(x) is a number of DCT coefficients that do not have a remainder when divided by x, for each integer x in range from 1 to 1000;
normalizing the factorial histogram h by a total number of DCT coefficients; and
estimating a quantization step of the quantization matrix for the frequency using the normalized factorial histogram h;
wherein estimating the quantization step of the quantization matrix using the normalized factorial histogram h comprises:
calculating =max{x|h(x)≥T 1 }, wherein T 1 is a predefined threshold;
when >2, estimating the quantization step for the frequency as ; and
when ≤2,
calculating y=max{x|h(x)≥T 2 }, wherein T 2 is a predefined threshold,
when y<4, estimating the quantization step for the frequency as , and
when y≥4,
constructing a modified factorial histogram h , wherein h (x) is the number of DCT coefficients that do not have a remainder when divided by x and do not belong to a set M={ky±1, k∈2}, wherein k is an integer value within a range Z,
normalizing the modified factorial histogram h by the total number of DCT coefficients that do not belong to the set M,
calculating =max{x|h(x)≥T 3 }, wherein T 3 is a predefined threshold,
when >3, estimating the quantization step for the frequency as , and
when ≤3, estimating the quantization step for the frequency as ,
search for discrepancies between the computed DCT coefficients and the estimated quantization matrix; and
determine whether the JPEG image contains any falsified areas based on a result of the search;
localizing the falsified areas;
outputting the result of localizing the falsified areas.
2 . The method of claim 1 , further comprising using the at least one hardware processor to, when determining that the JPEG image contains one or more falsified areas, identify a location of each of the one or more falsified areas.
3 . The method of claim 1 , wherein estimating the quantization step of the quantization matrix further comprises estimating a quantization step over an entirety of the JPEG image based on the quantization step estimated for each of the 64 frequencies of each of the plurality of blocks.
4 . The method of claim 1 , wherein searching for discrepancies between the computed DCT coefficients and the estimated quantization matrix comprises:
generating a first image I 1 in which each of the plurality of blocks is assigned a pixel, wherein each pixel for each of the plurality of blocks has a value representing a number of frequencies at which a DCT coefficient corresponding to the block does belong to a range {[k{circumflex over (q)}−1, k{circumflex over (q)}+1], k∈Z}, wherein k is an integer value within a range Z, and {circumflex over (q)} is the estimated quantization step for a respective frequency;
determining a set M 2 of frequencies, for which at least one of the plurality of blocks at one of the frequencies in set M 2 has a computed DCT coefficient not belonging to the range {[k{circumflex over (q)}−1, k{circumflex over (q)}+1], k∈Z};
generating a second image I 2 in which each of the plurality of blocks is assigned a pixel, wherein a size of the second image I 2 is a same size as the first image I 1 , and wherein each pixel for each of the plurality of blocks in the second image I 2 has a value representing a number of frequencies at which the DCT coefficient corresponding to the block has an absolute value greater than one; and
generating a third image I 3 , with a same size as the first image I 1 and the second image I 2 , according to:
I
3
(
u
)
=
max
{
I
1
(
u
)
-
t
I
2
(
u
)
+
1
,
0
}
wherein u is a pixel position, and t is a predefined value.
5 . The method of claim 4 , further comprising using the at least one hardware processor to, when determining that the JPEG image contains one or more falsified areas, identify a location of each of the one or more falsified areas by:
generating a fourth image I 4 by applying a morphological operation to the third image I 3 ; and
generating a fifth image I s with a same size as the JPEG image, wherein each pixel within each of the plurality of blocks in the fifth image I s has a value equal to a value of a pixel in the fourth image I 4 that corresponds to that block.
6 . The method of claim 5 , further comprising using the at least one hardware processor to calculate a probability of manipulation based on the fourth image 14 .
7 . The method of claim 1 , further comprising using the at least one hardware processor to search for a position of a JPEG compression grid for the JPEG image.
8 . A system comprising:
means for capturing Joint Photographic Experts Group (JPEG) image;
using at least one hardware processor; and
software configured to, when executed by the at least one hardware processor,
receive the captured Joint Photographic Experts Group (JPEG) image;
compute discrete cosine transform (DCT) coefficients of the JPEG image;
save information about the position of the 8×8 pixel blocks corresponding to the coefficients;
wherein computing DCT coefficients of the JPEG image comprises:
complementing sides of the JPEG image up to a multiplicity with eight black pixels;
transforming the JPEG image from a red-green-blue (RGB) color space to a luma-blue-difference-chroma-red-difference-chroma (YCbCr) color space;
splitting a brightness channel in the YCbCr color space into a plurality of blocks of 8×8 pixels;
applying a discrete cosine transform to each of the plurality of blocks; and
discarding any of the plurality of blocks that contains pixels with saturated values;
estimate a quantization matrix of the JPEG image based on the computed DCT coefficients;
wherein estimating the quantization matrix of the JPEG image based on the computed DCT coefficients comprises, for each of 64 frequencies in each of the plurality of blocks:
calculating a factorial histogram h, wherein h(x) is a number of DCT coefficients that do not have a remainder when divided by x, for each integer x in range from 1 to 1000;
normalizing the factorial histogram h by a total number of DCT coefficients; and
estimating a quantization step of the quantization matrix for the frequency using the normalized factorial histogram h;
wherein estimating the quantization step of the quantization matrix using the normalized factorial histogram h comprises:
calculating =max{x|h(x)≥T 1 }, wherein T 1 is a predefined threshold;
when >2, estimating the quantization step for the frequency as ; and
when ≤2,
calculating y=max{x|h(x)≥T 2 }, wherein T 2 is a predefined threshold,
when y<4, estimating the quantization step for the frequency as , and
when y≥4,
constructing a modified factorial histogram h , wherein h (x) is the number of DCT coefficients that do not have a remainder when divided by x and do not belong to a set M={ky±1, k∈Z}, wherein k is an integer value within a range Z,
normalizing the modified factorial histogram h by the total number of DCT coefficients that do not belong to the set M,
calculating =max{x| h (x)≥T 3 }, wherein T 3 is a predefined threshold,
when >3, estimating the quantization step for the frequency as , and
when ≤3, estimating the quantization step for the frequency as ,
search for discrepancies between the computed DCT coefficients and the estimated quantization matrix; and
determine whether the JPEG image contains any falsified areas based on a result of the search;
localizing the falsified areas;
outputting the result of localizing the falsified areas.
9 . A non-transitory computer-readable medium having instructions stores thereon, wherein the instructions, when executed by a processor, cause the processor to:
receive a captured Joint Photographic Experts Group (JPEG) image;
compute discrete cosine transform (DCT) coefficients of the JPEG image;
save information about the position of the 8×8 pixel blocks corresponding to the coefficients;
wherein computing DCT coefficients of the JPEG image comprises:
complementing sides of the JPEG image up to a multiplicity with eight black pixels;
transforming the JPEG image from a red-green-blue (RGB) color space to a luma-blue-difference-chroma-red-difference-chroma (YCbCr) color space;
splitting a brightness channel in the YCbCr color space into a plurality of blocks of 8×8 pixels;
applying a discrete cosine transform to each of the plurality of blocks; and
discarding any of the plurality of blocks that contains pixels with saturated values;
estimate a quantization matrix of the JPEG image based on the computed DCT coefficients;
wherein estimating the quantization matrix of the JPEG image based on the computed DCT coefficients comprises, for each of 64 frequencies in each of the plurality of blocks:
calculating a factorial histogram h, wherein h (x) is a number of DCT coefficients that do not have a remainder when divided by x, for each integer x in range from 1 to 1000;
normalizing the factorial histogram h by a total number of DCT coefficients; and
estimating a quantization step of the quantization matrix for the frequency using the normalized factorial histogram h;
wherein estimating the quantization step of the quantization matrix using the normalized factorial histogram h comprises:
calculating =max{x|h(x)≥T 1 }, wherein T 1 is a predefined threshold;
when >2, estimating the quantization step for the frequency as ; and
when ≤2,
calculating y=max{x|h(x)≥T 2 }, wherein T 2 is a predefined threshold,
when y<4, estimating the quantization step for the frequency as , and
when y≥4,
constructing a modified factorial histogram h , wherein h (x) is the number of DCT coefficients that do not have a remainder when divided by x and do not belong to a set M={ky±1, k∈Z}, wherein k is an integer value within a range Z,
normalizing the modified factorial histogram h by the total number of DCT coefficients that do not belong to the set M,
calculating =max{x|h(x)≥T 3 }, wherein T 3 is a predefined threshold,
when >3, estimating the quantization step for the frequency as , and
when ≤3, estimating the quantization step for the frequency as ,
search for discrepancies between the computed DCT coefficients and the estimated quantization matrix; and
determine whether the JPEG image contains any falsified areas based on a result of the search;
localizing the falsified areas;
outputting the result of localizing the falsified areas.