Login  Register

Re: (Java) How to save an ImageStack

Posted by Aryeh Weiss on Apr 04, 2019; 7:11am
URL: http://imagej.273.s1.nabble.com/Java-How-to-save-an-ImageStack-tp5021973p5021977.html

Hi Phillippe

The macro recorder (that also record Java code) is wonderful, but in
this case Wayne provided an important item that does not show in the
recorder. The IJ.save method  requires an ImagePlus , and when you
create a new stack you need to get an ImagePlus with that stack, and
Wayne does this with the line

img = new ImagePlus("RGB Stack",rgbStack);

The recorder does not show this step --it creates a stack with
IJ.createImage which returns the ImagePlus directly.

So while the macro recorder is wonderful, and i use it a lot, sometimes
you need to dig a bit to figure out how to use the API to do something.

Best regards
--aryeh

On 04/04/2019 9:56, Philippe CARL wrote:

> Dear Robert, for Wayne I just present my best greetings since I would be
> incredibly pretentious to think to teach you something within ImageJ :)
> The ImageJ PLugins>Macros>Record... tool can as well be configured to record
> Java code by changing the selection of the drop down menu on the top left of
> the recording window from macro to Java.
> And thus by opening "manually" a stack and saving it you can then easily
> figure out the needed code.
> My best regards,
> Philippe
>
> Philippe CARL
> Laboratoire de Bioimagerie et Pathologies
> UMR 7021 CNRS - Université de Strasbourg
> Faculté de Pharmacie
> 74 route du Rhin
> 67401 ILLKIRCH
> Tel : +33(0)3 68 85 41 84
>
> -----Message d'origine-----
> De : ImageJ Interest Group [mailto:[hidden email]] De la part de Wayne
> Rasband
> Envoyé : jeudi 4 avril 2019 01:08
> À : [hidden email]
> Objet : Re: (Java) How to save an ImageStack
>
>> On Apr 3, 2019, at 6:23 PM, Robert Lockwood <[hidden email]> wrote:
>>
>> I've created and populated an ImageStack in my Java app, how do I save the
>> stack?
>>
>> outRGBStack = ImageStack.create(NCOLS, NROWS, NSLICES, 24);
> Here is JavaScript example that creates a stack, saves it in the temp
> folder, re-opens it, and displays it:
>
>    NCOLS = NROWS = NSLICES = 256;
>    PATH = IJ.getDir("temp")+"RGB_Stack.tif";
>    rgbStack = ImageStack.create(NCOLS, NROWS, NSLICES, 24);
>    img = new ImagePlus("RGB Stack",rgbStack);
>    IJ.saveAs(img, "tif", PATH);
>    img = IJ.open(PATH);
>    img.show();
>
> -wayne
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051

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