Get an ImagePlus from one slice of a stack's ImagePlus ?

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

Get an ImagePlus from one slice of a stack's ImagePlus ?

lechristophe
Hi,

Sorry if this is a dumb question. What is the simplest way in
Java/Javascript to get a single-image ImagePus corresponding to one slice
inside another ImagePlus that is a stack ? I'd like to store and manipulate
single slices from a stack, but carry over all additional informations
(scale etc...).

Thanks for your help.

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

Re: Get an ImagePlus from one slice of a stack's ImagePlus ?

Stephan Saalfeld
You would make a new one with the calibration of the old one:

ImagePlus imp = IJ.getImage();
ImageStack stack = imp.getStack();
Calibration cal = imp.getCalibration();
ImagePlus newImp = new ImagePlus(
stack.getSliceLabel( i ),
stack.getProcessor( i ) );
newImp.setCalibration( cal );

Best,
Stephan




On Wed, 2012-07-04 at 16:09 +0200, Christophe Leterrier wrote:

> Hi,
>
> Sorry if this is a dumb question. What is the simplest way in
> Java/Javascript to get a single-image ImagePus corresponding to one slice
> inside another ImagePlus that is a stack ? I'd like to store and manipulate
> single slices from a stack, but carry over all additional informations
> (scale etc...).
>
> Thanks for your help.
>
> --
> 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: Get an ImagePlus from one slice of a stack's ImagePlus ?

Mohamed Tleis
In reply to this post by lechristophe
Hello Christoper,

here is a code example, i hope it will answer your question:

ImagePlus imp = new ImagePlus(" ...
ImageStack is = new ImageStack();
is = imp.getStack();
ImageProcessor ip = is.getProcessor(1); // specify number of slice
imp2.setProcessor(ip);

Best Regards,
Mohamed Tleis

On 07/04/2012 04:09 PM, Christophe Leterrier wrote:

> Hi,
>
> Sorry if this is a dumb question. What is the simplest way in
> Java/Javascript to get a single-image ImagePus corresponding to one slice
> inside another ImagePlus that is a stack ? I'd like to store and manipulate
> single slices from a stack, but carry over all additional informations
> (scale etc...).
>
> Thanks for your help.
>
> --
> 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: Get an ImagePlus from one slice of a stack's ImagePlus ?

lechristophe
In reply to this post by Stephan Saalfeld
Hi,

Thanks for the tip!
I also have found
sliceImp = new Duplicator().run(imp, sliceNumber, sliceNumber);
but yours seem more direct (does not rely on the Duplicator class)

Christophe


On Wed, Jul 4, 2012 at 4:32 PM, Stephan Saalfeld <[hidden email]>wrote:

> You would make a new one with the calibration of the old one:
>
> ImagePlus imp = IJ.getImage();
> ImageStack stack = imp.getStack();
> Calibration cal = imp.getCalibration();
> ImagePlus newImp = new ImagePlus(
> stack.getSliceLabel( i ),
> stack.getProcessor( i ) );
> newImp.setCalibration( cal );
>
> Best,
> Stephan
>
>
>
>
> On Wed, 2012-07-04 at 16:09 +0200, Christophe Leterrier wrote:
> > Hi,
> >
> > Sorry if this is a dumb question. What is the simplest way in
> > Java/Javascript to get a single-image ImagePus corresponding to one slice
> > inside another ImagePlus that is a stack ? I'd like to store and
> manipulate
> > single slices from a stack, but carry over all additional informations
> > (scale etc...).
> >
> > Thanks for your help.
> >
> > --
> > 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
|

How to get pixels on one line in 3D??

周鑫
In reply to this post by Mohamed Tleis
Hello,

I wonder if there is anything which allows me to get pixels on one line in 3D ?
For example, I want to get all the pixels from (0,0,0) on direction (0.1, 0.2, 0.1).
I did not find such a function in ImageStack.

Thanks for any helps.

Best regards, Xin

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

Re: How to get pixels on one line in 3D??

Thomas Boudier
Hi,

Something like that ?? Contact me for more details.

Thomas


  public double[] getLinePixelValue(int x0, int y0, int z0, int x1, int
y1, int z1)
         int dx = (x1 - x0);
         int dy = (y1 - y0);
         int dz = (z1 - z0);
         int dist = Math.max(Math.max(Math.abs(dx), Math.abs(dy)),
Math.abs(dz));

         double[] res = new double[dist];

         float xStep = dx / (float) dist;
         float yStep = dy / (float) dist;
         float zStep = dz / (float) dist;

         float posX, posY, posZ;

         for (int i = 0; i < dist; i++) {
             posX = x0 + (i * xStep);
             posY = y0 + (i * yStep);
             posZ = z0 + (i * zStep);

           res[i] = stack.getVoxel(posZ, posZ, posZ);
         }

         return res;
     }

Le 05/07/2012 12:56, 周鑫 a écrit :

> Hello,
>
> I wonder if there is anything which allows me to get pixels on one line in 3D ?
> For example, I want to get all the pixels from (0,0,0) on direction (0.1, 0.2, 0.1).
> I did not find such a function in ImageStack.
>
> Thanks for any helps.
>
> Best regards, Xin
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
   /**********************************************************/
      Thomas Boudier, MCU Université Pierre et Marie Curie,
      Modélisation Cellulaire et Imagerie Biologique (EE1),
      IFR 83, Bat B 7ème étage, porte 723, Campus Jussieu.
      Tel : 01 44 27 46 92   Fax : 01 44 27 22 91
/*******************************************************/

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

Re: How to get pixels on one line in 3D??

周鑫
Hi,

Thanks for the code.
Now I try to better understand it.

> double[] res = new double[dist];

You assumed that the biggest difference (in x, y, or z) can give the number of pixels on this line.....
But this can be not the case.

Actually, my application try to do a spiral scan, where for each direction, I submit a rayon. (in total 81 rayons)
Then I want those voxels that is on the rayon.
For example, compute the distance of one pixel to one rayon.
If the distance is < 0.5 voxel, I will assume that it is on the rayon.
The question is , go through all the voxels and check all the rayon is time comsumming.
So I ask if there is anything already there.

I guess I need to write it myself.
It should also include 3D interpolation somehow.

Best regards, Xin

> -----原始邮件-----
> 发件人: "Thomas Boudier" <[hidden email]>
> 发送时间: 2012年7月5日 星期四
> 收件人: [hidden email]
> 抄送:
> 主题: Re: How to get pixels on one line in 3D??
>
> Hi,
>
> Something like that ?? Contact me for more details.
>
> Thomas
>
>
>   public double[] getLinePixelValue(int x0, int y0, int z0, int x1, int
> y1, int z1)
>          int dx = (x1 - x0);
>          int dy = (y1 - y0);
>          int dz = (z1 - z0);
>          int dist = Math.max(Math.max(Math.abs(dx), Math.abs(dy)),
> Math.abs(dz));
>
>          double[] res = new double[dist];
>
>          float xStep = dx / (float) dist;
>          float yStep = dy / (float) dist;
>          float zStep = dz / (float) dist;
>
>          float posX, posY, posZ;
>
>          for (int i = 0; i < dist; i++) {
>              posX = x0 + (i * xStep);
>              posY = y0 + (i * yStep);
>              posZ = z0 + (i * zStep);
>
>            res[i] = stack.getVoxel(posZ, posZ, posZ);
>          }
>
>          return res;
>      }
>
> Le 05/07/2012 12:56, 周鑫 a écrit :
> > Hello,
> >
> > I wonder if there is anything which allows me to get pixels on one line in 3D ?
> > For example, I want to get all the pixels from (0,0,0) on direction (0.1, 0.2, 0.1).
> > I did not find such a function in ImageStack.
> >
> > Thanks for any helps.
> >
> > Best regards, Xin
> >
> > --
> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> >
>
> --
>    /**********************************************************/
>       Thomas Boudier, MCU Université Pierre et Marie Curie,
>       Modélisation Cellulaire et Imagerie Biologique (EE1),
>       IFR 83, Bat B 7ème étage, porte 723, Campus Jussieu.
>       Tel : 01 44 27 46 92   Fax : 01 44 27 22 91
> /*******************************************************/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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