Working with stacks

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

Working with stacks

Juanjo Vega
Hello everyone, I want to copy a ROI from a stack of images.

The idea is to select a rectangle from the stack of images and then,
when a button is pressed, a new image containing the stack of ROIs is
created.

I'm doing this, but it doesn't works (only the first image is created).
The problem is that I don't know where to find some help about how to
work with stacks to get a slice, replace, add a new one, or whatever.

Right now I'm doing this, but I tried many other stuff without success:
 
       Roi roi = IJ.getImage().getRoi();

        Point a = new Point(roi.getBounds().x, roi.getBounds().y);
        Point b = new Point(roi.getBounds().x + roi.getBounds().width,
roi.getBounds().y + roi.getBounds().height);

       short copy[][] = new short[IJ.getImage().getStackSize()][];

       for (int i = 0; i < IJ.getImage().getStackSize(); i++) {
           copy[i] = AUXcopyArea(IJ.getImage().getProcessor(), a, b);
       }

       ImageProcessor ipp = new ShortProcessor(roi.getBounds().width,
roi.getBounds().height, copy[0], null);
       ImagePlus processedImg = new ImagePlus("Processed", ipp);

       for (int i = 0; i < IJ.getImage().getStackSize(); i++) {
           processedImg.getStack().setPixels(copy[i], i);
       }

       processedImg.getProcessor().resetMinAndMax();
       processedImg.show();



Sincerelly,

Juanjo.

--
Juanjo Vega ([hidden email])

Unidad de Biocomputación. Laboratorio B-13.
Centro Nacional de Biotecnología. CNB-CSIC.
C\ Darwin, 3. Campus de Cantoblanco.
Universidad Autónoma de Madrid.
28049, Madrid, Spain.

http://www.cnb.csic.es
http://www.biocomp.cnb.uam.es

+34 91 585 4510


"Las mejores almas son capaces de los mayores vicios como de las mayores virtudes, y aquellos que caminan despacio por el camino recto pueden llegar más lejos que los que corren pero se apartan de él." - Discurso del Método, René Descartes.
Reply | Threaded
Open this post in threaded view
|

Re: Working with stacks

Julian Cooper
Hi Juanjo,

If I understand you correctly you can achieve what you describe in your
first paragraph by drawing your rectangle ROI, and then go to Image >
Duplicate (or press Ctrl, Shift and D). Make sure the duplicate stack
checkbox is selected and leave the range as it is if you want the whole
stack of rectangles. A new stack will open with the stack of ROIs.

Kind regards,

Julian

> -----Original Message-----
> From: ImageJ Interest Group [mailto:[hidden email]] On
> Behalf Of Juanjo Vega
> Sent: 09 June 2009 14:33
> To: [hidden email]
> Subject: Working with stacks
>
>
> Hello everyone, I want to copy a ROI from a stack of images.
>
> The idea is to select a rectangle from the stack of images and then,
> when a button is pressed, a new image containing the stack of ROIs is
> created.
>
> I'm doing this, but it doesn't works (only the first image is
> created).
> The problem is that I don't know where to find some help about how to
> work with stacks to get a slice, replace, add a new one, or whatever.
>
> Right now I'm doing this, but I tried many other stuff
> without success:
>  
>        Roi roi = IJ.getImage().getRoi();
>
>         Point a = new Point(roi.getBounds().x, roi.getBounds().y);
>         Point b = new Point(roi.getBounds().x +
> roi.getBounds().width,
> roi.getBounds().y + roi.getBounds().height);
>
>        short copy[][] = new short[IJ.getImage().getStackSize()][];
>
>        for (int i = 0; i < IJ.getImage().getStackSize(); i++) {
>            copy[i] = AUXcopyArea(IJ.getImage().getProcessor(), a, b);
>        }
>
>        ImageProcessor ipp = new ShortProcessor(roi.getBounds().width,
> roi.getBounds().height, copy[0], null);
>        ImagePlus processedImg = new ImagePlus("Processed", ipp);
>
>        for (int i = 0; i < IJ.getImage().getStackSize(); i++) {
>            processedImg.getStack().setPixels(copy[i], i);
>        }
>
>        processedImg.getProcessor().resetMinAndMax();
>        processedImg.show();
>
>
>
> Sincerelly,
>
> Juanjo.
>
> --
> Juanjo Vega ([hidden email])
>
> Unidad de Biocomputación. Laboratorio B-13.
> Centro Nacional de Biotecnología. CNB-CSIC.
> C\ Darwin, 3. Campus de Cantoblanco.
> Universidad Autónoma de Madrid.
> 28049, Madrid, Spain.
>
> http://www.cnb.csic.es
> http://www.biocomp.cnb.uam.es
>
> +34 91 585 4510
>
>
> "Las mejores almas son capaces de los mayores vicios como de
> las mayores virtudes, y aquellos que caminan despacio por el
> camino recto pueden llegar más lejos que los que corren pero
> se apartan de él." - Discurso del Método, René Descartes.
>
Reply | Threaded
Open this post in threaded view
|

Re: Working with stacks

Juanjo Vega
Hi Julian,

Finally I'm using part of the code from the duplicate plugin. I will
need to work withg a fourth dimension for the time soon and I find the
code approach more interesting.

Thanks a lot! :)

Sincerelly,
Juanjo.

Julian Cooper escribió:

> Hi Juanjo,
>
> If I understand you correctly you can achieve what you describe in your
> first paragraph by drawing your rectangle ROI, and then go to Image >
> Duplicate (or press Ctrl, Shift and D). Make sure the duplicate stack
> checkbox is selected and leave the range as it is if you want the whole
> stack of rectangles. A new stack will open with the stack of ROIs.
>
> Kind regards,
>
> Julian
>
>  
>> -----Original Message-----
>> From: ImageJ Interest Group [mailto:[hidden email]] On
>> Behalf Of Juanjo Vega
>> Sent: 09 June 2009 14:33
>> To: [hidden email]
>> Subject: Working with stacks
>>
>>
>> Hello everyone, I want to copy a ROI from a stack of images.
>>
>> The idea is to select a rectangle from the stack of images and then,
>> when a button is pressed, a new image containing the stack of ROIs is
>> created.
>>
>> I'm doing this, but it doesn't works (only the first image is
>> created).
>> The problem is that I don't know where to find some help about how to
>> work with stacks to get a slice, replace, add a new one, or whatever.
>>
>> Right now I'm doing this, but I tried many other stuff
>> without success:
>>  
>>        Roi roi = IJ.getImage().getRoi();
>>
>>         Point a = new Point(roi.getBounds().x, roi.getBounds().y);
>>         Point b = new Point(roi.getBounds().x +
>> roi.getBounds().width,
>> roi.getBounds().y + roi.getBounds().height);
>>
>>        short copy[][] = new short[IJ.getImage().getStackSize()][];
>>
>>        for (int i = 0; i < IJ.getImage().getStackSize(); i++) {
>>            copy[i] = AUXcopyArea(IJ.getImage().getProcessor(), a, b);
>>        }
>>
>>        ImageProcessor ipp = new ShortProcessor(roi.getBounds().width,
>> roi.getBounds().height, copy[0], null);
>>        ImagePlus processedImg = new ImagePlus("Processed", ipp);
>>
>>        for (int i = 0; i < IJ.getImage().getStackSize(); i++) {
>>            processedImg.getStack().setPixels(copy[i], i);
>>        }
>>
>>        processedImg.getProcessor().resetMinAndMax();
>>        processedImg.show();
>>
>>
>>
>> Sincerelly,
>>
>> Juanjo.
>>
>> --
>> Juanjo Vega ([hidden email])
>>
>> Unidad de Biocomputación. Laboratorio B-13.
>> Centro Nacional de Biotecnología. CNB-CSIC.
>> C\ Darwin, 3. Campus de Cantoblanco.
>> Universidad Autónoma de Madrid.
>> 28049, Madrid, Spain.
>>
>> http://www.cnb.csic.es
>> http://www.biocomp.cnb.uam.es
>>
>> +34 91 585 4510
>>
>>
>> "Las mejores almas son capaces de los mayores vicios como de
>> las mayores virtudes, y aquellos que caminan despacio por el
>> camino recto pueden llegar más lejos que los que corren pero
>> se apartan de él." - Discurso del Método, René Descartes.
>>
>>    
>
>  

--
Juanjo Vega ([hidden email])

Unidad de Biocomputación. Laboratorio B-13.
Centro Nacional de Biotecnología. CNB-CSIC.
C\ Darwin, 3. Campus de Cantoblanco.
Universidad Autónoma de Madrid.
28049, Madrid, Spain.

http://www.cnb.csic.es
http://www.biocomp.cnb.uam.es

+34 91 585 4510


"Las mejores almas son capaces de los mayores vicios como de las mayores virtudes, y aquellos que caminan despacio por el camino recto pueden llegar más lejos que los que corren pero se apartan de él." - Discurso del Método, René Descartes.