Apply clip based on the intensity distribution of input image. If `sharpness_factor` is provided, the intensity values will be soft clipped according to f(x) = x + (1/sharpness_factor)*softplus(- c(x - minv)) - (1/sharpness_factor)*softplus(c(x - maxv)) From https://medium.com/life-
| 1037 | |
| 1038 | |
| 1039 | class ClipIntensityPercentiles(Transform): |
| 1040 | """ |
| 1041 | Apply clip based on the intensity distribution of input image. |
| 1042 | If `sharpness_factor` is provided, the intensity values will be soft clipped according to |
| 1043 | f(x) = x + (1/sharpness_factor)*softplus(- c(x - minv)) - (1/sharpness_factor)*softplus(c(x - maxv)) |
| 1044 | From https://medium.com/life-at-hopper/clip-it-clip-it-good-1f1bf711b291 |
| 1045 | |
| 1046 | Soft clipping preserves the order of the values and maintains the gradient everywhere. |
| 1047 | For example: |
| 1048 | |
| 1049 | .. code-block:: python |
| 1050 | :emphasize-lines: 11, 22 |
| 1051 | |
| 1052 | image = torch.Tensor( |
| 1053 | [[[1, 2, 3, 4, 5], |
| 1054 | [1, 2, 3, 4, 5], |
| 1055 | [1, 2, 3, 4, 5], |
| 1056 | [1, 2, 3, 4, 5], |
| 1057 | [1, 2, 3, 4, 5], |
| 1058 | [1, 2, 3, 4, 5]]]) |
| 1059 | |
| 1060 | # Hard clipping from lower and upper image intensity percentiles |
| 1061 | hard_clipper = ClipIntensityPercentiles(30, 70) |
| 1062 | print(hard_clipper(image)) |
| 1063 | metatensor([[[2., 2., 3., 4., 4.], |
| 1064 | [2., 2., 3., 4., 4.], |
| 1065 | [2., 2., 3., 4., 4.], |
| 1066 | [2., 2., 3., 4., 4.], |
| 1067 | [2., 2., 3., 4., 4.], |
| 1068 | [2., 2., 3., 4., 4.]]]) |
| 1069 | |
| 1070 | |
| 1071 | # Soft clipping from lower and upper image intensity percentiles |
| 1072 | soft_clipper = ClipIntensityPercentiles(30, 70, 10.) |
| 1073 | print(soft_clipper(image)) |
| 1074 | metatensor([[[2.0000, 2.0693, 3.0000, 3.9307, 4.0000], |
| 1075 | [2.0000, 2.0693, 3.0000, 3.9307, 4.0000], |
| 1076 | [2.0000, 2.0693, 3.0000, 3.9307, 4.0000], |
| 1077 | [2.0000, 2.0693, 3.0000, 3.9307, 4.0000], |
| 1078 | [2.0000, 2.0693, 3.0000, 3.9307, 4.0000], |
| 1079 | [2.0000, 2.0693, 3.0000, 3.9307, 4.0000]]]) |
| 1080 | |
| 1081 | See Also: |
| 1082 | |
| 1083 | - :py:class:`monai.transforms.ScaleIntensityRangePercentiles` |
| 1084 | """ |
| 1085 | |
| 1086 | backend = [TransformBackends.TORCH, TransformBackends.NUMPY] |
| 1087 | |
| 1088 | def __init__( |
| 1089 | self, |
| 1090 | lower: float | None, |
| 1091 | upper: float | None, |
| 1092 | sharpness_factor: float | None = None, |
| 1093 | channel_wise: bool = False, |
| 1094 | return_clipping_values: bool = False, |
| 1095 | dtype: DtypeLike = np.float32, |
| 1096 | ) -> None: |
no outgoing calls
searching dependent graphs…