Hi, I am trying to make something like sobel filter on a single image in PyTorch.
I did that in Pyton using CV2.
How to do that for a single image in PyTorch?
Hi, I am trying to make something like sobel filter on a single image in PyTorch.
I did that in Pyton using CV2.
How to do that for a single image in PyTorch?
Hi,
You need to use torch.nn.functional.conv2d in order to convolve the image with an specific kernel.
docs indicates the shape of the kernel, very straight forward.
Note that pytorch use cross-correlation instead of convolutions.
Regards
Yes, JuanFMontesinos, I used just what you told me.
Where f is sobel filter expanded to all 3 channels.
import torch
filter = torch.tensor([[1., 2. , 1.], [0., 0., 0.], [-1., -2. , -1.]])
f = filter.expand(1,3,3,3)
Wonderful feedback. Thanks.