# Get a 2D gaussian kernel for deconvolution

Hello,

I am trying to apply the Lucy-Richardson deconvolution algorithm with the following code:

static Mat RLTikh_deconvolution(Mat observed, Mat psf, int iterations) {

Mat deconv = observed.clone();
double mu = 0.01;

// Iterate
for (int i = 0; i < iterations; i++) {

// Temporary matrix
Mat ratio;
filter2D(deconv, ratio, deconv.depth(), psf, Point(-1, -1), 0,
BORDER_REFLECT);

divide(observed, ratio, ratio);

filter2D(ratio, ratio, ratio.depth(), psf, Point(-1, -1), 0,
BORDER_REFLECT);

// TV Regularization
Mat denom;
Laplacian(deconv, denom, deconv.depth(), 1, 1, 0, BORDER_REFLECT);
denom = 1.0 - 2.0 * mu * denom;
divide(ratio, denom, ratio);

// Apply iteration on the estimate
multiply(deconv, ratio, deconv);
}

return deconv;
}


I get the psf mat with Mat psf = getGaussianKernel(13, -1);

The problem is that this kernel is a 1D kernel but I would like to apply a 2D one. I believe I could apply the kernel two times (in X direction and Y direction) to get the result I want. But how I can do it ?

edit retag close merge delete

Sort by ยป oldest newest most voted

you can use sepFilter2D with your 1d kernel:

I believe I could apply the kernel two times (in X direction and Y direction)

that's exactly, what it does.

static Mat RLTikh_deconvolution(Mat observed, Mat psf, int iterations) {

Mat deconv = observed.clone();
double mu = 0.01;

// Iterate
for (int i = 0; i < iterations; i++) {

// Temporary matrix
Mat ratio;
sepFilter2D(deconv, ratio, deconv.depth(), psf, psf, Point(-1, -1), 0,
BORDER_REFLECT);

divide(observed, ratio, ratio);

sepFilter2D(ratio, ratio, ratio.depth(), psf, psf, Point(-1, -1), 0,
BORDER_REFLECT);

// TV Regularization
Mat denom;
Laplacian(deconv, denom, deconv.depth(), 1, 1, 0, BORDER_REFLECT);
denom = 1.0 - 2.0 * mu * denom;
divide(ratio, denom, ratio);

// Apply iteration on the estimate
multiply(deconv, ratio, deconv);
}

return deconv;
}

more

1

So easy. Sorry for this dummy question :). And of course, thank you for your answer.

( 2017-12-07 05:30:43 -0600 )edit
1

well, you have to know , that it exists, then it's easy ...

( 2017-12-07 05:39:08 -0600 )edit

Official site

GitHub

Wiki

Documentation