Is it possible to calculate the phase image with the
FFT command in Process/FFT and use it along with a modified power spectrum to apply the inverse FFT? I know there is an inverse FFT procedure in the menu, but I need to apply a different operation to the power spectrum than the ones implemented. Also, why can the FFT command process images of any size? Is this because it is actually not using FFT but Fast Hartley Transform? Thanks Agus -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Agus,
you may have a look at the IJ-plugin "ParallelFFTJ" that does what you want but be aware that you can't control it from IJ-macros! Furthermore, be aware that "ParallelFFTJ" works with any image size but then uses the common DFT, not the FFT-algorithm, i.e. it is rather slow. That said, use it with square-sized images having side-lengths of a power of 2. HTH Herbie _________________________________ On 11.02.13 23:17, Agustin Lobo wrote: > Is it possible to calculate the phase image with the > FFT command in Process/FFT and use it > along with a modified power spectrum to apply the inverse > FFT? I know there is an inverse FFT procedure in the menu, > but I need to apply a different operation to the > power spectrum than the ones implemented. > > Also, why can the FFT command process images of any size? > Is this because it is actually not using FFT but Fast Hartley Transform? > > Thanks > Agus > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Agustin Lobo
Hi Agus,
if you want to do a simple multiplication (filtering in the frequency domain) on the power spectrum, you can use Process>FFT>Custom Filter. rsb.info.nih.gov/ij/docs/guide/146-29.html#toc-Subsection-29.10 It only works for multiplication with positive values, however, and it is limited to 8-bit values to multiply with. For other operations, it is easy to write a plugin that accesses the pixels of the FHT and modifies them: FHT fht = new FHT(ip); fht.transform(); float[] fhtPixels = (float[])(fht.getPixels()); If you want to keep the phase the same, just make sure that you multiply the value at (x,y) and (size-x, size-y) with the same value; with 'size' being the width and height of the FFT (in other words, keep the ratio between these two values constant). This code would be useful if you want to modify a few isolated x, y values of the FFT: int mask = size-1; //&mask is faster version of modulo size int p1 = (x&mask) + (y&mask)*size; int p2 = ((size-x)&mask) + ((size-y)&mask)*size; fhtPixels[p1] *= myFactor(x,y); fhtPixels[p2] *= myFactor(x,y); The power spectrum at that position would be sqr(fhtPixels[p1]) + sqr(fhtPixels[p2]) -- For image sizes that are not a power of 2, ImageJ uses padding to the next size being a power of 2. The simple FFT command simply fills the remaining part of the image with the average value of the original image. For filtering operations, this would lead to artifacts at the edges, similar to the artifacts that would occur with images having a size of 2^n, but not having periodic boundary values. Therefore, the FFT filters add a mirrored part of the original image at the outside where padding is required (even if the size is a power of 2; so it actually uses a larger size). Thus, edge artifacts will hardly ever occur. Michael ________________________________________________________________ On Feb 11, 2013, at 23:17, Agustin Lobo wrote: > Is it possible to calculate the phase image with the > FFT command in Process/FFT and use it > along with a modified power spectrum to apply the inverse > FFT? I know there is an inverse FFT procedure in the menu, > but I need to apply a different operation to the > power spectrum than the ones implemented. > > Also, why can the FFT command process images of any size? > Is this because it is actually not using FFT but Fast Hartley Transform? > > Thanks > Agus -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thank you all for your feedback.
I've found the contributed FFT plugin by Stephan Preibisch http://fly.mpi-cbg.de/~preibisch/software.html which is available in the Fiji distribution. I can get the phase and power spectrum images with it. The only problem is that the inverse FFT outputs a padded version of the input, but as all the images I have to deal with have the same size, this is easily solved within a macro. Agus On Tue, Feb 12, 2013 at 1:39 PM, Michael Schmid <[hidden email]> wrote: > Hi Agus, > > if you want to do a simple multiplication (filtering in the frequency domain) on the power spectrum, you can use Process>FFT>Custom Filter. > rsb.info.nih.gov/ij/docs/guide/146-29.html#toc-Subsection-29.10 > It only works for multiplication with positive values, however, and it is limited to 8-bit values to multiply with. > > For other operations, it is easy to write a plugin that accesses the pixels of the FHT and modifies them: > > FHT fht = new FHT(ip); > fht.transform(); > float[] fhtPixels = (float[])(fht.getPixels()); > If you want to keep the phase the same, just make sure that you multiply the value at (x,y) and (size-x, size-y) with the same value; with 'size' being the width and height of the FFT (in other words, keep the ratio between these two values constant). This code would be useful if you want to modify a few isolated x, y values of the FFT: > int mask = size-1; //&mask is faster version of modulo size > int p1 = (x&mask) + (y&mask)*size; > int p2 = ((size-x)&mask) + ((size-y)&mask)*size; > fhtPixels[p1] *= myFactor(x,y); > fhtPixels[p2] *= myFactor(x,y); > The power spectrum at that position would be sqr(fhtPixels[p1]) + sqr(fhtPixels[p2]) > > -- > > For image sizes that are not a power of 2, ImageJ uses padding to the next size being a power of 2. The simple FFT command simply fills the remaining part of the image with the average value of the original image. For filtering operations, this would lead to artifacts at the edges, similar to the artifacts that would occur with images having a size of 2^n, but not having periodic boundary values. > > Therefore, the FFT filters add a mirrored part of the original image at the outside where padding is required (even if the size is a power of 2; so it actually uses a larger size). Thus, edge artifacts will hardly ever occur. > > Michael > ________________________________________________________________ > On Feb 11, 2013, at 23:17, Agustin Lobo wrote: > >> Is it possible to calculate the phase image with the >> FFT command in Process/FFT and use it >> along with a modified power spectrum to apply the inverse >> FFT? I know there is an inverse FFT procedure in the menu, >> but I need to apply a different operation to the >> power spectrum than the ones implemented. >> >> Also, why can the FFT command process images of any size? >> Is this because it is actually not using FFT but Fast Hartley Transform? >> >> Thanks >> Agus > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |