Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python implementation of re-sampling algorithm #88

Merged
merged 2 commits into from
Jun 20, 2024

Conversation

UHstudent
Copy link
Contributor

This commit implements probability maps and fourier maps for detecting traces of resampling as explained in the paper:
"Exposing Digital Forgeries by Detecting Traces of Re-sampling" by Hany Farid & Alin C. Popescu
The book "Photo Forensics" by Hany Farid gives a more detailed explanation of the technique for those interested

The interface is pretty user friendly, but could be improved upon.

Brief explanation on how the tool might be used for analysis:

Upon opening the resampling tool, the image is displayed in grayscale. (re-sampling analysis must be done in grayscale in order to avoid CFA artifacts.)

left click on the image to select regions of interest to calculate the probability map; right click to remove last point.
if no region of interest is selected, the probability maps for the entire image is calculated when clicking the corresponding button.

In order to calculate fourier maps for a given area, switch the checkbox to "fourier Windows"

Analysis of fourier maps to verify periodic artifacts can be difficult, because JPEG compression artifacts are already visible at 98-99% quality and these periodic artifacts influence the visibility of other interpolation artifacts that might have been introduced through re-sizing,...
Further more, depending on the camera, an original picture at 0% compression might already have some type of periodic artifact.

To successfully use re-sampling for forensic analysis, it is advisable to compare fourier maps from different regions to the "general" fourier map of the entire picture.

local areas that were part of the original picture, should display a similar fourier map; where as manipulated regions might have a distinct fourier map and thus indicative of tampering/not being part of the original capture.

The probability map can also aide analysis, as similar regions should have a similar probability of being interpolated, when this is not the case, one region might be manipulated.

Different parameters to construct the fourier map have a huge impact on how periodic patterns might be perceived. Only compare fourier maps that have equal settings!

Uniform areas and different manipulations (compression, re-size, rotate,..) will disturb each others' periodic signals and make analysis more difficult.

@GuidoBartoli GuidoBartoli merged commit 8ecde49 into GuidoBartoli:master Jun 20, 2024
GuidoBartoli added a commit that referenced this pull request Jun 20, 2024
… 'PIL.JpegImagePlugin'` error (#72)

- Avoid clipping when importing RAW files (#86)
- Added Image Resampling tool (#88)
- Updated README.md
@Ray9T
Copy link

Ray9T commented Jun 21, 2024

Hello @UHstudent , @GuidoBartoli It's exciting to watch newer theories getting integrated into this app.
Question I have is, has this resampling method tested against known fabrications?
I have a set of images that the previous version clearly shows areas of fabrication, but from 0.89 version, those separations are less pronounced and very faded or blended in.

Was this paper/theory tested against known fabrications, and can you share the image sources?

@UHstudent
Copy link
Contributor Author

UHstudent commented Jun 23, 2024

Hi @Ray9T

Thanks for your interest in the developments to the project!

I've tested the resampling method extensively against real and manipulated images. (pictures taken by my cellphone and resized with cv2 library.) My general conclusion is that the compression artifacts generally overshadow resampling artifacts. For this reason, it is difficult to analyse most pictures since most camera's compress pictures automatically.

One drawback to my own testing, is that my device only allowed uncompressed images to be taken in a ".dng" format. When converting this format to grayscale with rawpy, a periodic artifact is introduced and detected by the algorithm. I know the periodic artifact is introduced by rawpy, as changing the demosaic algorithm, changes the periodic output:
image

Haney Farid in his paper uses a dataset made by a device he owns that is able to shoot uncompressed ".tif" images. To my knowledge, this dataset has not been made publicly available.

I've also tested on the "standard" test images found here:
https://www.imageprocessingplace.com/root_files_V3/image_databases.htm

Depending on how the fourier map is constructed, the results of the original paper is almost perfectly replicated. Note that the paper mentions that it shows "the central part of the fourier map", but gives no clear instructions on when or how this part is taken.

Here follows the original (color) mandril, followed by 5, 10 and 20% upsampling:
image
image
image
image
image

To my knowledge, this is the first time the resampling algorithm has been enabled for execution in the project? So I'm not sure what you mean by different versions showing different results?

Finally, consider this analysis. A picture of a classroom made by a cellphone at 95% JPEG quality. A part of the top right has been taken, resized, and inserted in the bottom right (cv2 lib):
actualrisize

local analysis (hanning, upsample, Highpass 1, gamma correction 4, rescale spectrum):
bottom fourier = resized area, top fourier we perceive JPEG compression
localized analysis

global analysis, same parameters:
general analysis

Please let me know your thoughts and insights!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants