(self, img: NdarrayOrTensor, randomize: bool = True)
| 1898 | ) |
| 1899 | |
| 1900 | def __call__(self, img: NdarrayOrTensor, randomize: bool = True) -> NdarrayOrTensor: |
| 1901 | img = convert_to_tensor(img, track_meta=get_track_meta()) |
| 1902 | if randomize: |
| 1903 | self.randomize() |
| 1904 | |
| 1905 | if not self._do_transform: |
| 1906 | return img |
| 1907 | |
| 1908 | if self.reference_control_points is None or self.floating_control_points is None: |
| 1909 | raise RuntimeError("please call the `randomize()` function first.") |
| 1910 | img_t = convert_to_tensor(img, track_meta=False) |
| 1911 | img_min, img_max = img_t.min(), img_t.max() |
| 1912 | if img_min == img_max: |
| 1913 | warn( |
| 1914 | f"The image's intensity is a single value {img_min}. " |
| 1915 | "The original image is simply returned, no histogram shift is done." |
| 1916 | ) |
| 1917 | return img |
| 1918 | xp, *_ = convert_to_dst_type(self.reference_control_points, dst=img_t) |
| 1919 | yp, *_ = convert_to_dst_type(self.floating_control_points, dst=img_t) |
| 1920 | reference_control_points_scaled = xp * (img_max - img_min) + img_min |
| 1921 | floating_control_points_scaled = yp * (img_max - img_min) + img_min |
| 1922 | img_t = self.interp(img_t, reference_control_points_scaled, floating_control_points_scaled) |
| 1923 | return convert_to_dst_type(img_t, dst=img)[0] |
| 1924 | |
| 1925 | |
| 1926 | class GibbsNoise(Transform, Fourier): |
nothing calls this directly
no test coverage detected