DSPRelated.com
Forums

Image filtering using Low Pass Hamming filter

Started by Unknown April 1, 2006
"Fred Marshall" <fmarshallx@remove_the_x.acm.org> wrote in message 
news:29mdnX9a2dlX_63ZnZ2dnUVZ_vGdnZ2d@centurytel.net...
> > "Anand" <aanand17@gmail.com> wrote in message > news:1144017442.084595.210550@u72g2000cwu.googlegroups.com... >> Thanks Fred for the explanation. >> >> I did try out in the frequency domain as well. >> >> The output after the filtering is completely washed out even here. >> >> I took the hamming order as 256, same as image, does that cause the >> problem? >> If I take a smaller value, there is an obvious mismatch between the >> size of the image and the filter. >> How can I overcome this? >> >> I am writing down my code so as to have a better understanding about >> what I have done. >> (2 D hamming window generated using the same algo. above) >> >> hamm1=hamming(256); >> len=length(hamm1); >> for i=1:len, >> for j=1:len, >> hamm2(j,i)=hamm1(j,1); >> end >> end >> hamm2d=hamm2.*hamm2'; >> hamm_max=max(max(hamm2)); >> norm_hamm2=hamm2d/hamm_max; >> h_fft=fft2(norm_hamm2); >> adj_h=abs(fftshift(h_fft)); >> >> >> fft_image=fft2(noisy_image); >> adj_noisy_image=fftshift(fft_image); >> >> output_image = abs(ifft2(ifftshift(adj_h.*adj_noisy_image))); >> >> Am i on the right track? If not, please tell me, what needs to be >> corrected. >> > > Anand, > > I generally don't read code.... > > What happens if you plot the hamming function you've generated? Do you > get something that tapers at the edges? That's what you want. > Except: > Then, you need to make sure that the filter is registered in frequency as > you'd want. > This means the peak is at zero frequency. > I don't often *do* 2-D FFTs so someone else can probably help you better > regarding registration. > I think that zero frequency would be at the upper left corner of the > matrix and will repeat near the upper end - in both dimensions. > If so, you may want to circularly rotate the filter by N/2 and N/2 so the > peak is at (1,1) and at (1,256) and at (256,1). > > For me, it's easier to visualize if the (0,0) frequency point is at > (128,128). Then the filter can be centered as well - which is what I > believe you have already. > You might try fftshift on the frequency content of the data and then > multiply by the filter and then ifftshift and then ifft2 ... something > like that. > > Fred
Anand, Well, I broke down and read the code and you should not be taking the fft of the filter. You need to use it to multiply in frequency unchanged. That's what I was trying to tell you before. Might I suggest you generate the interim result of the thus filtered / multiplied data in frequency so you can plot to see what it looks like before the shifting and ifft. If you put in a pure noise "image" it should be relatively flat in frequency and the result will have a countour that looks like a noisy version of the filter shape. Fred
Fred Marshall wrote:

   ...

> Anand, > > Well, I broke down and read the code and you should not be taking the fft of > the filter. You need to use it to multiply in frequency unchanged. That's > what I was trying to tell you before.
Fred, I smelled trouble when he first wrote about a Hamming "filter". He wants -- for lack of better knowledge of the spectra -- a lowpass filter, and not the one you're trying to help him make work. He probably wants a Gaussian, which is both circularly symmetric and separable. If Anand doesn't know what a separable 2D filter is, he should begin his attack on his problem by finding out. (It's in http://www.dspguide.com) Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Thanks Fred for taking time out to read the code and ur suggestions.
I am using 'cameraman.tif' image.

Earlier when using the 'fft' with hamming window , i was getting a
image with oval shaped black spot indicating the presence of the man in
the original image. the image looked free of the gaussian noise(grain
free) though.

Now that I have removed the 'fft' , I am getting a completely black
image with a lot of noise(grains).

I am sorry, i didn't completely understand the 2nd para of ur previous
post, what exactly u wanted me to do. Is it pollting the function, in
frequency domain using 'freqz' , I did that and the average magnitude
almost seem constant.

Thanks for the link Jerry.

I know what is seperable 2D filter.

It can be written as w(m,n)=w(m)w(n) and I know Gaussian is one kind.

But I am using a Hamming window low pass filter to remove the gaussian
noise from the image.

Is there a correlation? If it is, i dont know about that.

Thanks,
Anand

Anand wrote:
> Thanks for the link Jerry. > > I know what is seperable 2D filter. > > It can be written as w(m,n)=w(m)w(n) and I know Gaussian is one kind. > > But I am using a Hamming window low pass filter to remove the gaussian > noise from the image. > > Is there a correlation? If it is, i dont know about that.
A Hamming window is not, as far as I know, separable. A separable 2-D filter needs twice as many operations as the one-D prototype. A non-separable window squares the number of prototype operations. There are many windows -- read 'filter kernels' -- used to process images, some separable, some not. In my limited experience, I have not before seen a Hamming (raised cosine) window used or recommended. Why did you choose it? Gaussian noise has a uniform spectrum. If you remove all of it, you remove the picture too. If you use a sharp-cutoff filter that removes that portion of the image spectrum that is unneeded or is made useless by the noise, you will have removed some of the noise while retaining as much as possible of the image. The separable filters that I know which do this reasonably well are not circularly symmetric. Oh well! Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Jerry,
       As far as "why i chose it?" , coz I was asked to use "only" this
by my prof.

I guess they are more used in Biomedical imaging. I have read a few
article, using hamming window technique to remove noise from the image.

Though I dont know the complete procedure, how to do that still :) .

I was just playing with 'fwind2' function in Matlab, and for hamming ,
it gave quite a decent output, with my noisy image.

I am just trying to find out the details of the function.

I still wanted to work on the code that I was writing.

Just wanted to know if I m going on the right track.

I dont seem to get the result that I desire though.

Can anyone tell me, how can I make the output of the hamming window
symmetric.
I kno the function in Matlab gives the symmetric output by dafault.

I am writing the function on my own using its standard equation.

Thanks,
Anand


Anand wrote:
> > Jerry, > As far as "why i chose it?" , coz I was asked to use "only" this > by my prof. > > I guess they are more used in Biomedical imaging. I have read a few > article, using hamming window technique to remove noise from the image. > > Though I dont know the complete procedure, how to do that still :) . > > I was just playing with 'fwind2' function in Matlab, and for hamming , > it gave quite a decent output, with my noisy image.
See it wasn't that hard to explain the problem rather than ask why your solution isn't working without any clue as to the problem. So you have 2 tasks: one is to figure out what 'fwind2' does and to figure out what Hamming means in the context of that function. I don't speak Matlabese so I can't answer the question but I can guess what you did was apply the hamming window in the frequency domain with the window functions central hump centered at F0 and that produced a desirable result on your image in the spatial domain. This is a predictable result. The Hamming window you keep talking about could have been the well known 1D Hamming window applied separately as 2 orthogonal 1D windows or it could be a circular 2d window generated by sampling a revolved version of the 1d window. As it happens because of the shape of the window itself the difference between the 2 forms would be rather minor in much the same way that the difference between 2 Gausian windows generated by those 2 methods are very similar. Anyway the real problem here is you are not grasping a simple Fourier Transform property: the multiplication <-> convolution duality. That is multiplication in one domain equals convolution in the other. In your case you are getting confused as to which domain you want to have convolution and which multiplication. You need to achieve some grasp of this concept or you efforts will be just stabs in the dark. One thing I can tell you for sure. You do not want to multiply by a window function in the spatial domain. Even if that is what people often do it makes no sense in the context of what you are trying to achieve. So you want to apply your window function in the frequency domain. You may want to think about what that will accomplish. It will attenuate the higher frequency with less and less effect as you get closer to F0. It is equivalent to convolving your image by some kernel in the spatial domain that has the same effect on the frequency domain. So if your smart your first task would be to find out what the kernel of your window function looks like in the spatial domain. That is do an IDFT on the window function by itself. Good luck, -jim ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
basically what 'fwind2' does is to design a 2 D filter using the 2 D
window.

So what I have been trying to do is working only with window.

Was that the missing link?

Sorry...haven't been completely understand the working of 'fwind2' .

Still trying to figure out :)