Representing Phases and Doing Calculations with them in Images?

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

Representing Phases and Doing Calculations with them in Images?

Rebecca Keller
Dear ImageJ Community,

I've recently come across an interesting issue: representing phases an
image. I've got phase-images with ranges -pi to +pi radians, but the trick
is how to make this continuous range into a linear one. I.e., although the
phases (3.13 and -3.13) are actually very close in terms of phase, they are
far arithmetically, whereas (0.1 and -0.1) are just as close in phase but
are very close arithmetically. I am not sure how to combine the phases,
then, with non-cyclic information, like amplitude.

My goal here is to use the phases as a filter, presumably simply by
multiplying by the corresponding amplitudes, but for this, the closeness in
phase to some given value should be represented by the values in the image,
perhaps with the set value being the maximum? I guess this is equivalent to
rotating the phases, such that the preferred value is at the "top" of the
circle? But I can't think how to do this mathematically in the images.

All the best,

Jacob Keller

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Representing Phases and Doing Calculations with them in Images?

Herbie-4
Dear Jacob Keller,

is it possible that you speak of the phase of Fourier-spectra not images?

Images are generally positive-valued and sometimes real-valued but never
complex-valued. If you have a complex-valued 2D signal, it shouldn't be
called an image, and I would be very much interested in how it was
generated.

"use the phases as a filter"

What does that mean? What kind of filter? What for?

Somehow clueless

Herbie

::::::::::::::::::::::::::::::::::::::::
On 02.10.14 18:46, Rebecca Keller wrote:

> Dear ImageJ Community,
>
> I've recently come across an interesting issue: representing phases an
> image. I've got phase-images with ranges -pi to +pi radians, but the trick
> is how to make this continuous range into a linear one. I.e., although the
> phases (3.13 and -3.13) are actually very close in terms of phase, they are
> far arithmetically, whereas (0.1 and -0.1) are just as close in phase but
> are very close arithmetically. I am not sure how to combine the phases,
> then, with non-cyclic information, like amplitude.
>
> My goal here is to use the phases as a filter, presumably simply by
> multiplying by the corresponding amplitudes, but for this, the closeness in
> phase to some given value should be represented by the values in the image,
> perhaps with the set value being the maximum? I guess this is equivalent to
> rotating the phases, such that the preferred value is at the "top" of the
> circle? But I can't think how to do this mathematically in the images.
>
> All the best,
>
> Jacob Keller

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Representing Phases and Doing Calculations with them in Images?

Michael Schmid
In reply to this post by Rebecca Keller
Hi Jacob,

It is not really clear to me what you want: Filter the image with the phase?

Then, one way might be converting the phase to two channels, sin(phase) and cos(phase).
Then you can e.g. filter both the sin and cos channels, and use the atan2 function to recover the phase from the two filtered images.

Or do you just want to rotate the phase such that the 'typical' value is 0?
Then take the average over the sin(phase) and cos(phase) values, use atan2 on the result to get the 'typical phase', and subtract it from all phases. Thereafter loop through all pixels, subtract 2*pi from those above pi, and add 2*pi to those below -pi.

Michael
________________________________________________________________
On Oct 2, 2014, at 18:46, Rebecca Keller wrote:

> Dear ImageJ Community,
>
> I've recently come across an interesting issue: representing phases an
> image. I've got phase-images with ranges -pi to +pi radians, but the trick
> is how to make this continuous range into a linear one. I.e., although the
> phases (3.13 and -3.13) are actually very close in terms of phase, they are
> far arithmetically, whereas (0.1 and -0.1) are just as close in phase but
> are very close arithmetically. I am not sure how to combine the phases,
> then, with non-cyclic information, like amplitude.
>
> My goal here is to use the phases as a filter, presumably simply by
> multiplying by the corresponding amplitudes, but for this, the closeness in
> phase to some given value should be represented by the values in the image,
> perhaps with the set value being the maximum? I guess this is equivalent to
> rotating the phases, such that the preferred value is at the "top" of the
> circle? But I can't think how to do this mathematically in the images.
>
> All the best,
>
> Jacob Keller

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Representing Phases and Doing Calculations with them in Images?

Rebecca Keller
Okay, sorry, let me be a little clearer: I've used Jay Unruh's excellent
plugin (I will never stop complimenting his amazing plugins!) for temporal
FFTs of timelapses, and since my signal is periodic and of known frequency
and phase, I can use that information to filter out tons of noise,
analogous to so-called "lock-in" amplifiers--manuscript in preparation, so
stay tuned if you're interested! Since to my knowledge there is no way to
"notch filter" the signal over time, I use the phase and amplitude values
(represented as images) at stimulus frequency from the Fourier stack to do
this (there are two other plugins to extract the amplitude and phase info
from the FFT stack). The problem is, however, that often the desired phases
are some arbitrary, non-zero value, which makes combination with the
amplitude information difficult. Ideally, I would like to be able to have
an image representing "phase difference from x" (where x is the signal
phase) to combine with the amplitude info, or approximately similarly,
shift the phase of my signal to, say, 0, and shift all other phases
accordingly.

JPK


On Thu, Oct 2, 2014 at 1:15 PM, Michael Schmid <[hidden email]>
wrote:

> Hi Jacob,
>
> It is not really clear to me what you want: Filter the image with the
> phase?
>
> Then, one way might be converting the phase to two channels, sin(phase)
> and cos(phase).
> Then you can e.g. filter both the sin and cos channels, and use the atan2
> function to recover the phase from the two filtered images.
>
> Or do you just want to rotate the phase such that the 'typical' value is 0?
> Then take the average over the sin(phase) and cos(phase) values, use atan2
> on the result to get the 'typical phase', and subtract it from all phases.
> Thereafter loop through all pixels, subtract 2*pi from those above pi, and
> add 2*pi to those below -pi.
>
> Michael
> ________________________________________________________________
> On Oct 2, 2014, at 18:46, Rebecca Keller wrote:
>
> > Dear ImageJ Community,
> >
> > I've recently come across an interesting issue: representing phases an
> > image. I've got phase-images with ranges -pi to +pi radians, but the
> trick
> > is how to make this continuous range into a linear one. I.e., although
> the
> > phases (3.13 and -3.13) are actually very close in terms of phase, they
> are
> > far arithmetically, whereas (0.1 and -0.1) are just as close in phase but
> > are very close arithmetically. I am not sure how to combine the phases,
> > then, with non-cyclic information, like amplitude.
> >
> > My goal here is to use the phases as a filter, presumably simply by
> > multiplying by the corresponding amplitudes, but for this, the closeness
> in
> > phase to some given value should be represented by the values in the
> image,
> > perhaps with the set value being the maximum? I guess this is equivalent
> to
> > rotating the phases, such that the preferred value is at the "top" of the
> > circle? But I can't think how to do this mathematically in the images.
> >
> > All the best,
> >
> > Jacob Keller
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Representing Phases and Doing Calculations with them in Images?

Saalfeld, Stephan
This Beanshell script calculates the pixel-wise absolute radial
difference of a stack with two slices, each of them storing 32bit angle
values in radians in the range [-Pi, Pi], with ImageJ's built in image
calculators:


import ij.*;
import ij.process.*;
import java.lang.Math;

imp = IJ.getImage();
a = imp.getStack().getProcessor(1).convertToFloatProcessor();
b = imp.getStack().getProcessor(2).convertToFloatProcessor();

/* sort large values to b, small values to a */
c = a.duplicate();
a.copyBits(b, 0, 0, Blitter.MIN);
b.copyBits(c, 0, 0, Blitter.MAX);

/* b - a */
c = b.duplicate();
c.copyBits(a, 0, 0, Blitter.SUBTRACT);

/* a + PI - b */
d = a.duplicate();
d.add(2 * Math.PI);
d.copyBits(b, 0, 0, Blitter.SUBTRACT);

/* min */
d.copyBits(c, 0, 0, Blitter.MIN);

/* show */

new ImagePlus("radial difference", d).show();


Best,
Stephan



On Thu, 2014-10-02 at 14:48 -0400, Rebecca Keller wrote:

> Okay, sorry, let me be a little clearer: I've used Jay Unruh's excellent
> plugin (I will never stop complimenting his amazing plugins!) for temporal
> FFTs of timelapses, and since my signal is periodic and of known frequency
> and phase, I can use that information to filter out tons of noise,
> analogous to so-called "lock-in" amplifiers--manuscript in preparation, so
> stay tuned if you're interested! Since to my knowledge there is no way to
> "notch filter" the signal over time, I use the phase and amplitude values
> (represented as images) at stimulus frequency from the Fourier stack to do
> this (there are two other plugins to extract the amplitude and phase info
> from the FFT stack). The problem is, however, that often the desired phases
> are some arbitrary, non-zero value, which makes combination with the
> amplitude information difficult. Ideally, I would like to be able to have
> an image representing "phase difference from x" (where x is the signal
> phase) to combine with the amplitude info, or approximately similarly,
> shift the phase of my signal to, say, 0, and shift all other phases
> accordingly.
>
> JPK
>
>
> On Thu, Oct 2, 2014 at 1:15 PM, Michael Schmid <[hidden email]>
> wrote:
>
> > Hi Jacob,
> >
> > It is not really clear to me what you want: Filter the image with the
> > phase?
> >
> > Then, one way might be converting the phase to two channels, sin(phase)
> > and cos(phase).
> > Then you can e.g. filter both the sin and cos channels, and use the atan2
> > function to recover the phase from the two filtered images.
> >
> > Or do you just want to rotate the phase such that the 'typical' value is 0?
> > Then take the average over the sin(phase) and cos(phase) values, use atan2
> > on the result to get the 'typical phase', and subtract it from all phases.
> > Thereafter loop through all pixels, subtract 2*pi from those above pi, and
> > add 2*pi to those below -pi.
> >
> > Michael
> > ________________________________________________________________
> > On Oct 2, 2014, at 18:46, Rebecca Keller wrote:
> >
> > > Dear ImageJ Community,
> > >
> > > I've recently come across an interesting issue: representing phases an
> > > image. I've got phase-images with ranges -pi to +pi radians, but the
> > trick
> > > is how to make this continuous range into a linear one. I.e., although
> > the
> > > phases (3.13 and -3.13) are actually very close in terms of phase, they
> > are
> > > far arithmetically, whereas (0.1 and -0.1) are just as close in phase but
> > > are very close arithmetically. I am not sure how to combine the phases,
> > > then, with non-cyclic information, like amplitude.
> > >
> > > My goal here is to use the phases as a filter, presumably simply by
> > > multiplying by the corresponding amplitudes, but for this, the closeness
> > in
> > > phase to some given value should be represented by the values in the
> > image,
> > > perhaps with the set value being the maximum? I guess this is equivalent
> > to
> > > rotating the phases, such that the preferred value is at the "top" of the
> > > circle? But I can't think how to do this mathematically in the images.
> > >
> > > All the best,
> > >
> > > Jacob Keller
> >
> > --
> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> >
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Representing Phases and Doing Calculations with them in Images?

Rebecca Keller
Hah! Awesome! Thanks so much Stephan--this ought to do it! If I understand
the code right (I've never used beanshell) you're taking the minimum of the
two distances around the phase circle, correct? If so, very elegant!

But there is one thing:

I'd like to enter a value for the phase manually, such as 0.726, then find
phase differences from this value. I could use your code, but need to make
an image with all pixels at this value, I guess, which I don't know how to
do--never had to do this weird sort of thing. I figured out a clever
(kludgy) way to make one, but there must be some simple way to make an
image with appropriate constant pixel value. Alternatively, I guess the
code could be modified to just take a constant value instead of the second
image, but I am not sure how to modify this correctly. I will take a shot
at it if I don't hear from you.

It would be really cool to have a little dial or slider which would
calculate this on the fly (pixel-wise phase difference between phase image
and reference phase), but I am not sure who would really use it besides me!

All the best, and thanks a lot for this!

Jacob





On Thu, Oct 2, 2014 at 3:39 PM, Stephan Saalfeld <[hidden email]
> wrote:

> This Beanshell script calculates the pixel-wise absolute radial
> difference of a stack with two slices, each of them storing 32bit angle
> values in radians in the range [-Pi, Pi], with ImageJ's built in image
> calculators:
>
>
> import ij.*;
> import ij.process.*;
> import java.lang.Math;
>
> imp = IJ.getImage();
> a = imp.getStack().getProcessor(1).convertToFloatProcessor();
> b = imp.getStack().getProcessor(2).convertToFloatProcessor();
>
> /* sort large values to b, small values to a */
> c = a.duplicate();
> a.copyBits(b, 0, 0, Blitter.MIN);
> b.copyBits(c, 0, 0, Blitter.MAX);
>
> /* b - a */
> c = b.duplicate();
> c.copyBits(a, 0, 0, Blitter.SUBTRACT);
>
> /* a + PI - b */
> d = a.duplicate();
> d.add(2 * Math.PI);
> d.copyBits(b, 0, 0, Blitter.SUBTRACT);
>
> /* min */
> d.copyBits(c, 0, 0, Blitter.MIN);
>
> /* show */
>
> new ImagePlus("radial difference", d).show();
>
>
> Best,
> Stephan
>
>
>
> On Thu, 2014-10-02 at 14:48 -0400, Rebecca Keller wrote:
> > Okay, sorry, let me be a little clearer: I've used Jay Unruh's excellent
> > plugin (I will never stop complimenting his amazing plugins!) for
> temporal
> > FFTs of timelapses, and since my signal is periodic and of known
> frequency
> > and phase, I can use that information to filter out tons of noise,
> > analogous to so-called "lock-in" amplifiers--manuscript in preparation,
> so
> > stay tuned if you're interested! Since to my knowledge there is no way to
> > "notch filter" the signal over time, I use the phase and amplitude values
> > (represented as images) at stimulus frequency from the Fourier stack to
> do
> > this (there are two other plugins to extract the amplitude and phase info
> > from the FFT stack). The problem is, however, that often the desired
> phases
> > are some arbitrary, non-zero value, which makes combination with the
> > amplitude information difficult. Ideally, I would like to be able to have
> > an image representing "phase difference from x" (where x is the signal
> > phase) to combine with the amplitude info, or approximately similarly,
> > shift the phase of my signal to, say, 0, and shift all other phases
> > accordingly.
> >
> > JPK
> >
> >
> > On Thu, Oct 2, 2014 at 1:15 PM, Michael Schmid <[hidden email]>
> > wrote:
> >
> > > Hi Jacob,
> > >
> > > It is not really clear to me what you want: Filter the image with the
> > > phase?
> > >
> > > Then, one way might be converting the phase to two channels, sin(phase)
> > > and cos(phase).
> > > Then you can e.g. filter both the sin and cos channels, and use the
> atan2
> > > function to recover the phase from the two filtered images.
> > >
> > > Or do you just want to rotate the phase such that the 'typical' value
> is 0?
> > > Then take the average over the sin(phase) and cos(phase) values, use
> atan2
> > > on the result to get the 'typical phase', and subtract it from all
> phases.
> > > Thereafter loop through all pixels, subtract 2*pi from those above pi,
> and
> > > add 2*pi to those below -pi.
> > >
> > > Michael
> > > ________________________________________________________________
> > > On Oct 2, 2014, at 18:46, Rebecca Keller wrote:
> > >
> > > > Dear ImageJ Community,
> > > >
> > > > I've recently come across an interesting issue: representing phases
> an
> > > > image. I've got phase-images with ranges -pi to +pi radians, but the
> > > trick
> > > > is how to make this continuous range into a linear one. I.e.,
> although
> > > the
> > > > phases (3.13 and -3.13) are actually very close in terms of phase,
> they
> > > are
> > > > far arithmetically, whereas (0.1 and -0.1) are just as close in
> phase but
> > > > are very close arithmetically. I am not sure how to combine the
> phases,
> > > > then, with non-cyclic information, like amplitude.
> > > >
> > > > My goal here is to use the phases as a filter, presumably simply by
> > > > multiplying by the corresponding amplitudes, but for this, the
> closeness
> > > in
> > > > phase to some given value should be represented by the values in the
> > > image,
> > > > perhaps with the set value being the maximum? I guess this is
> equivalent
> > > to
> > > > rotating the phases, such that the preferred value is at the "top"
> of the
> > > > circle? But I can't think how to do this mathematically in the
> images.
> > > >
> > > > All the best,
> > > >
> > > > Jacob Keller
> > >
> > > --
> > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> > >
> >
> > --
> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html