@@ -373,6 +373,8 @@ class ScaleIntensity(Transform):
373373 If `minv` and `maxv` not provided, use `factor` to scale image by ``v = v * (1 + factor)``.
374374 """
375375
376+ backend = [TransformBackends .TORCH , TransformBackends .NUMPY ]
377+
376378 def __init__ (
377379 self , minv : Optional [float ] = 0.0 , maxv : Optional [float ] = 1.0 , factor : Optional [float ] = None
378380 ) -> None :
@@ -387,7 +389,7 @@ def __init__(
387389 self .maxv = maxv
388390 self .factor = factor
389391
390- def __call__ (self , img : np . ndarray ) -> np . ndarray :
392+ def __call__ (self , img : NdarrayOrTensor ) -> NdarrayOrTensor :
391393 """
392394 Apply the transform to `img`.
393395
@@ -396,9 +398,11 @@ def __call__(self, img: np.ndarray) -> np.ndarray:
396398
397399 """
398400 if self .minv is not None and self .maxv is not None :
399- return np . asarray ( rescale_array (img , self .minv , self .maxv , img .dtype ) )
401+ return rescale_array (img , self .minv , self .maxv , img .dtype )
400402 if self .factor is not None :
401- return np .asarray (img * (1 + self .factor ), dtype = img .dtype )
403+ out = img * (1 + self .factor )
404+ out , * _ = convert_data_type (out , dtype = img .dtype )
405+ return out
402406 raise ValueError ("Incompatible values: minv=None or maxv=None and factor=None." )
403407
404408
@@ -408,6 +412,8 @@ class RandScaleIntensity(RandomizableTransform):
408412 is randomly picked.
409413 """
410414
415+ backend = ScaleIntensity .backend
416+
411417 def __init__ (self , factors : Union [Tuple [float , float ], float ], prob : float = 0.1 ) -> None :
412418 """
413419 Args:
@@ -429,7 +435,7 @@ def randomize(self, data: Optional[Any] = None) -> None:
429435 self .factor = self .R .uniform (low = self .factors [0 ], high = self .factors [1 ])
430436 super ().randomize (None )
431437
432- def __call__ (self , img : np . ndarray ) -> np . ndarray :
438+ def __call__ (self , img : NdarrayOrTensor ) -> NdarrayOrTensor :
433439 """
434440 Apply the transform to `img`.
435441 """
0 commit comments