05-28-2013 01:41 PM
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
05-29-2013 01:29 AM - edited 05-29-2013 01:29 AM
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,
05-29-2013 06:06 PM - edited 05-29-2013 06:11 PM
@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:
Result:
@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:
Result:
Andrey.
05-30-2013 12:39 AM
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,
05-30-2013 01:52 AM
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:
So sigmax = sigmay = sqrt(125) and A = 1 in your example.
Also plotting the distribution gives the bell shaped characteristic:
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,
05-30-2013 02:33 AM - edited 05-30-2013 02:51 AM
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:
and results:
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.
05-30-2013 02:45 AM - edited 05-30-2013 02:45 AM
Thank you very much for the clear explanation.
I understand this now!!!
Best regards,
05-30-2013 01:08 PM - edited 05-30-2013 01:22 PM
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
05-30-2013 01:11 PM
hey Klemen!
actually i have done element by element multiplication of matrix by converting it in array 🙂
05-31-2013 12:38 AM - edited 05-31-2013 12:38 AM
Hello fairy55,
I was refering to this piece of code in your first post:
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:
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:
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,