Sharpen images using the Gaussian Blur filter. Referring to: http://scipy-lectures.org/advanced/image_processing/auto_examples/plot_sharpen.html. The algorithm is shown as below .. code-block:: python blurred_f = gaussian_filter(img, sigma1) filter_blurred_f = gaus
| 1701 | |
| 1702 | |
| 1703 | class GaussianSharpen(Transform): |
| 1704 | """ |
| 1705 | Sharpen images using the Gaussian Blur filter. |
| 1706 | Referring to: http://scipy-lectures.org/advanced/image_processing/auto_examples/plot_sharpen.html. |
| 1707 | The algorithm is shown as below |
| 1708 | |
| 1709 | .. code-block:: python |
| 1710 | |
| 1711 | blurred_f = gaussian_filter(img, sigma1) |
| 1712 | filter_blurred_f = gaussian_filter(blurred_f, sigma2) |
| 1713 | img = blurred_f + alpha * (blurred_f - filter_blurred_f) |
| 1714 | |
| 1715 | A set of default values `sigma1=3.0`, `sigma2=1.0` and `alpha=30.0` is provide for reference. |
| 1716 | |
| 1717 | Args: |
| 1718 | sigma1: sigma parameter for the first gaussian kernel. if a list of values, must match the count |
| 1719 | of spatial dimensions of input data, and apply every value in the list to 1 spatial dimension. |
| 1720 | if only 1 value provided, use it for all spatial dimensions. |
| 1721 | sigma2: sigma parameter for the second gaussian kernel. if a list of values, must match the count |
| 1722 | of spatial dimensions of input data, and apply every value in the list to 1 spatial dimension. |
| 1723 | if only 1 value provided, use it for all spatial dimensions. |
| 1724 | alpha: weight parameter to compute the final result. |
| 1725 | approx: discrete Gaussian kernel type, available options are "erf", "sampled", and "scalespace". |
| 1726 | see also :py:meth:`monai.networks.layers.GaussianFilter`. |
| 1727 | |
| 1728 | """ |
| 1729 | |
| 1730 | backend = [TransformBackends.TORCH] |
| 1731 | |
| 1732 | def __init__( |
| 1733 | self, |
| 1734 | sigma1: Sequence[float] | float = 3.0, |
| 1735 | sigma2: Sequence[float] | float = 1.0, |
| 1736 | alpha: float = 30.0, |
| 1737 | approx: str = "erf", |
| 1738 | ) -> None: |
| 1739 | self.sigma1 = sigma1 |
| 1740 | self.sigma2 = sigma2 |
| 1741 | self.alpha = alpha |
| 1742 | self.approx = approx |
| 1743 | |
| 1744 | def __call__(self, img: NdarrayTensor) -> NdarrayTensor: |
| 1745 | img = convert_to_tensor(img, track_meta=get_track_meta()) |
| 1746 | img_t, *_ = convert_data_type(img, torch.Tensor, dtype=torch.float32) |
| 1747 | |
| 1748 | gf1, gf2 = ( |
| 1749 | GaussianFilter(img_t.ndim - 1, sigma, approx=self.approx).to(img_t.device) |
| 1750 | for sigma in (self.sigma1, self.sigma2) |
| 1751 | ) |
| 1752 | blurred_f = gf1(img_t.unsqueeze(0)) |
| 1753 | filter_blurred_f = gf2(blurred_f) |
| 1754 | out_t: torch.Tensor = (blurred_f + self.alpha * (blurred_f - filter_blurred_f)).squeeze(0) |
| 1755 | out, *_ = convert_to_dst_type(out_t, dst=img, dtype=out_t.dtype) |
| 1756 | return out |
| 1757 | |
| 1758 | |
| 1759 | class RandGaussianSharpen(RandomizableTransform): |
no outgoing calls
searching dependent graphs…