Filters API
Pictologics provides IBSI 2-compliant convolutional filters for image response map generation.
Overview
All filters can be used via the RadiomicsPipeline filter step or called directly:
# Pipeline usage
{"step": "filter", "params": {"type": "log", "sigma_mm": 1.5}}
# Direct usage
from pictologics.filters import laplacian_of_gaussian, BoundaryCondition
response = laplacian_of_gaussian(image.array, sigma_mm=1.5, spacing_mm=image.spacing)
Available Filters
| Filter | Function | Use Case |
|---|---|---|
| Mean | mean_filter |
Local averaging |
| LoG | laplacian_of_gaussian |
Edge/blob detection |
| Laws | laws_filter |
Texture energy |
| Gabor | gabor_filter |
Directional patterns |
| Wavelet | wavelet_transform |
Multi-resolution analysis |
| Simoncelli | simoncelli_wavelet |
Non-separable wavelet |
| Riesz | riesz_transform, riesz_log, riesz_simoncelli |
Rotation-equivariant transforms |
Boundary Conditions
pictologics.filters.BoundaryCondition
Bases: Enum
IBSI 2 boundary conditions for image padding (GBYQ).
Maps to scipy.ndimage mode parameter values.
Source code in pictologics/filters/base.py
pictologics.filters.FilterResult
dataclass
Container for filter response maps and metadata.
Source code in pictologics/filters/base.py
dtype
property
Data type of the response map.
shape
property
Shape of the response map.
pictologics.filters.LAWS_KERNELS = _LAWS_KERNELS
module-attribute
Dictionary of normalized Laws kernels (IBSI 2 Table 6).
Filter Functions
pictologics.filters.mean_filter(image, support=15, boundary=BoundaryCondition.ZERO, source_mask=None)
Apply 3D mean filter (IBSI code: S60F).
The mean filter computes the average intensity over an M×M×M spatial support. Per IBSI 2 Eq. 2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
NDArray[floating[Any]]
|
3D input image array |
required |
support
|
int
|
Filter support M in voxels (must be odd, YNOF) |
15
|
boundary
|
Union[BoundaryCondition, str]
|
Boundary condition for padding (GBYQ) |
ZERO
|
source_mask
|
Optional[NDArray[bool_]]
|
Optional boolean mask where True = valid voxel. When provided, uses normalized convolution to exclude invalid (sentinel) voxels from mean computation. |
None
|
Returns:
| Type | Description |
|---|---|
Union[NDArray[floating[Any]], tuple[NDArray[floating[Any]], NDArray[bool_]]]
|
If source_mask is None: Response map with same dimensions as input |
Union[NDArray[floating[Any]], tuple[NDArray[floating[Any]], NDArray[bool_]]]
|
If source_mask provided: Tuple of (response_map, output_valid_mask) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If support is not an odd positive integer |
Example
Apply Mean filter with 15-voxel support:
import numpy as np
from pictologics.filters import mean_filter
# Create dummy 3D image
image = np.random.rand(50, 50, 50)
# Apply filter (original API)
response = mean_filter(image, support=15, boundary="zero")
# With source_mask for sentinel exclusion
mask = image > -1000 # Valid voxels
response, valid_mask = mean_filter(image, support=15, source_mask=mask)
Note
Support M is defined in voxel units as per IBSI specification.
Source code in pictologics/filters/mean.py
pictologics.filters.laplacian_of_gaussian(image, sigma_mm, spacing_mm=1.0, truncate=4.0, boundary=BoundaryCondition.ZERO, source_mask=None)
laplacian_of_gaussian(
image: npt.NDArray[np.floating[Any]],
sigma_mm: float,
spacing_mm: Union[
float, Tuple[float, float, float]
] = ...,
truncate: float = ...,
boundary: Union[BoundaryCondition, str] = ...,
source_mask: None = ...,
) -> npt.NDArray[np.floating[Any]]
laplacian_of_gaussian(
image: npt.NDArray[np.floating[Any]],
sigma_mm: float,
spacing_mm: Union[
float, Tuple[float, float, float]
] = ...,
truncate: float = ...,
boundary: Union[BoundaryCondition, str] = ...,
source_mask: npt.NDArray[np.bool_] = ...,
) -> tuple[
npt.NDArray[np.floating[Any]], npt.NDArray[np.bool_]
]
Apply 3D Laplacian of Gaussian filter (IBSI code: L6PA).
The LoG is a band-pass, spherically symmetric operator. Per IBSI 2 Eq. 3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
NDArray[floating[Any]]
|
3D input image array |
required |
sigma_mm
|
float
|
Standard deviation in mm (σ*, 41LN) |
required |
spacing_mm
|
Union[float, Tuple[float, float, float]]
|
Voxel spacing in mm (scalar for isotropic, or tuple) |
1.0
|
truncate
|
float
|
Filter size cutoff in σ units (default 4.0, WGPM) |
4.0
|
boundary
|
Union[BoundaryCondition, str]
|
Boundary condition for padding (GBYQ) |
ZERO
|
source_mask
|
Optional[NDArray[bool_]]
|
Optional boolean mask where True = valid voxel. When provided, uses normalized convolution to exclude invalid (sentinel) voxels from computation. |
None
|
Returns:
| Type | Description |
|---|---|
Union[NDArray[floating[Any]], tuple[NDArray[floating[Any]], NDArray[bool_]]]
|
If source_mask is None: Response map with same dimensions as input |
Union[NDArray[floating[Any]], tuple[NDArray[floating[Any]], NDArray[bool_]]]
|
If source_mask provided: Tuple of (response_map, output_valid_mask) |
Example
Apply LoG filter with 5.0mm sigma on an image with 2.0mm spacing:
import numpy as np
from pictologics.filters import laplacian_of_gaussian
# Create dummy 3D image
image = np.random.rand(50, 50, 50)
# Apply filter (original API)
response = laplacian_of_gaussian(
image,
sigma_mm=5.0,
spacing_mm=(2.0, 2.0, 2.0),
truncate=4.0
)
# With source_mask for sentinel exclusion
mask = image > -1000
response, valid_mask = laplacian_of_gaussian(
image, sigma_mm=5.0, spacing_mm=2.0, source_mask=mask
)
Note
- σ is converted from mm to voxels: σ_voxels = σ_mm / spacing_mm
- Filter size: M = 1 + 2⌊d×σ + 0.5⌋ where d=truncate
- The kernel should sum to approximately 0 (zero-mean)
Source code in pictologics/filters/log.py
pictologics.filters.laws_filter(image, kernels, boundary=BoundaryCondition.ZERO, rotation_invariant=False, pooling='max', compute_energy=False, energy_distance=7, use_parallel=None, source_mask=None)
laws_filter(
image: npt.NDArray[np.floating[Any]],
kernels: str,
boundary: Union[BoundaryCondition, str] = ...,
rotation_invariant: bool = ...,
pooling: str = ...,
compute_energy: bool = ...,
energy_distance: int = ...,
use_parallel: Union[bool, None] = ...,
source_mask: None = ...,
) -> npt.NDArray[np.floating[Any]]
laws_filter(
image: npt.NDArray[np.floating[Any]],
kernels: str,
boundary: Union[BoundaryCondition, str] = ...,
rotation_invariant: bool = ...,
pooling: str = ...,
compute_energy: bool = ...,
energy_distance: int = ...,
use_parallel: Union[bool, None] = ...,
source_mask: npt.NDArray[np.bool_] = ...,
) -> Tuple[
npt.NDArray[np.floating[Any]], npt.NDArray[np.bool_]
]
Apply 3D Laws kernel filter (IBSI code: JTXT).
Laws kernels detect texture patterns via separable 1D filters combined into 2D/3D filters via outer products.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
NDArray[floating[Any]]
|
3D input image array |
required |
kernels
|
str
|
Kernel specification as string, e.g., "E5L5S5" for 3D |
required |
boundary
|
Union[BoundaryCondition, str]
|
Boundary condition for padding (GBYQ) |
ZERO
|
rotation_invariant
|
bool
|
If True, apply pseudo-rotational invariance (O1AQ) using max pooling over 24 right-angle rotations |
False
|
pooling
|
str
|
Pooling method for rotation invariance ("max", "average", "min") |
'max'
|
compute_energy
|
bool
|
If True, compute texture energy image (PQSD) |
False
|
energy_distance
|
int
|
Chebyshev distance δ for energy computation (I176) |
7
|
use_parallel
|
Union[bool, None]
|
If True, use parallel processing for rotation_invariant mode. If None (default), auto-enables for images > ~128³ voxels. Only affects rotation_invariant mode. |
None
|
source_mask
|
Optional[NDArray[bool_]]
|
Optional boolean mask where True = valid voxel. When provided, uses normalized separable convolution to exclude invalid (sentinel) voxels from computation. Only supported in non-rotation-invariant mode. |
None
|
Returns:
| Type | Description |
|---|---|
Union[NDArray[floating[Any]], Tuple[NDArray[floating[Any]], NDArray[bool_]]]
|
If source_mask is None: Response map (or energy image if compute_energy=True) |
Union[NDArray[floating[Any]], Tuple[NDArray[floating[Any]], NDArray[bool_]]]
|
If source_mask provided: Tuple of (response_map, output_valid_mask) |
Example
Apply Laws E5L5S5 kernel with rotation invariance and texture energy:
Note
- Kernels are normalized (deviate from Laws' original unnormalized)
- Energy is computed as: mean(|h|) over δ neighborhood
- For rotation invariance, energy is computed after pooling
- Uses separable 1D convolutions for ~8x speedup over full 3D
Source code in pictologics/filters/laws.py
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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
pictologics.filters.gabor_filter(image, sigma_mm, lambda_mm, gamma=1.0, theta=0.0, spacing_mm=1.0, boundary=BoundaryCondition.ZERO, rotation_invariant=False, delta_theta=None, pooling='average', average_over_planes=False, use_parallel=None, source_mask=None)
Apply 2D Gabor filter to 3D image (IBSI code: Q88H).
The Gabor filter is applied in the axial plane (k1, k2) and optionally averaged over orthogonal planes. Per IBSI 2 Eq. 9.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
NDArray[floating[Any]]
|
3D input image array |
required |
sigma_mm
|
float
|
Standard deviation of Gaussian envelope in mm (41LN) |
required |
lambda_mm
|
float
|
Wavelength in mm (S4N6) |
required |
gamma
|
float
|
Spatial aspect ratio (GDR5), typically 0.5 to 2.0 |
1.0
|
theta
|
float
|
Orientation angle in radians (FQER), clockwise in (k1,k2) |
0.0
|
spacing_mm
|
Union[float, Tuple[float, float, float]]
|
Voxel spacing in mm (scalar or tuple) |
1.0
|
boundary
|
Union[BoundaryCondition, str]
|
Boundary condition for padding (GBYQ) |
ZERO
|
rotation_invariant
|
bool
|
If True, average over orientations |
False
|
delta_theta
|
Optional[float]
|
Orientation step for rotation invariance (XTGK) |
None
|
pooling
|
str
|
Pooling method ("average", "max", "min") |
'average'
|
average_over_planes
|
bool
|
If True, average 2D responses over 3 orthogonal planes |
False
|
use_parallel
|
Union[bool, None]
|
If True, process slices in parallel. If None (default), auto-enables for images > ~80³ voxels. |
None
|
source_mask
|
Optional[NDArray[bool_]]
|
Optional boolean mask where True = valid voxel. When provided, zeros out invalid (sentinel) voxels before FFT-based convolution to prevent contamination. |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[floating[Any]]
|
Response map (modulus of complex response) |
Example
Apply Gabor filter with rotation invariance over orthogonal planes:
Note
- Returns modulus |h| = |g ⊗ f| for feature extraction
- 2D filter applied slice-by-slice, then optionally over planes
- Uses single complex FFT convolution for ~2x speedup
Source code in pictologics/filters/gabor.py
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 | |
pictologics.filters.wavelet_transform(image, wavelet='db2', level=1, decomposition='LHL', boundary=BoundaryCondition.ZERO, rotation_invariant=False, pooling='average', use_parallel=None, source_mask=None)
Apply 3D separable wavelet transform (undecimated/stationary).
Uses the à trous algorithm for undecimated wavelet decomposition. The transform is translation-invariant (unlike decimated transform).
Supported wavelets
- "haar" (UOUE): Haar wavelet
- "db2", "db3": Daubechies wavelets
- "coif1": Coiflet wavelet
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
NDArray[floating[Any]]
|
3D input image array |
required |
wavelet
|
str
|
Wavelet name (e.g., "db2", "coif1", "haar") |
'db2'
|
level
|
int
|
Decomposition level (GCEK) |
1
|
decomposition
|
str
|
Which response map to return, e.g., "LHL", "HHH" |
'LHL'
|
boundary
|
Union[BoundaryCondition, str]
|
Boundary condition for padding |
ZERO
|
rotation_invariant
|
bool
|
If True, average over 24 rotations |
False
|
pooling
|
str
|
Pooling method for rotation invariance |
'average'
|
use_parallel
|
Union[bool, None]
|
If True, use parallel processing for rotation_invariant mode. If None (default), auto-enables for images > ~128³ voxels. |
None
|
source_mask
|
Optional[NDArray[bool_]]
|
Optional boolean mask where True = valid voxel. When provided, zeros out invalid (sentinel) voxels before wavelet decomposition to prevent contamination. |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[floating[Any]]
|
Response map for the specified decomposition |
Example
Apply Daubechies 2 wavelet transform at level 1, returning LHL coefficients:
Source code in pictologics/filters/wavelets.py
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 | |
pictologics.filters.simoncelli_wavelet(image, level=1, boundary=BoundaryCondition.PERIODIC, source_mask=None)
Apply Simoncelli non-separable wavelet (IBSI code: PRT7).
The Simoncelli wavelet is isotropic (spherically symmetric) and implemented in the Fourier domain. Per IBSI 2 Eq. 27.
For decomposition level N, the frequency band is scaled by j = N-1: - Level 1 (j=0): band [π/4, π] (highest frequencies) - Level 2 (j=1): band [π/8, π/2] - Level 3 (j=2): band [π/16, π/4]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
NDArray[floating[Any]]
|
3D input image array |
required |
level
|
int
|
Decomposition level (1 = highest frequency band) |
1
|
boundary
|
Union[BoundaryCondition, str]
|
Boundary condition (FFT is inherently periodic) |
PERIODIC
|
source_mask
|
Optional[NDArray[bool_]]
|
Optional boolean mask where True = valid voxel |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[floating[Any]]
|
Band-pass response map (B map) for the specified level |
Example
Apply first-level Simoncelli wavelet (highest frequency band):
Source code in pictologics/filters/wavelets.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
pictologics.filters.riesz_transform(image, order, source_mask=None)
Apply Riesz transform (IBSI code: AYRS).
The Riesz transform computes higher-order all-pass image derivatives in the Fourier domain. Per IBSI 2 Eq. 34.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
NDArray[floating[Any]]
|
3D input image array |
required |
order
|
Tuple[int, ...]
|
Tuple (l1, l2, l3) specifying derivative order per axis e.g., (1,0,0) = first-order along k1 (gradient-like) (2,0,0), (1,1,0), (0,2,0) = second-order (Hessian-like) |
required |
source_mask
|
Optional[NDArray[bool_]]
|
Optional boolean mask where True = valid voxel. When provided, zeros out invalid (sentinel) voxels before FFT-based transform to prevent contamination. |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[floating[Any]]
|
Riesz-transformed image (real part) |
Example
Compute first-order Riesz transform along the k1 axis:
Note
- First-order Riesz components form the image gradient
- Second-order Riesz components form the image Hessian
- All-pass: doesn't amplify high frequencies like regular derivatives
Source code in pictologics/filters/riesz.py
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 | |
pictologics.filters.riesz_log(image, sigma_mm, spacing_mm=1.0, order=(1, 0, 0), truncate=4.0, source_mask=None)
Apply Riesz transform to LoG-filtered image.
Combines multi-scale analysis (LoG) with directional analysis (Riesz). First applies LoG filtering, then applies Riesz transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
NDArray[floating[Any]]
|
3D input image array |
required |
sigma_mm
|
float
|
LoG scale in mm |
required |
spacing_mm
|
Union[float, Tuple[float, float, float]]
|
Voxel spacing in mm |
1.0
|
order
|
Tuple[int, ...]
|
Riesz order tuple (l1, l2, l3) |
(1, 0, 0)
|
truncate
|
float
|
LoG truncation parameter |
4.0
|
source_mask
|
Optional[NDArray[bool_]]
|
Optional boolean mask where True = valid voxel |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[floating[Any]]
|
Riesz-transformed LoG response |
Example
Compute first-order Riesz transform of LoG-filtered image at 5mm scale:
Source code in pictologics/filters/riesz.py
pictologics.filters.riesz_simoncelli(image, level=1, order=(1, 0, 0), source_mask=None)
Apply Riesz transform to Simoncelli wavelet-filtered image.
Combines isotropic multi-scale analysis (Simoncelli) with directional analysis (Riesz) for rotation-invariant directional features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
NDArray[floating[Any]]
|
3D input image array |
required |
level
|
int
|
Simoncelli decomposition level |
1
|
order
|
Tuple[int, ...]
|
Riesz order tuple (l1, l2, l3) |
(1, 0, 0)
|
source_mask
|
Optional[NDArray[bool_]]
|
Optional boolean mask where True = valid voxel |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[floating[Any]]
|
Riesz-transformed Simoncelli response |
Example
Compute second-order Riesz transform (Hessian-like) of Simoncelli level 2: