(Java) How to save an ImageStack

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

(Java) How to save an ImageStack

Robert Lockwood
I've created and populated an ImageStack in my Java app, how do I save the
stack?

outRGBStack = ImageStack.create(NCOLS, NROWS, NSLICES, 24);

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

Re: (Java) How to save an ImageStack

Wayne Rasband-2
> 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
Reply | Threaded
Open this post in threaded view
|

Re: (Java) How to save an ImageStack

CARL Philippe (LBP)
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
Reply | Threaded
Open this post in threaded view
|

Re: (Java) How to save an ImageStack

Aryeh Weiss
In reply to this post by Wayne Rasband-2
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
Reply | Threaded
Open this post in threaded view
|

Re: (Java) How to save an ImageStack

CARL Philippe (LBP)
Dear Aryeh,
I don't really know whether and / or how I should answer your mail or not.
As I wrote it, I really don't believe (or even try) to teach something to Wayne (even knowing that I'm French and thus probably very pretentious by nature).
I just wanted to point out that the ImageJ recorder (even it is found within the menu Plugins>Macros>Record...) is not only able to save macro code, but can as well be configurated for generating java code which is quite helpful and often doing the needed job.
And as far as I'm concerned, I didn't know (or took attention of) this option for a long time and since I know it, it is helping me out a lot.
Thus I just wanted to share this information for the readers who never took attention on this point, that was the reason of my post, nothing more...
Have a nice day,
Philippe

-----Message d'origine-----
De : ImageJ Interest Group [mailto:[hidden email]] De la part de Aryeh Weiss
Envoyé : jeudi 4 avril 2019 09:12
À : [hidden email]
Objet : Re: (Java) How to save an ImageStack

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

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

Re: (Java) How to save an ImageStack

Robert Lockwood
In reply to this post by Aryeh Weiss
Thanks for the heads up that I can record as Java!

On Thu, Apr 4, 2019 at 12:47 AM Philippe CARL <[hidden email]>
wrote:

> Dear Aryeh,
> I don't really know whether and / or how I should answer your mail or not.
> As I wrote it, I really don't believe (or even try) to teach something to
> Wayne (even knowing that I'm French and thus probably very pretentious by
> nature).
> I just wanted to point out that the ImageJ recorder (even it is found
> within the menu Plugins>Macros>Record...) is not only able to save macro
> code, but can as well be configurated for generating java code which is
> quite helpful and often doing the needed job.
> And as far as I'm concerned, I didn't know (or took attention of) this
> option for a long time and since I know it, it is helping me out a lot.
> Thus I just wanted to share this information for the readers who never
> took attention on this point, that was the reason of my post, nothing
> more...
> Have a nice day,
> Philippe
>
> -----Message d'origine-----
> De : ImageJ Interest Group [mailto:[hidden email]] De la part de
> Aryeh Weiss
> Envoyé : jeudi 4 avril 2019 09:12
> À : [hidden email]
> Objet : Re: (Java) How to save an ImageStack
>
> 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
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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