Please refer to :py:class:`monai.transforms.AddExtremePointsChannel` for the usage. Applies a gaussian filter to the extreme points image. Then the pixel values in points image are rescaled to range [rescale_min, rescale_max]. Args: points: Extreme points of the object/org
(
points: list[tuple[int, ...]],
label: NdarrayOrTensor,
sigma: Sequence[float] | float | Sequence[torch.Tensor] | torch.Tensor = 0.0,
rescale_min: float = -1.0,
rescale_max: float = 1.0,
)
| 1636 | |
| 1637 | |
| 1638 | def extreme_points_to_image( |
| 1639 | points: list[tuple[int, ...]], |
| 1640 | label: NdarrayOrTensor, |
| 1641 | sigma: Sequence[float] | float | Sequence[torch.Tensor] | torch.Tensor = 0.0, |
| 1642 | rescale_min: float = -1.0, |
| 1643 | rescale_max: float = 1.0, |
| 1644 | ) -> torch.Tensor: |
| 1645 | """ |
| 1646 | Please refer to :py:class:`monai.transforms.AddExtremePointsChannel` for the usage. |
| 1647 | |
| 1648 | Applies a gaussian filter to the extreme points image. Then the pixel values in points image are rescaled |
| 1649 | to range [rescale_min, rescale_max]. |
| 1650 | |
| 1651 | Args: |
| 1652 | points: Extreme points of the object/organ. |
| 1653 | label: label image to get extreme points from. Shape must be |
| 1654 | (1, spatial_dim1, [, spatial_dim2, ...]). Doesn't support one-hot labels. |
| 1655 | sigma: if a list of values, must match the count of spatial dimensions of input data, |
| 1656 | and apply every value in the list to 1 spatial dimension. if only 1 value provided, |
| 1657 | use it for all spatial dimensions. |
| 1658 | rescale_min: minimum value of output data. |
| 1659 | rescale_max: maximum value of output data. |
| 1660 | """ |
| 1661 | # points to image |
| 1662 | # points_image = torch.zeros(label.shape[1:], dtype=torch.float) |
| 1663 | points_image = torch.zeros_like(torch.as_tensor(label[0]), dtype=torch.float) |
| 1664 | for p in points: |
| 1665 | points_image[p] = 1.0 |
| 1666 | |
| 1667 | if isinstance(sigma, Sequence): |
| 1668 | sigma = [torch.as_tensor(s, device=points_image.device) for s in sigma] |
| 1669 | else: |
| 1670 | sigma = torch.as_tensor(sigma, device=points_image.device) |
| 1671 | |
| 1672 | # add channel and add batch |
| 1673 | points_image = points_image.unsqueeze(0).unsqueeze(0) |
| 1674 | gaussian_filter = GaussianFilter(label.ndim - 1, sigma=sigma) |
| 1675 | points_image = gaussian_filter(points_image).squeeze(0).detach() |
| 1676 | |
| 1677 | # rescale the points image to [rescale_min, rescale_max] |
| 1678 | min_intensity = points_image.min() |
| 1679 | max_intensity = points_image.max() |
| 1680 | points_image = (points_image - min_intensity) / (max_intensity - min_intensity) |
| 1681 | return points_image * (rescale_max - rescale_min) + rescale_min |
| 1682 | |
| 1683 | |
| 1684 | def map_spatial_axes( |
no test coverage detected
searching dependent graphs…