This repository is a compact PRNU-based tamper-detection demo for PRISM-D. Instead of using wavelets and other traditional denoisers, PRSIM-D uses the DoG-LCN residual representation for PRNU estimation, thereby reducing extraction time. Moreover, PRISM-D includes PCE gating for full frame injection attack detection and MSF tamper localization algorithm to localize the exact tamper area.
The pipeline has two phases:
offline: builds per-camera artifacts, including a PRNU fingerprint, PCE threshold, q-hat predictors, and sigma estimates.online: runs a full-frame PCE gate first. If the query is rejected by PCE, the output is an all-white mask. If the query passes PCE, the code runs MSF tamper localization and writes a binary mask.
Available Soon
The main implementation lives in these files:
main.py: CLI entry point and offline / online orchestration.helper.py: dataset discovery, image listing, JSON I/O, model loading, and other small I/O helpers.prnu.py: grayscale image loading, DoG-LCN residual extraction, and PRNU fingerprint estimation.pce.py: normalized cross-correlation, PCE scoring, PCE calibration, and PCE gate decision.predictor.py: q-hat predictor training, various feature grids calcualtions, ridge fitting, and sigma estimation.msf.py: multi-scale fusion tamper localization and final binary mask generation.
Create a virtual environment and install the Python dependencies:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txtDependencies are listed in requirements.txt:
numpy
opencv-python
scipy
scikit-learn
PyWavelets
PyMaxflow
Build artifacts for all discovered protected cameras with default path:
python3 main.py offlineBuild artifacts for one camera, and specified the path to dataset and artifacts:
python3 main.py offline --camera CAM_FRONT --data-root Image_Database/nuscenes --out artifactsEach camera writes:
artifacts/<CAMERA>/
|-- fingerprint.npy
|-- fingerprint.png
|-- predictor_w64.npz
|-- predictor_w128.npz
|-- predictor_w256.npz
|-- sigma.json
|-- pce_calibration.json
`-- model.json
model.json is the online phase entry point for a camera. It records the artifact paths and the DoG-LCN, PCE, predictor, and MSF parameters used to build the model.
Run online inference for all discovered cameras with default path::
python3 main.py onlineRun online inference for one camera, and specified the path to dataset and artifacts::
python3 main.py online --camera CAM_FRONT_LEFT --data-root Image_Database/nuscenes --artifact-root artifacts --out outputsEach query writes:
outputs/<CAMERA>/<image_name>/
|-- tamper_mask.png
`-- decision.json
decision.json records the PCE score, PCE threshold, PCE gate decision, final decision, mask type, sigma values, MSF windows, graph-cut usage, and parameter snapshots.
For each query image:
- Preprocess each query image.
- Extract a DoG-LCN residual representation.
- Compute PCE between the query residual and the camera fingerprint.
- If
PCE < tau, returnrejected_by_pceand write an all-white mask. - If
PCE >= tau, run MSF tamper localization. - If the MSF mask has no foreground pixels, the final decision is
authentic; otherwise it istampered.
CAM_FRONT demonstrates local tamper localization. Its query images pass the PCE gate and are localized by MSF.
CAM_FRONT_LEFT demonstrates PCE gate behavior:
- Genuine
CAM_FRONT_LEFTclean queries should pass PCE and produce all-black MSF masks, meaning "authentic". - Foreign
CAM_BACKclean queries should be rejected by PCE and produce all-white masks, meaning "full frame injection".
- The code requires at least two protected camera folders for offline calibration because each camera uses another discovered camera as the impostor source for sigma0 and PCE threshold calibration.
- The current dataset is small and curated for demo behavior. It is not a full benchmark reproduction.