Skip to content

Commit 94b40fc

Browse files
committed
Fixes metadata dropping
Fixes metadata-dropping bug by implementing the src/convert_to_dst_type round-trip. Fixes isort error by re-ordering imports in transforms/__init__.py. Signed-off-by: karllandheer <karllandheer@gmail.com>
1 parent 7eb60ca commit 94b40fc

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

monai/transforms/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,12 @@
200200
RandKSpaceSpikeNoised,
201201
RandKSpaceSpikeNoiseD,
202202
RandKSpaceSpikeNoiseDict,
203-
RandRicianNoised,
204-
RandRicianNoiseD,
205-
RandRicianNoiseDict,
206203
RandNonCentralChiNoised,
207204
RandNonCentralChiNoiseD,
208205
RandNonCentralChiNoiseDict,
206+
RandRicianNoised,
207+
RandRicianNoiseD,
208+
RandRicianNoiseDict,
209209
RandScaleIntensityd,
210210
RandScaleIntensityD,
211211
RandScaleIntensityDict,

monai/transforms/intensity/array.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,13 @@ def __call__(self, img: NdarrayOrTensor, randomize: bool = True) -> NdarrayOrTen
252252
"""
253253
Apply the transform to `img`.
254254
"""
255+
src = img
255256
img = convert_to_tensor(img, track_meta=get_track_meta(), dtype=self.dtype)
256257
if randomize:
257258
super().randomize(None)
258259

259260
if not self._do_transform:
261+
img, *_ = convert_to_dst_type(img, dst=src, dtype=self.dtype)
260262
return img
261263

262264
if self.channel_wise:
@@ -278,10 +280,18 @@ def __call__(self, img: NdarrayOrTensor, randomize: bool = True) -> NdarrayOrTen
278280
if not isinstance(std, (int, float)):
279281
raise RuntimeError(f"std must be a float or int number, got {type(std)}.")
280282
img = self._add_noise(img, mean=self.mean, std=std, k=self.degrees_of_freedom)
283+
284+
img, *_ = convert_to_dst_type(img, dst=src, dtype=self.dtype)
281285
return img
286+
<<<<<<< HEAD
287+
282288

283289

290+
=======
291+
284292

293+
294+
>>>>>>> 83d8ad52 (Fixes metadata dropping)
285295
class RandRicianNoise(RandomizableTransform):
286296
"""
287297
Add Rician noise to image.

0 commit comments

Comments
 (0)