[FEATURE] Add borderType option to kornia.filters like OpenCV
See original GitHub issuekornia.filters
operations have no option like borderType
on OpenCV.
In my experience, borderType
is the most critical argument in the arguments that is not in kornia.filters
.
To reproduce it, I suggest the changes like below:
class BoxBlur(nn.Module):
def __init__(self, kernel_size: Tuple[int, int], border_type='zero': str) -> None:
super(BoxBlur, self).__init__()
self.kernel: torch.Tensor = _get_box_filter(kernel_size)
self.padding: Tuple[int, int] = _compute_zero_padding(kernel_size)
self.border_type = border_type
def forward(self, input: torch.Tensor): # type: ignore
if not torch.is_tensor(input):
raise TypeError("Input type is not a torch.Tensor. Got {}"
.format(type(input)))
if not len(input.shape) == 4:
raise ValueError("Invalid input shape, we expect BxCxHxW. Got: {}"
.format(input.shape))
# prepare kernel
b, c, h, w = input.shape
tmp_kernel: torch.Tensor = self.kernel.to(input.device).to(input.dtype)
kernel: torch.Tensor = tmp_kernel.repeat(c, 1, 1, 1)
return conv2d(input, kernel, padding=self.padding, padding_mode=self.border_type, stride=1, groups=c)
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
kornia.filters
Function that returns Gaussian filter coefficients. Parameters. kernel_size ( int ) – filter size. It should be odd and positive. sigma ...
Read more >Image Filtering - OpenCV
Unnormalized box filter is useful for computing various integral characteristics over each pixel neighborhood, such as covariance matrices of image ...
Read more >Guide To Kornia: An OpenCV-inspired PyTorch Framework
Kornia is an open-source Python library inspired by OpenCV designed to handle generic Computer Vision tasks.
Read more >目录 - Gitee
IDEA: Add quantization and pruning functionality OpenCV DNN module ... New-Filter-Engine ... Dmytro Mishkin has git hub repsoitory (on Kornia paper).
Read more >A survey on Kornia: an Open Source Differentiable Computer ...
Inspired by OpenCV, Kornia is composed of a set of modules containing operators ... and low level image processing techniques, such as filtering...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeap, it’s something we needed for a while. I’ve seen you implemented YCbCr, are you planning to send a PR? The is a lot of color stuff to be done 😆
@S-aiueo32 you are absolutely right. However,
torch.conv2d
only implementszeros
orcircular
padding modes. To address this issue, as @ducha-aiki suggested in https://github.com/arraiyopensource/kornia/pull/168, we need to manually pad the input usingtorch.pad
which already implement more advanced padding techniques. In order to generalize the other filtering operators, I will implement this strategy in afilter2d
operator which is BTW already implemented in OpenCV.