Apply Gaussian smooth to the input data based on specified `sigma` parameter. A default value `sigma=1.0` is provided for reference. Args: sigma: if a list of values, must match the count of spatial dimensions of input data, and apply every value in the list to 1 sp
| 1612 | |
| 1613 | |
| 1614 | class GaussianSmooth(Transform): |
| 1615 | """ |
| 1616 | Apply Gaussian smooth to the input data based on specified `sigma` parameter. |
| 1617 | A default value `sigma=1.0` is provided for reference. |
| 1618 | |
| 1619 | Args: |
| 1620 | sigma: if a list of values, must match the count of spatial dimensions of input data, |
| 1621 | and apply every value in the list to 1 spatial dimension. if only 1 value provided, |
| 1622 | use it for all spatial dimensions. |
| 1623 | approx: discrete Gaussian kernel type, available options are "erf", "sampled", and "scalespace". |
| 1624 | see also :py:meth:`monai.networks.layers.GaussianFilter`. |
| 1625 | |
| 1626 | """ |
| 1627 | |
| 1628 | backend = [TransformBackends.TORCH] |
| 1629 | |
| 1630 | def __init__(self, sigma: Sequence[float] | float = 1.0, approx: str = "erf") -> None: |
| 1631 | self.sigma = sigma |
| 1632 | self.approx = approx |
| 1633 | |
| 1634 | def __call__(self, img: NdarrayTensor) -> NdarrayTensor: |
| 1635 | img = convert_to_tensor(img, track_meta=get_track_meta()) |
| 1636 | img_t, *_ = convert_data_type(img, torch.Tensor, dtype=torch.float) |
| 1637 | sigma: Sequence[torch.Tensor] | torch.Tensor |
| 1638 | if isinstance(self.sigma, Sequence): |
| 1639 | sigma = [torch.as_tensor(s, device=img_t.device) for s in self.sigma] |
| 1640 | else: |
| 1641 | sigma = torch.as_tensor(self.sigma, device=img_t.device) |
| 1642 | gaussian_filter = GaussianFilter(img_t.ndim - 1, sigma, approx=self.approx) |
| 1643 | out_t: torch.Tensor = gaussian_filter(img_t.unsqueeze(0)).squeeze(0) |
| 1644 | out, *_ = convert_to_dst_type(out_t, dst=img, dtype=out_t.dtype) |
| 1645 | |
| 1646 | return out |
| 1647 | |
| 1648 | |
| 1649 | class RandGaussianSmooth(RandomizableTransform): |
no outgoing calls
searching dependent graphs…