Fourier transform and filtering

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Fourier transform and filtering

Antonio
Hi, I'm recently working with the options "FFT->custom filter" of ImageJ.

My goal is to extract from an image only a selected spatial frequency, then transform the image again to obtain the real space distribution of that frequency. As custom filters, I use rings of the radius of interest and 2-5 pixels large.
But if I execute the command "custom filter", I don't obtain back the same image I would by manually perform the filtering. That's to say: I transform an image, then overlay the filter (with "image processor->AND"), then transform again the result. The final image is totally different from what I get with built-in filtering.

Is not clear to me whence this difference should arise, as the "AND" operator between the filter and the transformed image is actually like a multiplication for a step-function (or square wave) in the frequency domain, that's to say a convolution in real space.
I guess there's some other operations or normalization ImgeJ performs while filtering, and I'd need to know some more details about that, to know how to interpret my result.

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Fourier transform and filtering

Michael Schmid
Hi Antonio,

there are quite a few differences between "bandpass filter" and  
selecting frequencies in the Fourier domain or "custom filter":

First, it is very important to note that the values (in pixels) in  
"Bandpass filter" are *half* of the spatial frequencies that you can  
read from the status line when moving the cursor over the FFT image.
That's because "structure size" means size of, e.g., a bright  
particle; and the lowest strong Fourier component is that where the  
upper half-cycle of the sinewave corresponds to the particle, the  
negative "surrounding" correspond to the background.

Just in case this is not clear: The values in pixels in "bandpass  
filters" are in real space, i.e., pixels of the image. The scale of  
the custom filter is in frequency space. 1 pixel from the origin  
(center) corresponds to one period per image size, 2 pixels from the  
origin corresponds to two cycles per image size, etc. For images that  
are not 2^n*2^n, "image size" here means the lowest value of 2^n that  
is not smaller than width and height.

If you run "FFT" or "Custom Filter" you will get edge artifacts,  
usually visible in the power spectrum as horizontal and vertical  
lines through the origin (center). The bandpass filter in ImageJ  
continues the image outside the image area with its mirrored  
counterpart to avoid any jumps at the edges, greatly reducing such  
artifacts.
When selecting "Display Filter" of the bandpass filter, with image  
sizes of 2^n or somewhat smaller, you will also see that the filter  
size (equal to the size of the input image) is 2*2^n, due to the  
space needed for the mirrored-image continuation. In this case, you  
have to downscale the filter created by "Display Filter" by a factor  
of 2 before using it as a custom filter.

"Bandpass filter" uses very soft cutoff. You will see this when  
selecting "Display Filter". If the lower and higher cut-off frequency  
are not very different (by factor of, say, 5 or more), even  
frequencies in the center of the band will be noticeably attenuated.

"Bandpass filter" passes spatial frequency 0 unattanuated, i.e., it  
does not change the average gray level of an image.

Hope this helps,

Michael
________________________________________________________________

On 29 Oct 2008, at 13:24, Antonio wrote:

> Hi, I'm recently working with the options "FFT->custom filter" of  
> ImageJ.
>
> My goal is to extract from an image only a selected spatial  
> frequency, then
> transform the image again to obtain the real space distribution of  
> that
> frequency. As custom filters, I use rings of the radius of interest  
> and 2-5
> pixels large.
> But if I execute the command "custom filter", I don't obtain back  
> the same
> image I would by manually perform the filtering. That's to say: I  
> transform
> an image, then overlay the filter (with "image processor->AND"), then
> transform again the result. The final image is totally different  
> from what I
> get with built-in filtering.
>
> Is not clear to me whence this difference should arise, as the "AND"
> operator between the filter and the transformed image is actually  
> like a
> multiplication for a step-function (or square wave) in the  
> frequency domain,
> that's to say a convolution in real space.
> I guess there's some other operations or normalization ImgeJ  
> performs while
> filtering, and I'd need to know some more details about that, to  
> know how to
> interpret my result.
>
> Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Fourier transform and filtering

Antonio
Michael Schmid-3 wrote
First, it is very important to note that the values (in pixels) in  
"Bandpass filter" are *half* of the spatial frequencies that you can  
read from the status line when moving the cursor over the FFT image.
That's because "structure size" means size of, e.g., a bright  
particle; and the lowest strong Fourier component is that where the  
upper half-cycle of the sinewave corresponds to the particle, the  
negative "surrounding" correspond to the background.

Just in case this is not clear: The values in pixels in "bandpass  
filters" are in real space, i.e., pixels of the image. The scale of  
the custom filter is in frequency space. 1 pixel from the origin  
(center) corresponds to one period per image size, 2 pixels from the  
origin corresponds to two cycles per image size, etc. For images that  
are not 2^n*2^n, "image size" here means the lowest value of 2^n that  
'is not smaller than width and height.
Thanks for replying.

Concerning the right frequencies to select, I dealt directly with the problem doing the following: before taking the pictures of interest, I shot one of an object of known size, so I know the actual ratio pixel/cm. Then, the smallest wave vector allowed in my system being q_min = 2*3,14/(image_size_cm), each pixel of the transformed image (or of the filter) will correspond to a wave vector of q = q_min*(pixel_from_center)*R.
R has to be equal to (image_size)/(transformed_size), so on the borders of the transformed image I can retrieve half the maximum wave vector allowed, since to span the whole spectrum both -q and +q are needed.
With this, I can arrange a custom filter at the right frequency, or check the wave vectors selected by a given bandpass filter. So, if I'm not doing a mistake, this way of using a filter should yield the right frequency.
I tested this calibration by transforming via FFT a dummy circle, then obtaining an Airy frequency pattern and eventually checking the position of the first dark ring (it occurs at pixels which 'carry' a wave vector value in accord with theory).

If you run "FFT" or "Custom Filter" you will get edge artifacts,  
usually visible in the power spectrum as horizontal and vertical  
lines through the origin (center). The bandpass filter in ImageJ  
continues the image outside the image area with its mirrored  
counterpart to avoid any jumps at the edges, greatly reducing such  
artifacts.
When selecting "Display Filter" of the bandpass filter, with image  
sizes of 2^n or somewhat smaller, you will also see that the filter  
size (equal to the size of the input image) is 2*2^n, due to the  
space needed for the mirrored-image continuation. In this case, you  
have to downscale the filter created by "Display Filter" by a factor  
of 2 before using it as a custom filter.
I started using bandpass filtering, then I switched to custom filtering for at least two reason: one of my purposes is to effectively remove the 0-frequency component, and I found the filters provided rather too spread (the cutoff is too soft, as you said).
I was unaware of the bandpass 'size duplication', but it is still a little unclear to me.
Do you mean that the bandpass filtering actually doubles the allowed frequency range, so to reduce the edge noise, or that the real image is padded so to place the 'true' pixels in a range of spatial structures that are better reconstructed?
Still, if it's a matter of avoiding artifacts, or rescaling by 2 the bandpass filter, I'm not so sure it can fully account for the inconsistency I see (as I simply tried to make manually the same frequency selection that 'custom filter' should be performing *as far as I know*); anyway your explanation has been useful, I'm going to do a bit of work on bandpass filtering as well.

Antonio
Reply | Threaded
Open this post in threaded view
|

Re: Fourier transform and filtering

Michael Schmid
Hi Antonio,

concerning the size duplication:

The image is expanded to the smallest 2^n size that is larger than  
1.5 times the maximum of image width and image height.

Examples:
150*160 pixels -> max=160; 160*1.5=240. Will be expanded to 256*256
180*160 pixels -> max=180; 180*1.5=270. Will be expanded to 512*512

The code is in
   http://rsb.info.nih.gov/ij/source/ij/plugin/filter/FFTFilter.java

int maxN = Math.max(roiRect.width, roiRect.height);
int i=2;
while(i<1.5 * maxN) i *= 2;

Michael
________________________________________________________________

On 29 Oct 2008, at 22:41, Antonio wrote:

> Michael Schmid-3 wrote:
>>
>> First, it is very important to note that the values (in pixels) in
>> "Bandpass filter" are *half* of the spatial frequencies that you can
>> read from the status line when moving the cursor over the FFT image.
>> That's because "structure size" means size of, e.g., a bright
>> particle; and the lowest strong Fourier component is that where the
>> upper half-cycle of the sinewave corresponds to the particle, the
>> negative "surrounding" correspond to the background.
>>
>> Just in case this is not clear: The values in pixels in "bandpass
>> filters" are in real space, i.e., pixels of the image. The scale of
>> the custom filter is in frequency space. 1 pixel from the origin
>> (center) corresponds to one period per image size, 2 pixels from the
>> origin corresponds to two cycles per image size, etc. For images that
>> are not 2^n*2^n, "image size" here means the lowest value of 2^n that
>> 'is not smaller than width and height.
>>
>
> Thanks for replying.
>
> Concerning the right frequencies to select, I dealt directly with the
> problem doing the following: before taking the pictures of  
> interest, I shot
> one of an object of known size, so I know the actual ratio pixel/
> cm. Then,
> the smallest wave vector allowed in my system being q_min =
> 2*3,14/(image_size_cm), each pixel of the transformed image (or of the
> filter) will correspond to a wave vector of q = q_min*
> (pixel_from_center)*R.
> R has to be equal to (image_size)/(transformed_size), so on the  
> borders of
> the transformed image I can retrieve half the maximum wave vector  
> allowed,
> since to span the whole spectrum both -q and +q are needed.
> With this, I can arrange a custom filter at the right frequency, or  
> check
> the wave vectors selected by a given bandpass filter. So, if I'm  
> not doing a
> mistake, this way of using a filter should yield the right frequency.
> I tested this calibration by transforming via FFT a dummy circle, then
> obtaining an Airy frequency pattern and eventually checking the  
> position of
> the first dark ring (it occurs at pixels which 'carry' a wave  
> vector value
> in accord with theory).
>
>
>
>> If you run "FFT" or "Custom Filter" you will get edge artifacts,
>> usually visible in the power spectrum as horizontal and vertical
>> lines through the origin (center). The bandpass filter in ImageJ
>> continues the image outside the image area with its mirrored
>> counterpart to avoid any jumps at the edges, greatly reducing such
>> artifacts.
>> When selecting "Display Filter" of the bandpass filter, with image
>> sizes of 2^n or somewhat smaller, you will also see that the filter
>> size (equal to the size of the input image) is 2*2^n, due to the
>> space needed for the mirrored-image continuation. In this case, you
>> have to downscale the filter created by "Display Filter" by a factor
>> of 2 before using it as a custom filter.
>>
>
> I started using bandpass filtering, then I switched to custom  
> filtering for
> at least two reason: one of my purposes is to effectively remove the
> 0-frequency component, and I found the filters provided rather too  
> spread
> (the cutoff is too soft, as you said).
> I was unaware of the bandpass 'size duplication', but it is still a  
> little
> unclear to me.
> Do you mean that the bandpass filtering actually doubles the allowed
> frequency range, so to reduce the edge noise, or that the real  
> image is
> padded so to place the 'true' pixels in a range of spatial  
> structures that
> are better reconstructed?
> Still, if it's a matter of avoiding artifacts, or rescaling by 2 the
> bandpass filter, I'm not so sure it can fully account for the  
> inconsistency
> I see (as I simply tried to make manually the same frequency  
> selection that
> 'custom filter' should be performing *as far as I know*); anyway your
> explanation has been useful, I'm going to do a bit of work on bandpass
> filtering as well.
>
> Antonio
>
> --
> View this message in context: http://n2.nabble.com/Fourier- 
> transform-and-filtering-tp1393214p1395497.html
> Sent from the ImageJ mailing list archive at Nabble.com.