monai-weekly 1.4.dev2440__py3-none-any.whl → 1.4.dev2441__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
monai/__init__.py CHANGED
@@ -136,4 +136,4 @@ except BaseException:
136
136
 
137
137
  if MONAIEnvVars.debug():
138
138
  raise
139
- __commit_id__ = "76ef9f40c8da626928238c91eacddc789b0b4530"
139
+ __commit_id__ = "796271ccd4ee48065af3b2afd56bf46960a53112"
monai/_version.py CHANGED
@@ -8,11 +8,11 @@ import json
8
8
 
9
9
  version_json = '''
10
10
  {
11
- "date": "2024-10-06T02:29:02+0000",
11
+ "date": "2024-10-13T02:28:40+0000",
12
12
  "dirty": false,
13
13
  "error": null,
14
- "full-revisionid": "c2bfe29203f3a82b689d3f1d5334e484f6fbb1a6",
15
- "version": "1.4.dev2440"
14
+ "full-revisionid": "cf815ed4e44a5b8ce67e894ab0bc2765279a1a59",
15
+ "version": "1.4.dev2441"
16
16
  }
17
17
  ''' # END VERSION_JSON
18
18
 
@@ -803,6 +803,14 @@ class RestoreLabeld(MapTransform):
803
803
  original_shape_key: key that records original shape for foreground.
804
804
  cropped_shape_key: key that records cropped shape for foreground.
805
805
  allow_missing_keys: don't raise exception if key is missing.
806
+ restore_resizing: used to enable or disable resizing restoration, default is True.
807
+ If True, the transform will resize the items back to its original shape.
808
+ restore_cropping: used to enable or disable cropping restoration, default is True.
809
+ If True, the transform will restore the items to its uncropped size.
810
+ restore_spacing: used to enable or disable spacing restoration, default is True.
811
+ If True, the transform will resample the items back to the spacing it had before being altered.
812
+ restore_slicing: used to enable or disable slicing restoration, default is True.
813
+ If True, the transform will reassemble the full volume by restoring the slices to their original positions.
806
814
  """
807
815
 
808
816
  def __init__(
@@ -819,6 +827,10 @@ class RestoreLabeld(MapTransform):
819
827
  original_shape_key: str = "foreground_original_shape",
820
828
  cropped_shape_key: str = "foreground_cropped_shape",
821
829
  allow_missing_keys: bool = False,
830
+ restore_resizing: bool = True,
831
+ restore_cropping: bool = True,
832
+ restore_spacing: bool = True,
833
+ restore_slicing: bool = True,
822
834
  ) -> None:
823
835
  super().__init__(keys, allow_missing_keys)
824
836
  self.ref_image = ref_image
@@ -833,6 +845,10 @@ class RestoreLabeld(MapTransform):
833
845
  self.end_coord_key = end_coord_key
834
846
  self.original_shape_key = original_shape_key
835
847
  self.cropped_shape_key = cropped_shape_key
848
+ self.restore_resizing = restore_resizing
849
+ self.restore_cropping = restore_cropping
850
+ self.restore_spacing = restore_spacing
851
+ self.restore_slicing = restore_slicing
836
852
 
837
853
  def __call__(self, data: Any) -> dict:
838
854
  d = dict(data)
@@ -842,38 +858,45 @@ class RestoreLabeld(MapTransform):
842
858
  image = d[key]
843
859
 
844
860
  # Undo Resize
845
- current_shape = image.shape
846
- cropped_shape = meta_dict[self.cropped_shape_key]
847
- if np.any(np.not_equal(current_shape, cropped_shape)):
848
- resizer = Resize(spatial_size=cropped_shape[1:], mode=mode)
849
- image = resizer(image, mode=mode, align_corners=align_corners)
861
+ if self.restore_resizing:
862
+ current_shape = image.shape
863
+ cropped_shape = meta_dict[self.cropped_shape_key]
864
+ if np.any(np.not_equal(current_shape, cropped_shape)):
865
+ resizer = Resize(spatial_size=cropped_shape[1:], mode=mode)
866
+ image = resizer(image, mode=mode, align_corners=align_corners)
850
867
 
851
868
  # Undo Crop
852
- original_shape = meta_dict[self.original_shape_key]
853
- result = np.zeros(original_shape, dtype=np.float32)
854
- box_start = meta_dict[self.start_coord_key]
855
- box_end = meta_dict[self.end_coord_key]
856
-
857
- spatial_dims = min(len(box_start), len(image.shape[1:]))
858
- slices = tuple(
859
- [slice(None)] + [slice(s, e) for s, e in zip(box_start[:spatial_dims], box_end[:spatial_dims])]
860
- )
861
- result[slices] = image
869
+ if self.restore_cropping:
870
+ original_shape = meta_dict[self.original_shape_key]
871
+ result = np.zeros(original_shape, dtype=np.float32)
872
+ box_start = meta_dict[self.start_coord_key]
873
+ box_end = meta_dict[self.end_coord_key]
874
+
875
+ spatial_dims = min(len(box_start), len(image.shape[1:]))
876
+ slices = tuple(
877
+ [slice(None)] + [slice(s, e) for s, e in zip(box_start[:spatial_dims], box_end[:spatial_dims])]
878
+ )
879
+ result[slices] = image
880
+ else:
881
+ result = image
862
882
 
863
883
  # Undo Spacing
864
- current_size = result.shape[1:]
865
- # change spatial_shape from HWD to DHW
866
- spatial_shape = list(np.roll(meta_dict["spatial_shape"], 1))
867
- spatial_size = spatial_shape[-len(current_size) :]
884
+ if self.restore_spacing:
885
+ current_size = result.shape[1:]
886
+ # change spatial_shape from HWD to DHW
887
+ spatial_shape = list(np.roll(meta_dict["spatial_shape"], 1))
888
+ spatial_size = spatial_shape[-len(current_size) :]
868
889
 
869
- if np.any(np.not_equal(current_size, spatial_size)):
870
- resizer = Resize(spatial_size=spatial_size, mode=mode)
871
- result = resizer(result, mode=mode, align_corners=align_corners) # type: ignore
890
+ if np.any(np.not_equal(current_size, spatial_size)):
891
+ resizer = Resize(spatial_size=spatial_size, mode=mode)
892
+ result = resizer(result, mode=mode, align_corners=align_corners) # type: ignore
872
893
 
873
894
  # Undo Slicing
874
895
  slice_idx = meta_dict.get("slice_idx")
875
896
  final_result: NdarrayOrTensor
876
- if slice_idx is None or self.slice_only:
897
+ if not self.restore_slicing: # do nothing if restore slicing isn't requested
898
+ final_result = result
899
+ elif slice_idx is None or self.slice_only:
877
900
  final_result = result if len(result.shape) <= 3 else result[0]
878
901
  else:
879
902
  slice_idx = meta_dict["slice_idx"][0]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: monai-weekly
3
- Version: 1.4.dev2440
3
+ Version: 1.4.dev2441
4
4
  Summary: AI Toolkit for Healthcare Imaging
5
5
  Home-page: https://monai.io/
6
6
  Author: MONAI Consortium
@@ -1,5 +1,5 @@
1
- monai/__init__.py,sha256=3xB7PrwYLHggh2WFpNAbzY3MQqA0crXLlS8jNEWtecw,4095
2
- monai/_version.py,sha256=-ga-_qWT6XVACl55eNJjoMaOVXleLJpCWK4Goh4e1BI,503
1
+ monai/__init__.py,sha256=0V-ca1Bt9VxdrUBijK2gfQswTYDXWtBA9PBHIs9oSZ0,4095
2
+ monai/_version.py,sha256=pfNb_sO0WbswtIrF1esHnac1VUqYKHVs5ovDRsLId8w,503
3
3
  monai/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  monai/_extensions/__init__.py,sha256=NEBPreRhQ8H9gVvgrLr_y52_TmqB96u_u4VQmeNT93I,642
5
5
  monai/_extensions/loader.py,sha256=7SiKw36q-nOzH8CRbBurFrz7GM40GCu7rc93Tm8XpnI,3643
@@ -26,7 +26,7 @@ monai/apps/deepedit/transforms.py,sha256=Udj35m10Irek5Gtqo6Hgv6Lt7S6jSo-z0NuyVbs
26
26
  monai/apps/deepgrow/__init__.py,sha256=s9djSd6kvViPnFvMR11Dgd30Lv4oY6FaPJr4ZZJZLq0,573
27
27
  monai/apps/deepgrow/dataset.py,sha256=W0wv1QujA4sZgrAcBS64dl3OBbDBM2cF4RK0fDCQnRU,10054
28
28
  monai/apps/deepgrow/interaction.py,sha256=-smtOl93i_SDEo_Yo8DE5U3FnDrUcdJWeP14nCq5GS4,3748
29
- monai/apps/deepgrow/transforms.py,sha256=MQ3WPGfqagXoN6ySccpPFWOQAcxKOX4VUeQ0Zybx45I,41873
29
+ monai/apps/deepgrow/transforms.py,sha256=RmKMoN4sqhT84ognTJt55t6UtkL_OpkzRcP5VPseSss,43349
30
30
  monai/apps/detection/__init__.py,sha256=s9djSd6kvViPnFvMR11Dgd30Lv4oY6FaPJr4ZZJZLq0,573
31
31
  monai/apps/detection/metrics/__init__.py,sha256=s9djSd6kvViPnFvMR11Dgd30Lv4oY6FaPJr4ZZJZLq0,573
32
32
  monai/apps/detection/metrics/coco.py,sha256=bpF6hAAMKsBNLfat-Fzh0CR-0swDsAAVcwTaZ-lo1_g,26618
@@ -416,8 +416,8 @@ monai/visualize/img2tensorboard.py,sha256=NnMcyfIFqX-jD7TBO3Rn02zt5uug79d_7pIIaV
416
416
  monai/visualize/occlusion_sensitivity.py,sha256=OQHEJLyIhB8zWqQsfKaX-1kvCjWFVYtLfS4dFC0nKFI,18160
417
417
  monai/visualize/utils.py,sha256=B-MhTVs7sQbIqYS3yPnpBwPw2K82rE2PBtGIfpwZtWM,9894
418
418
  monai/visualize/visualizer.py,sha256=qckyaMZCbezYUwE20k5yc-Pb7UozVavMDbrmyQwfYHY,1377
419
- monai_weekly-1.4.dev2440.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
420
- monai_weekly-1.4.dev2440.dist-info/METADATA,sha256=_3k44c2ZfHiPSK9L-fDB3FhQP03fWtqUbjC-G1oa2q4,11172
421
- monai_weekly-1.4.dev2440.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
422
- monai_weekly-1.4.dev2440.dist-info/top_level.txt,sha256=UaNwRzLGORdus41Ip446s3bBfViLkdkDsXDo34J2P44,6
423
- monai_weekly-1.4.dev2440.dist-info/RECORD,,
419
+ monai_weekly-1.4.dev2441.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
420
+ monai_weekly-1.4.dev2441.dist-info/METADATA,sha256=VPKdbi178DBdGodZ-DsfUHOc13tPT-58VDGTFXdV_DE,11172
421
+ monai_weekly-1.4.dev2441.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
422
+ monai_weekly-1.4.dev2441.dist-info/top_level.txt,sha256=UaNwRzLGORdus41Ip446s3bBfViLkdkDsXDo34J2P44,6
423
+ monai_weekly-1.4.dev2441.dist-info/RECORD,,