2D Hilbert Transformations on PyTorch - Code example based on research article
This example of Python code is the implementation of the article below.
Lorenzo-Ginori, Juan. (2007). An Approach to the 2D Hilbert Transform for Image Processing Applications. Lecture Notes in Computer Science. 157-165. 10.1007/978-3-540-74260-9_14.
%%bash
if !python -c "import torch_hilbert" 2>/dev/null; then
pip install https://github.com/Simon-Bertrand/2DHilbertTransformations-PyTorch/archive/main.zip
fi
import torch_hilbert
!pip install -q torchvision requests matplotlib
import torchvision
import torch.nn.functional as F
import torch
im = torchvision.io.read_image("./imgs/example.png", torchvision.io.ImageReadMode.GRAY).divide(255)
�[1m[�[0m�[34;49mnotice�[0m�[1;39;49m]�[0m�[39;49m A new release of pip is available: �[0m�[31;49m23.2.1�[0m�[39;49m -> �[0m�[32;49m24.0�[0m
�[1m[�[0m�[34;49mnotice�[0m�[1;39;49m]�[0m�[39;49m To update, run: �[0m�[32;49mpip install --upgrade pip�[0m
import torch_hilbert
import matplotlib.pyplot as plt
for mode in ["AS", "HT"]:
for method in ["basic", "combined", "single_orthant", "directional"]:
plt.imshow(
torch_hilbert.HilbertTransformations(method, mode)(im)
.abs()
.moveaxis(0, -1)
)
plt.title(f"{method=} {mode=}")
plt.colorbar()
plt.show()