Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

gaussian filter

hi

i have made a gaussian function and convlove it with log of an image by taking fourier transform and then invers fft after multiplication. i have got the blurr image but its axis are inversed . 

here is the attached vi plz give an image file path to the file path and see the result and tell me how can i get correct image

thnx

FAIRY

0 Kudos
Message 1 of 37
(17,403 Views)

Hello fairy55,

 

your title says "gaussian filter". The Gaussian filter applied to an image smooths the image by calculating the weighted averages using the overlaying kernel. Yo are trying to blur the image right?

Why don't you use convolution operation with Gaussian kernel (i think there are some predefined kernels already in Labview). You can do the operation directly on an image.

 

In your code, why are you using matrix to array.vi? I don't understand this. Btw, the operations performed on matrices and arrays are different. Why filtering in frequency domain? Could you please share a link to the equations behind your code (or please explain)?

 

Best regards,


https://decibel.ni.com/content/blogs/kl3m3n



"Kudos: Users may give one another Kudos on the forums for posts that they found particularly helpful or insightful."
0 Kudos
Message 2 of 37
(17,388 Views)

@fairy55 wrote:

here is the attached vi plz give an image file path to the file path and see the result and tell me how can i get correct image

thnx

 


Hmmm... it seems to be frequencies are flipped. Anyway I've got working smoothing in your code by removing one of FFT. Slightly cleaned up version:

 

f1.png

 

Result:

f2.png

 

 


@Klemen wrote:

Why filtering in frequency domain? 


Technically filtering in frequency domain and convolution are equivalent, so you can FFT the image and the kernel, then multiply both in freq domain and perform inverse FFT, for example:

f3.png

Result:

 

f4.jpg

 

 

Andrey.

Download All
Message 3 of 37
(17,369 Views)

Dear Andrey_Dmitriev,

 

I am aware that  image filtering can be performed both in spatial and frequency domain. I just thought that spatial domain filtering with Gaussian  was more roboust (I have read somewhere that FFT has some degree of quality loss) and faster? Anyway, thank you very much for the explanation, I have never used Gaussian filter in frequency domain yet.

 

Thank you and best regards,


https://decibel.ni.com/content/blogs/kl3m3n



"Kudos: Users may give one another Kudos on the forums for posts that they found particularly helpful or insightful."
0 Kudos
Message 4 of 37
(17,354 Views)

Dear Andrey_Dmitriev,

 

I have one more question please as I am trying to understand the code:

 

Taking look at the snapshot of the first code of your post, the created Gaussian distribution is in spatial domain:

 

f(x,y) = A \exp\left(- \left(\frac{(x-x_o)^2}{2\sigma_x^2} + \frac{(y-y_o)^2}{2\sigma_y^2} \right)\right).

 

So sigmax = sigmay = sqrt(125) and A = 1 in your example.

 

Also plotting the distribution gives the bell shaped characteristic:

 

gauss.png

 

Why is there no FFT applied prior to filtering, since the image is also in frequency domain?

 

Please help me understand.

 

Thank you and best regards,


https://decibel.ni.com/content/blogs/kl3m3n



"Kudos: Users may give one another Kudos on the forums for posts that they found particularly helpful or insightful."
Message 5 of 37
(17,349 Views)

 

Why is there no FFT applied prior to filtering, since the image is also in frequency domain?

 


Because its just  truncates the frequencies of a complex image.

 

Compare the following pieces of code:

 

fft3.png

 

and results:

 

fft3.jpg

 

You're right - we should perform FFT for the kernel (as it shown above), but I was unable to get the code above running with FFT on the gaussian distribution. When image in frequency domain multiplied with bell-shaped function, then high frequencies gets truncated and image smoothed. It was just trick.

 

Andrey.

Message 6 of 37
(17,343 Views)

Thank you very much for the clear explanation.

 

I understand this now!!!

 

Best regards,

 

 


https://decibel.ni.com/content/blogs/kl3m3n



"Kudos: Users may give one another Kudos on the forums for posts that they found particularly helpful or insightful."
0 Kudos
Message 7 of 37
(17,339 Views)

hi Andrey!

thnx alot for replying and helping me. i have some problems. actually i am doing my final year project. i m working on a theory named MULTISCALE RETINEX THEORY to enhance a coloured image. in that theory i have to convolv grayscale image with gaussian function. i know i can use gaussian filter that exists in l.v. but my problem is that i have to give three different values of sigma and calculate three gaussian function and then convolve the image with these func separately. so i dont know how to use gaussian filter for these three scales. those are.. 5,80 and 255. i showed u the vi with first scale. as Klemen told that image get smooth through gaussian and blurred through avrage filter. but the result of my that code in matlab is a blurred image. plz tell me

1) is it an avrage filter or gaussian filter as i m using gaussian function?

2) can i use built in filters for this task with three different values of sigma?

3) u have removed fft that i applied on gaussian function but for convolving the two func we have to take fft of both and the multiply them,then why u have removed it?

 

thnx

Fairy

0 Kudos
Message 8 of 37
(17,322 Views)

hey Klemen!

 actually i have done element by element multiplication of matrix by converting it in array 🙂

0 Kudos
Message 9 of 37
(17,325 Views)

Hello fairy55,

 

I was refering to this piece of code in your first post:

 

array to array.png

 

You have array type as input and array type as output. Why using "matrix to array.vi"? You can just cast the datatype to double using numeric conversion pallete.

 

 

Smoothing is blurring:

http://docs.opencv.org/doc/tutorials/imgproc/gausian_median_blur_bilateral_filter/gausian_median_blu...

 

1. The 3D plot in one of my previous posts was plotted directly from the generated Gaussian distribution of Andrey_Dmitriev' code. So, yes you are using Gaussian.

 

2. You can generate your own kernel with the desired sigma value. Take a look at this examples:

http://stackoverflow.com/questions/8204645/implementing-gaussian-blur-how-to-calculate-convolution-m...

 

3. Andrey_Dmitriev already answered that question in his last post.

 

Ni Vision Concepts:

 

"In an image, details and sharp edges are associated with moderate to high spatial frequencies because they introduce significant gray-level variations over short distances. Gradually varying patterns are associated with low spatial frequencies."

 

So if you permorm FFT on an image and flip the frequencies correctly (low frequencies at the center) and apply the Gaussian, you are doing lowpass filtering - attenuate higher frequencies. You don't need to perform FFT on the Gaussian - a trick like Andrey_Dmitriev said.

 

Best regards,

 

 

 


https://decibel.ni.com/content/blogs/kl3m3n



"Kudos: Users may give one another Kudos on the forums for posts that they found particularly helpful or insightful."
0 Kudos
Message 10 of 37
(17,307 Views)