question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FEATURE] Add borderType option to kornia.filters like OpenCV

See original GitHub issue

kornia.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:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
edgarribacommented, Jun 26, 2019

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 😆

1reaction
edgarribacommented, Jun 25, 2019

@S-aiueo32 you are absolutely right. However, torch.conv2d only implements zeros or circular 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 using torch.pad which already implement more advanced padding techniques. In order to generalize the other filtering operators, I will implement this strategy in a filter2d operator which is BTW already implemented in OpenCV.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found