MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / __call__

Method __call__

monai/transforms/intensity/array.py:533–586  ·  view source on GitHub ↗

Apply the transform to `img`. Args: img: the input tensor/array factor: factor scale by ``v = v * (1 + factor)``

(self, img: NdarrayOrTensor, factor=None)

Source from the content-addressed store, hash-verified

531 self.dtype = dtype
532
533 def __call__(self, img: NdarrayOrTensor, factor=None) -> NdarrayOrTensor:
534 """
535 Apply the transform to `img`.
536 Args:
537 img: the input tensor/array
538 factor: factor scale by ``v = v * (1 + factor)``
539
540 """
541
542 factor = factor if factor is not None else self.factor
543
544 img = convert_to_tensor(img, track_meta=get_track_meta())
545 img_t = convert_to_tensor(img, track_meta=False)
546 ret: NdarrayOrTensor
547 if self.channel_wise:
548 out = []
549 for d in img_t:
550 if self.preserve_range:
551 clip_min = d.min()
552 clip_max = d.max()
553
554 if self.fixed_mean:
555 mn = d.mean()
556 d = d - mn
557
558 out_channel = d * (1 + factor)
559
560 if self.fixed_mean:
561 out_channel = out_channel + mn
562
563 if self.preserve_range:
564 out_channel = clip(out_channel, clip_min, clip_max)
565
566 out.append(out_channel)
567 ret = torch.stack(out)
568 else:
569 if self.preserve_range:
570 clip_min = img_t.min()
571 clip_max = img_t.max()
572
573 if self.fixed_mean:
574 mn = img_t.mean()
575 img_t = img_t - mn
576
577 ret = img_t * (1 + factor)
578
579 if self.fixed_mean:
580 ret = ret + mn
581
582 if self.preserve_range:
583 ret = clip(ret, clip_min, clip_max)
584
585 ret = convert_to_dst_type(ret, dst=img, dtype=self.dtype or img_t.dtype)[0]
586 return ret
587
588
589class RandScaleIntensityFixedMean(RandomizableTransform):

Callers

nothing calls this directly

Calls 5

convert_to_tensorFunction · 0.90
get_track_metaFunction · 0.90
clipFunction · 0.90
convert_to_dst_typeFunction · 0.90
appendMethod · 0.45

Tested by

no test coverage detected