ihhub / penguinV

Computer vision library with focus on heterogeneous systems
Other
119 stars 90 forks source link

Add median and gaussian 1D filters as an optional step for gradient based edge detection #346

Open ihhub opened 5 years ago

ihhub commented 5 years ago

We have an implementation of gradient based edge detection in src/edge_detection.h and src/edge_detection.cpp. Due to image quality of some input data it's good to have an extra image filtration before finding gradient values. Median and Gaussian filters are most common filters used in such case. We want to add them as an optional step before finding first and second gradients on an image (findEdgePoints) function.

vrozin commented 5 years ago

Hi @ihhub ! I am very interested in working with this issue. May I ask you something regarding Gaussian noise filtering? As I can see, in filtering.h and filtering.cpp there is present a function for Gauss kernel search void GetGaussianKernel( std::vector<float> & filter, uint32_t width, uint32_t height, uint32_t kernelSize, float sigma );. Will I be correct to assume that in order to filter an image with usage of Gaussian kernel, I would need to implement a linear filter function?

ihhub commented 5 years ago

@vrozin you would need to follow the idea of creation of Gaussian kernel based on code in filter.h. GetGaussianKernel function is designed to return 2D filter kernel while for edge detection we need 1D. This is pretty simple to do: think that you don't have Y axis so the line of the code:

*x = doubleSigmaPiInv * expf( -static_cast<float>(posX * posX + posY2) / doubleSigma );

would be transformed into

*x = doubleSigmaPiInv * expf( -static_cast<float>(posX * posX) / doubleSigma );

with having a single loop :)

Once you have 1D kernel (which is just std::vector<>) you do a simple multiplication of elements where the center of the kernel is your current pixel position.

I recommend to create a function of 1D Gaussian kernel creation inside edge_detection.cpp file which returns a vector of normalized (0..1) values. You could copy GetGaussianKernel function and paste it with modification for 1D case.

vrozin commented 5 years ago

@ihhub Thank you for the detailed explanation! Will work on it :)

ihhub commented 5 years ago

Sure!