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
pip install prnu
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")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
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}%")This software is licensed under the GPLv3 License.