Image Signals API¶
FrequencySignal
¶
Bases: BaseSignal
Detects AI images using frequency domain analysis (FFT).
AI-generated images often exhibit specific artifacts in the frequency domain, such as regular grid-like patterns (checkerboard artifacts) from upsampling layers or anomalous power distributions compared to natural images.
This signal computes the Fourier Transform of the image and extracts features like: - Mean frequency magnitude - High-frequency energy ratio - Variance of the Laplacian (sharpness/texture)
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
'frequency_artifacts' |
dtype |
str
|
'image' |
Source code in veridex/image/frequency.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
run(input_data)
¶
Input data should be a path to an image or a numpy array/PIL Image. For simplicity, we assume input_data is a file path or a PIL Image.
Source code in veridex/image/frequency.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
DIRESignal
¶
Bases: BaseSignal
Detects AI images using Diffusion Reconstruction Error (DIRE).
Based on the hypothesis that diffusion models can reconstruct images they generated (or similar ones) more accurately than real natural images.
Methodology
- Take input image I.
- Add noise to obtain I_noisy (simulating diffusion forward step).
- Denoise I_noisy using a pre-trained diffusion model to get I_rec.
- Calculate Reconstruction Error = |I - I_rec|.
- Low Error -> Likely AI (on the model's manifold).
- High Error -> Likely Real (harder to reconstruct).
Note
This is a simplified approximation using Image-to-Image translation with low strength as a proxy for the full DDIM inversion process described in the original paper.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
'dire_reconstruction' |
dtype |
str
|
'image' |
model_id |
str
|
HuggingFace Diffusion model ID. |
Source code in veridex/image/dire.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
__init__(model_id='runwayml/stable-diffusion-v1-5', device='cpu')
¶
Initialize the DIRE signal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The Stable Diffusion model to use for reconstruction. |
'runwayml/stable-diffusion-v1-5'
|
device
|
str
|
Computation device ('cpu' or 'cuda'). |
'cpu'
|
Source code in veridex/image/dire.py
CLIPSignal
¶
Bases: BaseSignal
Detects AI images using CLIP (Contrastive Language-Image Pre-Training) Zero-Shot Classification.
Based on the research "Towards Universal Fake Image Detectors that Generalize Across Generative Models" (UnivFD) and "Raising the Bar of AI-generated Image Detection with CLIP".
Methodology
- Encodes the input image using a pre-trained CLIP vision encoder.
- Encodes a set of text prompts representing "Real" and "Fake" classes.
- Computes cosine similarity between the image embedding and text embeddings.
- Returns the probability of the "Fake" class (softmax of similarities).
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
'clip_zeroshot' |
dtype |
str
|
'image' |
model_id |
str
|
HuggingFace CLIP model ID (default: "openai/clip-vit-base-patch32"). |
Source code in veridex/image/clip.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
__init__(model_id='openai/clip-vit-base-patch32', device='cpu', real_prompts=None, fake_prompts=None)
¶
Initialize the CLIP signal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The CLIP model to use. |
'openai/clip-vit-base-patch32'
|
device
|
str
|
Computation device ('cpu' or 'cuda'). |
'cpu'
|
real_prompts
|
List[str]
|
Custom prompts for the 'Real' class. |
None
|
fake_prompts
|
List[str]
|
Custom prompts for the 'Fake' class. |
None
|
Source code in veridex/image/clip.py
MLEPSignal
¶
Bases: BaseSignal
Detects AI images using Multi-granularity Local Entropy Patterns (MLEP).
Based on the research "MLEP: Multi-granularity Local Entropy Patterns for Universal AI-generated Image Detection" (Paper 3).
Hypothesis
Synthetic images often exhibit different local entropy characteristics compared to natural images, particularly in high-frequency regions or at specific scales, due to the generative upsampling process.
Methodology
- Convert image to grayscale.
- Calculate local entropy map (using a neighborhood kernel, e.g., disk).
- Extract statistical features from the entropy map (e.g., mean, variance, skewness).
- (Ideally) Pass features to a classifier.
- (Heuristic fallback) Return a score based on entropy anomalies. Paper suggests AI images might have lower local entropy complexity in textures.
Note: Without a trained SVM/RF classifier on a large dataset, this signal acts as a statistical feature extractor. We provide a heuristic score for demonstration, where Extreme Entropy (very low or very high) is penalized/flagged.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
'mlep_entropy' |
dtype |
str
|
'image' |
Source code in veridex/image/mlep.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |