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.
Links
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 ai_predictor
# Initialize model instance
model = ai_predictor.Model() # this model is saved in your python installation
if model.load():
# Returns scaled AI probability between 0 and 1
probability = model.predict("sample_image.png")
print(f"AI Probability: {probability * 100:.2f}%")
License
This software is licensed under the GPLv3 License.
Metadata
Release files for prnu 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| prnu-0.1.0.tar.gz | 41.6 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| prnu-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 83.1 MB
Release files / prnu-0.1.0.tar.gz
| Download URL | prnu-0.1.0.tar.gz |
|---|---|
| Size | 41.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
35b869d2fc64ef60e8ee71b8102a01be977e1b045c95e0a1407a45c9d28c0561
|
|
BLAKE2b-256 checksum How to use checksums |
0c271a8483b65ae34017254e132b30d919c6f4a907adcdcebdf716203c1a410f
|
| 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.0-py3-none-any.whl
| Download URL | prnu-0.1.0-py3-none-any.whl |
|---|---|
| Size | 41.6 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c413e5948b3f03ef87ce2e888ecf688f6c94af156f2dbc2f6caf32601c65a032
|
|
BLAKE2b-256 checksum How to use checksums |
ce8ceb73d3390864b9da9ed575d632f109ba1188f818c0302215e947fa3efb67
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.7
|