Performs probability based non-maximum suppression (NMS) on the probabilities map via iteratively selecting the coordinate with highest probability and then move it as well as its surrounding values. The remove range is determined by the parameter `box_size`. If multiple coordinates
| 899 | |
| 900 | |
| 901 | class ProbNMS(Transform): |
| 902 | """ |
| 903 | Performs probability based non-maximum suppression (NMS) on the probabilities map via |
| 904 | iteratively selecting the coordinate with highest probability and then move it as well |
| 905 | as its surrounding values. The remove range is determined by the parameter `box_size`. |
| 906 | If multiple coordinates have the same highest probability, only one of them will be |
| 907 | selected. |
| 908 | |
| 909 | Args: |
| 910 | spatial_dims: number of spatial dimensions of the input probabilities map. |
| 911 | Defaults to 2. |
| 912 | sigma: the standard deviation for gaussian filter. |
| 913 | It could be a single value, or `spatial_dims` number of values. Defaults to 0.0. |
| 914 | prob_threshold: the probability threshold, the function will stop searching if |
| 915 | the highest probability is no larger than the threshold. The value should be |
| 916 | no less than 0.0. Defaults to 0.5. |
| 917 | box_size: the box size (in pixel) to be removed around the pixel with the maximum probability. |
| 918 | It can be an integer that defines the size of a square or cube, |
| 919 | or a list containing different values for each dimensions. Defaults to 48. |
| 920 | |
| 921 | Return: |
| 922 | a list of selected lists, where inner lists contain probability and coordinates. |
| 923 | For example, for 3D input, the inner lists are in the form of [probability, x, y, z]. |
| 924 | |
| 925 | Raises: |
| 926 | ValueError: When ``prob_threshold`` is less than 0.0. |
| 927 | ValueError: When ``box_size`` is a list or tuple, and its length is not equal to `spatial_dims`. |
| 928 | ValueError: When ``box_size`` has a less than 1 value. |
| 929 | |
| 930 | """ |
| 931 | |
| 932 | backend = [TransformBackends.NUMPY] |
| 933 | |
| 934 | def __init__( |
| 935 | self, |
| 936 | spatial_dims: int = 2, |
| 937 | sigma: Sequence[float] | float | Sequence[torch.Tensor] | torch.Tensor = 0.0, |
| 938 | prob_threshold: float = 0.5, |
| 939 | box_size: int | Sequence[int] = 48, |
| 940 | ) -> None: |
| 941 | self.sigma = sigma |
| 942 | self.spatial_dims = spatial_dims |
| 943 | if self.sigma != 0: |
| 944 | self.filter = GaussianFilter(spatial_dims=spatial_dims, sigma=sigma) |
| 945 | if prob_threshold < 0: |
| 946 | raise ValueError("prob_threshold should be no less than 0.0.") |
| 947 | self.prob_threshold = prob_threshold |
| 948 | if isinstance(box_size, int): |
| 949 | self.box_size = np.asarray([box_size] * spatial_dims) |
| 950 | elif len(box_size) != spatial_dims: |
| 951 | raise ValueError("the sequence length of box_size should be the same as spatial_dims.") |
| 952 | else: |
| 953 | self.box_size = np.asarray(box_size) |
| 954 | if self.box_size.min() <= 0: |
| 955 | raise ValueError("box_size should be larger than 0.") |
| 956 | |
| 957 | self.box_lower_bd = self.box_size // 2 |
| 958 | self.box_upper_bd = self.box_size - self.box_lower_bd |
no outgoing calls
searching dependent graphs…