DSPRelated.com
Forums

Image filtering using Low Pass Hamming filter

Started by Unknown April 1, 2006
Hello all,
         I am trying to remove gaussian noise from a 2-D gray scale
image using low pass hamming filter.

I know I can generate the 1-D hamming filter using the equation. How
do I use that on the 2-D image.
 
I really need some help for this. 
 
Thanks in advance.

<aanand17@gmail.com> wrote in message 
news:1143873057.652570.89060@i39g2000cwa.googlegroups.com...
> Hello all, > I am trying to remove gaussian noise from a 2-D gray scale > image using low pass hamming filter. > > I know I can generate the 1-D hamming filter using the equation. How > do I use that on the 2-D image. > > I really need some help for this. > > Thanks in advance. >
http://www.logicdevices.com/support/appnotes/convolver.doc Fred
<aanand17@gmail.com> wrote in message 
news:1143873057.652570.89060@i39g2000cwa.googlegroups.com...
> Hello all, > I am trying to remove gaussian noise from a 2-D gray scale > image using low pass hamming filter. > > I know I can generate the 1-D hamming filter using the equation. How > do I use that on the 2-D image. > > I really need some help for this. > > Thanks in advance. >
And... http://www.ece.arizona.edu/~dial/ece533/notes11.pdf Fred
Fred Marshall wrote:
> <aanand17@gmail.com> wrote in message > news:1143873057.652570.89060@i39g2000cwa.googlegroups.com... > >>Hello all, >> I am trying to remove gaussian noise from a 2-D gray scale >>image using low pass hamming filter. >> >>I know I can generate the 1-D hamming filter using the equation. How >>do I use that on the 2-D image.
Fred, What is a Hamming filter? 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;
What I meant was FIR 2 D Hamming window.

I guess there are two methods.

One is to use the 1D window and convolve first horizontally then
vertically or viceversa


Other is to create a 2D window and convolve with the image.


Please correct me , if i am wrong.


Which of the above method is better( easier to implement ;) )


If i have an image of size 256*256, what size of hamming window should
I choose?


So the besic steps would be :
1. take FFT of the noisy image
2. take FFT of the hamming window
3. convolve the two
4. take IFFT 


Did I miss something?? 


Thanks for all your help.

I have formed a 2 D hamming window using the algo given below.
Algo:
1)  h[1][1 --> 32] = 1D hamming window
2) h[2][1--->32] = h[1][1 --> 32] ;
         |                        |
         |                        |
    h[32][1--->32] = h[32][1 --> 32] ;

3)  let h* = transpose of h
4) 2d hamming =  h x h* ( element by element multiplication)
5) Find the max of the 2d hamming matrix and divide all matrix elements
by it to normalize it.

When I convolved it with the noisy image, I am not getting anything
close to desired result.

Can someone tell , what is wrong and how can I correct it?

My code is:
hamm1=hamming(32);
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;

%fft_hamm2=fft2(norm_hamm2);

K=conv2(norm_hamm2,noisy_image);


Any help will be highly appreciated.

Thanks.

"Anand" <aanand17@gmail.com> wrote in message 
news:1144010847.824250.256950@e56g2000cwe.googlegroups.com...
>I have formed a 2 D hamming window using the algo given below. > Algo: > 1) h[1][1 --> 32] = 1D hamming window > 2) h[2][1--->32] = h[1][1 --> 32] ; > | | > | | > h[32][1--->32] = h[32][1 --> 32] ; > > 3) let h* = transpose of h > 4) 2d hamming = h x h* ( element by element multiplication) > 5) Find the max of the 2d hamming matrix and divide all matrix elements > by it to normalize it. > > When I convolved it with the noisy image, I am not getting anything > close to desired result.
Hmmmmm.... you have a noisy image and you want to filter it to reduce the noise, right? To "filter" generally means to remove certain frequency components. To filter out noise often means to lowpass or bandpass filter the data. In the case of a noisy image, this means getting rid of high frequencies most likely. A Hamming window is just that, a window. If you apply it in the spatial domain then it will have the affect of reducing leakage in the spatial frequency domain. But, what you want is a filter..... So, when might a Hamming window be a filter? Well, first let's notice that a Hamming window is shaped like a very gradual lowpass filter - even though it's normally applied in time or space for the reasons given above. But, what if you really mean to apply it as a lowpass filter? Then you do this: Apply the window in frequency. Not by convolving but by multiplying. This has the affect of removing high frequencies to a degree. It is the same as convolving the spatial data with a narrow kernel that tends to average data over a few pixels. Isn't that what you want? I leave the code up to you. Fred
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.

Thanks,
Anand.

"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