Skip to content

Commit 380f042

Browse files
authored
1680 Add squeeze SegmentationSaver handler (#1686)
* [DLMED] add suqeeze to handler Signed-off-by: Nic Ma <[email protected]> * [DLMED] update according to comments Signed-off-by: Nic Ma <[email protected]>
1 parent ac9f953 commit 380f042

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

monai/handlers/segmentation_saver.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def __init__(
4141
scale: Optional[int] = None,
4242
dtype: DtypeLike = np.float64,
4343
output_dtype: DtypeLike = np.float32,
44+
squeeze_end_dims: bool = True,
4445
batch_transform: Callable = lambda x: x,
4546
output_transform: Callable = lambda x: x,
4647
name: Optional[str] = None,
@@ -77,6 +78,11 @@ def __init__(
7778
If None, use the data type of input data.
7879
It's used for Nifti format only.
7980
output_dtype: data type for saving data. Defaults to ``np.float32``, it's used for Nifti format only.
81+
squeeze_end_dims: if True, any trailing singleton dimensions will be removed (after the channel
82+
has been moved to the end). So if input is (C,H,W,D), this will be altered to (H,W,D,C), and
83+
then if C==1, it will be saved as (H,W,D). If D also ==1, it will be saved as (H,W). If false,
84+
image will always be saved as (H,W,D,C).
85+
it's used for NIfTI format only.
8086
batch_transform: a callable that is used to transform the
8187
ignite.engine.batch into expected format to extract the meta_data dictionary.
8288
output_transform: a callable that is used to transform the
@@ -96,6 +102,7 @@ def __init__(
96102
scale=scale,
97103
dtype=dtype,
98104
output_dtype=output_dtype,
105+
squeeze_end_dims=squeeze_end_dims,
99106
save_batch=True,
100107
)
101108
self.batch_transform = batch_transform

monai/transforms/io/array.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ class SaveImage(Transform):
206206
has been moved to the end). So if input is (C,H,W,D), this will be altered to (H,W,D,C), and
207207
then if C==1, it will be saved as (H,W,D). If D also ==1, it will be saved as (H,W). If false,
208208
image will always be saved as (H,W,D,C).
209+
it's used for NIfTI format only.
209210
210211
"""
211212

monai/transforms/io/dictionary.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class SaveImaged(MapTransform):
172172
has been moved to the end). So if input is (C,H,W,D), this will be altered to (H,W,D,C), and
173173
then if C==1, it will be saved as (H,W,D). If D also ==1, it will be saved as (H,W). If false,
174174
image will always be saved as (H,W,D,C).
175+
it's used for NIfTI format only.
175176
176177
"""
177178

0 commit comments

Comments
 (0)