Skip to main content

PRNU Toolkit & AI Predictor

A Python library for Photo-Response Non-Uniformity (PRNU) noise extraction, camera identification through fingerprint correlation and a ResNet-18-based AI image detector.

Refer to the interactive website as a usage example and the repository

Installation

pip install prnu

Usage Examples

1. Extract visible noise

Extract PRNU noise from an image and scale subtle variance into a viewable 8-bit PNG image:

import prnu

# Initialize extractor with an image file path
extractor = prnu.NoiseExtractor("image.png")

# Extract PRNU multiplicative noise residual
extractor.extract_noise()

# Make the noise visible
extractor.shift_to_visual()

# Save visual representation to disk
extractor.write_to_file("visual_noise.png")

2. Camera identification

Average the noise patterns from training photos taken by a single camera, compute an average reference fingerprint, and then test an unknown image:

import os
import prnu

training_dir = "/path/to/camera_samples"
test_image_path = "/path/to/test_image.jpg"

# 1. Collect noise from training photos
avg = prnu.AverageNoise()
for file_name in os.listdir(training_dir):
    file_path = os.path.join(training_dir, file_name)
    
    # Extract noise without zero-meaning during aggregation
    extractor = prnu.NoiseExtractor(file_path)
    extractor.extract_noise(disable_zero_meaning=True)
    avg.add_image_data(extractor)

# Compute final reference fingerprint
avg.analyse()

# 2. Extract noise from test image
test_extractor = prnu.NoiseExtractor(test_image_path)
test_extractor.extract_noise()

# 3. Correlate test image against reference profile
comparison = prnu.Compare(test_extractor, avg)
score = comparison.correlate()

print(f"Correlation Score: {score:.5f}")
if score > 0.008:
    print("The test image likely originated from the target camera sensor.")

Generally with a correlation score of 0.008 or higher a photo can be considered as being from the same camera

3. AI Image Detection

Load the attached trained ResNet-18 model to predict the likelihood that a give image is AI-generated:

import prnu.ai_predictor as ai_predictor

# Initialize model instance
model = ai_predictor.Model() # this model is saved in your python installation

model.load():
# Returns scaled AI probability between 0 and 1
probability = model.predict("sample_image.png", optimal_probability=0.97) # For the included model 0.97 is the optimal threshold
print(f"AI Probability: {probability * 100:.2f}%")

License

This software is licensed under the GPLv3 License.

Metadata

Release files for prnu 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prnu 0.1.2
File Size Uploaded Provenance Actions
prnu-0.1.2.tar.gz 41.6 MB Without provenance Details for prnu-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for prnu 0.1.2
File Interpreter ABI Platform Actions
prnu-0.1.2-py3-none-any.whl Python 3 none any Details for prnu-0.1.2-py3-none-any.whl

Total release size: 83.1 MB

Release files / prnu-0.1.2.tar.gz

Download URL prnu-0.1.2.tar.gz
Size 41.6 MB
Tags Source
SHA-256 checksum
How to use checksums
63a9199d8486f52d07a858759b746d4aa010ab61bd5d24effacea83b69822d27
BLAKE2b-256 checksum
How to use checksums
3fab21d5f6c86e62ea802a3d04d84cf93dda9209224ffd46ba004bfa31d31ca6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.7

Release files / prnu-0.1.2-py3-none-any.whl

Download URL prnu-0.1.2-py3-none-any.whl
Size 41.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
19fd6439bf34b4537e160049a748777a75d1c7e6827046e203fac8b6bf6d6875
BLAKE2b-256 checksum
How to use checksums
e83087787412dac9dde6804778ab816ae527cd4a00ddc466807af73144d38492
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.7

Security for prnu 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page