Transforms#
Transforms are deterministic pre/post-processing steps in
konfai/data/transform.py. They run every time (train / predict / evaluate),
either whole-image at load time (transforms:) or per extracted patch
(patch_transforms:), under a dataset group:
Dataset:
groups_src:
CT:
groups_dest:
CT:
transforms:
Standardize: { } # bare name → konfai.data.transform.Standardize
is_input: true
A transform whose base class is TransformInverse can be run in reverse during
post-processing / reassembly when you pass inverse: true.
Important
A transform that changes the spatial shape must implement transform_shape()
correctly — patch planning depends on an exact prediction. The Shape column
below flags those. Transforms that only change the channel count (OneHot,
Argmax, Sum, …) intentionally do not override it (patching strips the
channel axis first). Inv flags whether a working inverse() exists.
Intensity & normalisation#
Name |
Purpose |
Key args (defaults) |
Shape |
Inv |
|---|---|---|---|---|
|
Clamp intensities to a fixed or data-dependent range. |
|
no |
no |
|
Linear map to |
|
no |
yes |
|
Map |
|
no |
no |
|
Zero-mean / unit-std from cached, given, or mask-derived stats. |
|
no |
yes |
|
SimpleITK histogram match to a reference group. |
|
no |
no |
Geometry & resampling#
Name |
Purpose |
Key args (defaults) |
Shape |
Inv |
|---|---|---|---|---|
|
|
|
yes |
yes |
|
Crop to foreground bounding box; caches the box; updates Origin. |
|
yes |
yes (pads back) |
|
Resample to a target voxel spacing (per-axis |
|
yes |
yes |
|
Resample to a target shape (per-axis |
|
yes |
yes |
|
Warp by stored SimpleITK transforms read from the dataset. |
|
no |
no |
|
Reorient to canonical direction (3-D); updates Origin/Direction. |
|
no |
yes |
|
Permute spatial axes. |
|
yes |
yes |
|
Flip spatial axes. |
|
no |
yes (self-inverse) |
|
|
|
no |
yes |
|
Flatten to 1-D. |
— |
yes |
no |
Labels & masks#
Name |
Purpose |
Key args (defaults) |
Shape |
Inv |
|---|---|---|---|---|
|
Cast dtype; caches original for inverse. |
|
no |
yes |
|
One-hot encode a label map (changes channels). |
|
no† |
yes |
|
|
|
no† |
no |
|
|
|
no |
no |
|
Binarise selected labels (else |
|
no |
no |
|
Remap labels; entries are |
|
no |
no |
|
Set voxels where mask==0 to |
|
no |
no |
|
Binary dilation via max-pool (2D/3D). |
|
no |
no |
|
Sum over |
|
no† |
no |
|
Gradient-magnitude image (or components). |
|
no† |
no |
Ensemble / uncertainty post-processing#
Operate on a stacked [N, …] ensemble axis (prediction post-processing).
Name |
Purpose |
Key args |
Shape |
|---|---|---|---|
|
Aggregate an ensemble stack (mean / median / seg-argmax); writes an |
|
no |
|
Vector magnitude over the trailing axis (drops it). |
— |
yes |
|
Per-voxel variance over N. |
— |
no† |
|
Per-voxel std over N. |
— |
no† |
|
Per-voxel label disagreement across N segmentations. |
|
no† |
|
|
|
no |
Side-effect & advanced#
Name |
Purpose |
|---|---|
|
Records ImageMin/Max/Mean/Std to the attribute cache and returns the tensor unchanged (feeds the perceptual criteria |
|
Marker — a no-op passthrough (a checkpoint hint, not a saver). |
|
Run a nested KonfAI app inference in a spawned subprocess. Needs |
† changes the channel dimension, not spatial — no transform_shape
override needed.
Next steps#
Augmentations — the random, train-time counterpart
Datasets and groups — where transforms sit in a dataset config
Extension points — write your own
Transform(implement__call__andtransform_shape())