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.

[Feat] Discrete Gaussian kernel (gaussian) should be adapted for discrete filtering

See original GitHub issue

🐛 Bug

The current Gaussian kernel simply samples the continuous Gaussian function:

def gaussian(window_size, sigma):
    x = torch.arange(window_size).float() - window_size // 2
    if window_size % 2 == 0:
        x = x + 0.5
    gauss = torch.exp((-x.pow(2.0) / float(2 * sigma ** 2)))
    return gauss / gauss.sum()

Expected behavior

Discrete Gaussian filtering should be compatible with scale-space theory and rely on modified Bessel function for its kernel weights. See e.g.: https://en.wikipedia.org/wiki/Scale_space_implementation#The_discrete_Gaussian_kernel

Additional context

Note that this is a similar issue to that raised in MONAI: https://github.com/Project-MONAI/MONAI/issues/363

I came here while looking for a PyTorch implementation of a Discrete Gaussian filter but realised this one was also sampling the continuous Gaussian function.

ITK implements such a behaviour in itk::GaussianOperator: https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Core/Common/include/itkGaussianOperator.hxx

Wikipedia also provides a basic python implementation (albeit relying on scipy and without normalisation):

from scipy.special import iv
import numpy as np

def discrete_gaussian_kernel(n, t):
    T = np.exp(-t) * iv(n, t)
    return T

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
ducha-aikicommented, May 8, 2020

I will check the actual difference. In case of we are doing the change, we also would need to modify our spatial_gradient kernels. And it should help with local features localization precision as well.

0reactions
edgarribacommented, Oct 18, 2020

@wyli that sounds good we could try to target to include this feature for v0.5

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gaussian Filters for Nonlinear Filtering Problems - DTIC
We present the systematic formulation of Gaussian filters and develop efficient and accurate numerical integration of the optimal filter. We ...
Read more >
Computer Vision Assignment 1 - NARAYAN'S LOG BOOK
Gaussuan Filter ends up losing essential features because of blurring with larger window and higher sigma to remove noisy pixels. Problem 2 ...
Read more >
Spatial Filters - Gaussian Smoothing
The Gaussian smoothing operator is a 2-D convolution operator that is used to `blur' images and remove detail and noise. In this sense...
Read more >
Particle-kernel estimation of the filter density in state-space ...
the model is linear and Gaussian, πt is also Gaussian and can be computed exactly using a set of recursive equations known as...
Read more >
2 Filtering - Insight Toolkit
This filter can be used to transform the intensity levels of an image in three ... The discrete Gaussian filter type is instantiated...
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