Skip to content

Add segmentation of images in "native image space"#691

Merged
m-reuter merged 5 commits into
Deep-MI:devfrom
dkuegler:feature/native-segmentation
May 16, 2025
Merged

Add segmentation of images in "native image space"#691
m-reuter merged 5 commits into
Deep-MI:devfrom
dkuegler:feature/native-segmentation

Conversation

@dkuegler
Copy link
Copy Markdown
Member

@dkuegler dkuegler commented May 8, 2025

Add segmentation of images in "native image space".

This adds the --native_image flag to run_fastsurfer.sh and multiple more fine-grained flags to conform.py and the various run_predicions.pys for more fine control over the 3 components of the image space: "orientation", "voxel size" and "image size".

--orientation

For conform.py, this commit implements additional options for orientation in addition to the previous "lia" which is default and required for downstream surface reconstruction with FreeSurfer binaries.
--orientation "XXX" e.g. "lia" -- reformat the affine so it is always aligned along the primary axes, for example [-X 0 0, 0 0 -X, 0 X 0] with X the voxel size for "lia",
--orientation "soft-XXX", e.g. "soft-lia" -- reformat the affine so the primary directions as above, but axes might not be perfectly aligned. For this, DOES NOT -- by itself -- trigger an interpolate the image.
-- orientation "native" -- do not reformat the affine, keep it as is.

There is a second change to native images done by conform, changing the image dimensions so all dimensions in all directions are the same (e.g. 256 for 1mm voxelsize images), but this number is different for highres images.
This behavior is still the default behavior (explicitly also --image_size "auto").
However, as this will also change the native image dimensions for segmentation, additional options are available:
--image_size "auto": as before/above
--image_size int: directly force a specific image dimension, e.g. 256.
--image_size "fov": keep the field of view consistent, i.e. if the voxel size is not touched, keep the image size the same, or -- if the voxel size is changed via --vox_size -- set the image size such that the field of view -- the region we have data for -- stays consistent.

Changes to files:
conform.py and its functions are heavily restructured to optimally support these features.
run_prediction and run_fastsurfer get --orientation and --image_size flags (run_fastsurfer also gets the --keepgeom flag: alias for --orientation native --image_size fov)
add and consistently use function to change data orientations
add documentation for new flags

Comment thread FastSurferCNN/data_loader/conform.py Outdated
Comment thread FastSurferCNN/data_loader/conform.py Outdated
Comment thread FastSurferCNN/data_loader/conform.py Outdated
Comment thread FastSurferCNN/data_loader/conform.py Outdated
Comment thread FastSurferCNN/data_loader/conform.py Outdated
Comment thread FastSurferCNN/utils/parser_defaults.py Outdated
Comment thread doc/overview/FLAGS.md Outdated
Comment thread doc/overview/FLAGS.md Outdated
dkuegler added 3 commits May 15, 2025 14:25
…2 components:

1. no image rotation (affine matrix stays the same, covered by the --orientation flag) and
2. no change of image dimensions (covered by the --image_size flag).

This commit implements 2 versions for orientation in addition to the previous "lia" which is default and required for downstream surface reconstruction with FreeSurfer binaries.
--orientation "lia" -- reformat the affine so it is always [-X 0 0, 0 0 -X, 0 X 0] with X the voxel size,
--orientation "soft lia" (or "soft-lia") -- reformat the affine so the primary directions as above, but axes might not be perfectly aligned. For this, DO NOT interpolate the image.
-- orientation "native" -- do not reformat the affine, keep it as is.

There is a second change to native images done by conform, changing the image dimensions so all dimensions in all directions are the same (e.g. 256 for 1mm voxelsize images), but this number is different for highres images.
This behavior is still the default behavior (explicitly also --image_size "auto").
However, as this will also change the native image dimensions for segmentation, additional options are available:
--image_size "auto": as before/above
--image_size int: directly force a specific image dimension, e.g. 256.
--image_size "fov": keep the field of view consistent, i.e. if the voxel size is not touched, keep the image size the same, or -- if the voxel size is changed via --vox_size -- set the image size such that the field of view -- the region we have data for -- stays consistent.

Changes to files:
conform.py and its functions are heavily restructured to optimally support these features.
run_prediction and run_fastsurfer get --orientation and --image_size flags (run_fastsurfer also gets the --keepgeom flag: alias for --orientation native --image_size fov)
add and consistently use function to change data orientations
add documentation for new flags
@dkuegler dkuegler force-pushed the feature/native-segmentation branch from 3388bb3 to a32f1de Compare May 15, 2025 17:19
@dkuegler
Copy link
Copy Markdown
Member Author

I think this should fix everything, but I will run a final check for non-isotropic images tomorrow.

Comment thread FastSurferCNN/run_prediction.py
Comment thread doc/overview/FLAGS.md Outdated
* `--no_biasfield`: Deactivate the biasfield correction and calculation of partial volume-corrected statistics in the segmentation modules.
* `--orientation`: **Only supported for `--seg_only`**, select the image orientation (`lia` (default), `soft lia` or `soft-lia` -- orient to LIA orientation, but do not interpolate, `native` -- segment in the native image space).
* `--image_size`: Select the target image size (a number to use, `fov` to set the image size to the input field of view (**allows non-cube images, only supported for `--seg_only`**), or `auto` (default) expands the image so all three image dimensions are the same).
* `--keepgeom`: **Only supported for `--seg_only`**, segment in native image space (both orientation and image size), same as `--orientation native --image_size fov`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in documentation we should use native_image as it is easier to understand.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually forgot to change this here. --orientation and --image_size no longer supported, just --keepgeom and --native_image.

Comment thread run_fastsurfer.sh Outdated
Comment thread FastSurferCNN/data_loader/conform.py Outdated
type=__img_size,
help="Specifies the image size to conform to. Options: <int> (dimension of the target image), 'auto' "
"(determine dimensions of image from largest field-of-view dimension, min. 256), 'fov' (determine "
"dims. of image from field of view, dims. may be differ) or 'any' (ignore this criteria, similar to fov).",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not toally clear here what the difference between auto and fov is. maybe auto is always a cube ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"auto" is basically fov but expanded to a cube, "fov" keeps the original field of view

@dkuegler dkuegler force-pushed the feature/native-segmentation branch from c077a12 to e56093d Compare May 16, 2025 10:28
@m-reuter m-reuter merged commit 614eb6d into Deep-MI:dev May 16, 2025
3 checks passed
@dkuegler dkuegler deleted the feature/native-segmentation branch May 16, 2025 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants