Ask Your Question

vaibhav_wimpsta's profile - activity

2018-06-06 01:42:36 -0600 asked a question What are the steps to perform blind deconvolution on an image?

What are the steps to perform blind deconvolution on an image? I aim to write a CPP code in opencv to deblur an image us

2018-06-05 23:42:49 -0600 marked best answer Wiener decovlotuin in cpp giving back the same image

I was trying to deblur a noisy image using wiener deconvolution. I found this code which added noise to an image and removed it as well. Modifying this code only i tried to implement the exact formula given on wiki. But the output is same as input image

In the code i debugged a bit and found when i performed magI=magI/x values in magI all became 1. Can anyone please check if the calculation i have done are correct or not? If so how do i prevent values in magI becoming 1

PS: I have included the full code in case anyone wants to learn and implement the code. You can jump straight to wiener2 function as the error is in there.

#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"

using namespace cv;
using namespace std;

Mat wiener2(Mat I, Mat image_spectrum, int noise_stddev);
Mat padd_image(Mat I);

Mat get_spectrum(Mat I);
Mat get_dft(Mat I);

Mat with_noise(Mat image, int stddev);
Mat rand_noise(Mat I, int stddev);

Mat createavg(Size imsize) ;
void shift(Mat magI);


int main(int argc, char *argv[]) {

int noise_stddev=20;
string input_filename="blur.png", output_filename="write.png";   // Have a blurred image here
cout << "noise standard deviation: " << noise_stddev << "\n";
cout << "input file: " << input_filename << "\n";

Mat I = imread(input_filename, CV_LOAD_IMAGE_GRAYSCALE);
if(I.data==NULL){
    cout << "Can't open file: " << input_filename << "\n";
    return 2;
}

Mat raw_sample = imread("blur.png", CV_LOAD_IMAGE_GRAYSCALE);
if(raw_sample.data==NULL){
    cout << "Can't open file: sample.bmp\n";
    return 3;
}

Mat padded = padd_image(I);
Mat noisy;

    noisy = with_noise(padded, noise_stddev);

Mat sample(padded.rows, padded.cols, CV_8U);
resize(raw_sample, sample, sample.size());    
Mat spectrum = get_spectrum(sample);    //to get signal spectrum of known image 
Mat enhanced = wiener2(noisy, spectrum, noise_stddev);
imshow("image 1", noisy);
imshow("image 2", enhanced);
waitKey();
}
Mat createavg(Size imsize) {


Mat kernel = Mat(5,5,CV_32FC1,Scalar(0.04));

int w = imsize.width-kernel.cols;
int h = imsize.height-kernel.rows;

int r = w/2;
int l = imsize.width-kernel.cols -r;

int b = h/2;
int t = imsize.height-kernel.rows -b;

Mat ret;
copyMakeBorder(kernel,ret,t,b,l,r,BORDER_CONSTANT,Scalar::all(0));

return ret;

}

//inputs are the blurry image with noise , the original image power spectra , and standard deviation of the noise introduced
Mat wiener2(Mat final_noise, Mat image_spectrum, int noise_stddev){
Mat padded = padd_image(final_noise);
Mat noise = rand_noise(padded, noise_stddev);
Mat noise_spectrum = get_spectrum(noise);

Scalar padded_mean = mean(padded);

Mat planes[2];
Mat complexI = get_dft(padded);
split(complexI, planes);    // planes[0] = Re(DFT(I), planes[1] = Im(DFT(I))

Mat factor = (noise_spectrum / image_spectrum); //calculates the signal to noise ratio
//-----------------compute the frequency domain multiplier



Mat mask = createavg(padded.size());            //creating the kernel which initally prduced the blurred image
shift(mask);// shifting the filter
Mat mplane[] = {Mat_<float>(mask), Mat::zeros(mask.size(), CV_32F)};
Mat kernelcomplex;
merge(mplane, 2, kernelcomplex); 

dft(kernelcomplex, kernelcomplex);  // computing dft of kernel

split(kernelcomplex, mplane);// splitting the dft of kernel ...
(more)
2018-06-05 23:42:49 -0600 received badge  Scholar (source)
2018-06-04 12:45:49 -0600 asked a question Wiener decovlotuin in cpp giving back the same image

Wiener decovlotuin in cpp giving back the same image I was trying to deblur a noisy image using wiener deconvolution. I

2018-06-04 01:11:05 -0600 asked a question What does wiki means by inverse of original system?(Wiener Deconvolution)

What does wiki means by inverse of original system?(Wiener Deconvolution) Can anyone explain how to calculate this in cp

2018-06-01 13:14:34 -0600 asked a question CPP code fro deblurring an image using Weiner filter.

CPP code fro deblurring an image using Weiner filter. I need a code to deblur an image using weiner filter... I am not s

2018-05-30 02:31:29 -0600 commented question Why is mean filter not working in frequency domain?

I first computed dft of my main image, then made a kernel mask padded it with zeroes to the size of image, after that i

2018-05-30 02:30:44 -0600 commented question Why is mean filter not working in frequency domain?

I first computed dft of my main image, then made a kernel mask padded it with zeroes to the size of image, after that i

2018-05-30 02:28:01 -0600 commented question Why is mean filter not working in frequency domain?

Can you provide me a kernel for performing average blur to the image in frequency domain?According to me it should have

2018-05-30 02:12:12 -0600 commented question Why is mean filter not working in frequency domain?

And the kernel isnt Blurring the image,, i changed the values from 127 to 255 in your specified kernel @LBerger and i go

2018-05-30 02:07:18 -0600 commented question Why is mean filter not working in frequency domain?

The output image is quite distorted after using the kernel you specified. Why so? And what was my kernel doing and what

2018-05-30 01:37:44 -0600 commented question Why is mean filter not working in frequency domain?

Can you please explain what it does? I just need to apply the mean blur filter so need a Mat kernel for the same.

2018-05-30 01:20:56 -0600 commented question Why is mean filter not working in frequency domain?

Just focus on the function createavg(Size imsize); I commented the code for gaussian kernel but it works fine for that,

2018-05-30 00:54:23 -0600 asked a question Why is mean filter not working in frequency domain?

Why is mean filter not working in frequency domain? #include "opencv2/core/core.hpp" #include "opencv2/imgproc/imgproc.h