87 lines
1.9 KiB
Markdown
87 lines
1.9 KiB
Markdown
# SpectralForensics
|
|
|
|
SpectralForensics is an open-source Python library for image forensic analysis using **Fast Fourier Transform (FFT)** and frequency-domain feature extraction.
|
|
|
|
The library was designed to support research in digital image forensics, synthetic media detection, diffusion model analysis, and explainable artificial intelligence (XAI).
|
|
|
|
## Features
|
|
|
|
SpectralForensics extracts a set of interpretable spectral descriptors from images:
|
|
|
|
- Spectral Entropy
|
|
- Anisotropy
|
|
- Dominant Frequency
|
|
- Energy Density
|
|
- High Frequency Ratio
|
|
- Mean Spectral Energy
|
|
|
|
These descriptors can be used for:
|
|
|
|
- AI-generated image detection
|
|
- Deepfake forensics
|
|
- Diffusion model fingerprinting
|
|
- Frequency-domain analysis
|
|
- Explainable machine learning pipelines
|
|
|
|
## Installation
|
|
|
|
### Local installation
|
|
|
|
```bash
|
|
py -m pip install -e .
|
|
|
|
|
|
### Future PyPI installation
|
|
|
|
pip install spectralforensics
|
|
|
|
|
|
## Quick Start
|
|
|
|
### Extract Features from a Single Image
|
|
|
|
```python
|
|
from spectralforensics import extract_spectral_features
|
|
|
|
features = extract_spectral_features("image.jpg")
|
|
|
|
print(features)
|
|
```
|
|
|
|
### Example Output
|
|
|
|
```python
|
|
{
|
|
"filename": "image.jpg",
|
|
"spectral_entropy": 2.31,
|
|
"anisotropy": 0.021,
|
|
"dominant_frequency": 12.7,
|
|
"energy_density": 58210.3,
|
|
"high_frequency_ratio": 0.000091,
|
|
"mean_energy": 58210.3
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
### Extract Features from an Entire Folder
|
|
|
|
```python
|
|
from spectralforensics import extract_features_from_folder
|
|
|
|
df = extract_features_from_folder(
|
|
folder_path="dataset",
|
|
output_csv="results.csv"
|
|
)
|
|
|
|
print(df.head())
|
|
```
|
|
|
|
### Example Output
|
|
|
|
| filename | spectral_entropy | anisotropy | dominant_frequency | energy_density | high_frequency_ratio |
|
|
|-----------|----------------|------------|-------------------|----------------|---------------------|
|
|
| real_001.jpg | 1.21 | 0.012 | 11.0 | 91327 | 0.000037 |
|
|
| dalle_001.png | 2.50 | 0.034 | 16.0 | 68150 | 0.000177 |
|
|
| flux_001.jpg | 2.51 | 0.019 | 6.0 | 61004 | 0.000064 |
|