Access File Info in macro?

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

Access File Info in macro?

xchopp

My macro code:

run("Raw...", "open="+path+infile+" image=[16-bit Unsigned] width="+srcCols+" height="+Wsize+" offset="+mOffset+" number="+NumChunks+" gap=0 little-endian use");

must be preceded by a line in which the offset is hardwired, thus:
 
mOffset = 52840;      

This is pretty inelegant: is there any way I can access the offset value from ImageJ macro language?  If not, is there a Javascript function that I can call from the macro to do the same (and how to call?).  

Cheers!

--Mark    

Reply | Threaded
Open this post in threaded view
|

Re: Access File Info in macro?

Krs5
Dear Mark,


Do you mean you want to be able to change the offset value manually? For that you can use the code below
mOffset = 52840;
Dialog.create("Offset");
        Dialog.addNumber("Give an offset value", mOffset);
Dialog.show();
mOffset = Dialog.getNumber();

Best wishes

Kees


Dr Ir K.R. Straatman
Senior Experimental Officer
Centre for Core Biotechnology Services
University of Leicester

http://www.le.ac.uk/biochem/microscopy/home.html


-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of xchopp
Sent: 22 July 2013 21:15
To: [hidden email]
Subject: Access File Info in macro?

My macro code:

run("Raw...", "open="+path+infile+" image=[16-bit Unsigned] width="+srcCols+" height="+Wsize+" offset="+mOffset+" number="+NumChunks+"
gap=0 little-endian use");

must be preceded by a line in which the offset is hardwired, thus:
 
mOffset = 52840;      

This is pretty inelegant: is there any way I can access the offset value from ImageJ macro language?  If not, is there a Javascript function that I can call from the macro to do the same (and how to call?).  

Cheers!

--Mark    





--
View this message in context: http://imagej.1557.x6.nabble.com/Access-File-Info-in-macro-tp5004079.html
Sent from the ImageJ mailing list archive at Nabble.com.

--
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: Access File Info in macro?

Gabriel Landini
In reply to this post by xchopp
On Monday 22 Jul 2013 21:15:15 you wrote:

> My macro code:
> run("Raw...", "open="+path+infile+" image=[16-bit Unsigned]
> width="+srcCols+" height="+Wsize+" offset="+mOffset+" number="+NumChunks+"
> gap=0 little-endian use");
>
> must be preceded by a line in which the offset is hardwired, thus:
>
> mOffset = 52840;
>
> This is pretty inelegant: is there any way I can access the offset value
> from ImageJ macro language?  If not, is there a Javascript function that I
> can call from the macro to do the same (and how to call?).

Where is the value you want to use in the macro supposed to exist if not in a
variable or constant?

Cheers

Gabriel

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

Re: Access File Info in macro?

xchopp
Hi Gabriel,

Thanks for responding.

Where is the value you want to use in the macro supposed to exist if not in a
variable or constant?

It's embedded in the TIFF file.  You need to know it in order to use run("Raw..."...) with the "use virtual" option. I found a rather inelegant workaround:

The offset value needed is obtained by having the macro switch on the Debugger, open the source image, save the results from the Log into a file called FileInfo.txt, close the source image, read back that file and split to parse out the offset value. The source image can then clod re-opened as a Virtual Stack.

  FIname = path+"FileInfo.txt";      // assign name for the file information file
  saveAs("Text", FIname);            // with the Log window this saves a copy but does not rename the window

  // ... code ...

  // first need to get the offset value
  AllText     = File.openAsString(FIname);
  ftext         = split(AllText, "\n");
  finfo         = ftext[53];               // index is 53 because the files
  otext        = split(finfo, ":");
  mOffset   =parseInt(otext[1]);   // testing: print("Offset = "+mOffset);

 // now open the TIFF using the Raw method, to allow use of the Virtual Stack facility.

run("Raw...", "open="+path+infile+" image=[16-bit Unsigned] width="+srcCols+" height="+Wsize+"  \\ offset="+mOffset+" number="+NumChunks+" gap=0 little-endian use");

A bit of jiggery-pokery but it seems to work.  Wayne suggested using the File>Import>TIFF Virtual Stack command; I'll also try this.

Cheers,

  Mark
Reply | Threaded
Open this post in threaded view
|

Re: Access File Info in macro?

xchopp
In reply to this post by Krs5
Hi Kees,

Thanks very much for responding. The run("Raw...") routine is for importing an image, optionally using ImageJ's virtual stack method (the "use" at the end of the command). However, this requires knowledge of the offset to imagery in the file. FileOpener provides information about the image file in the Log window but only when the Debugger is switched on. We used to do this manually and hardwire the value.

Yesterday I found a workaround: The offset value needed is obtained by having the macro switch on the Debugger, open the source image, save the results from the Log into a file called FileInfo.txt, close the source image, read back that file and split to parse out the offset value. The source image can then clod re-opened as a Virtual Stack.

  // Open the source image in Debug mode to obtain the dimensions and offset.

  run("Misc...", "divide=Infinity debug"); // switch on Debug mode to get File Info (in Log window)
  open(path+infile);
  srcCols  = getWidth();
  srcRows = getHeight();
  // ... code ....

  selectWindow("Log");
  FIname = path+"FileInfo.txt";     // assign name for the file information file
  saveAs("Text", FIname);            // with the Log window this saves a copy but does not rename the window 

  tmp = getTitle();                         // close the image window.
  selectWindow(tmp);
  run("Close");
  run("Misc...", "divide=Infinity");  // switch off Debug mode
  FIname = path+"FileInfo.txt";    // assign name for the file information file
  saveAs("Text", FIname);           // with the Log window this saves a copy but does not rename the window
  // ... code ...

  // open using Raw with Virtual Stack; first need to get the offset value
  AllText     = File.openAsString(FIname);
  ftext         = split(AllText, "\n");
  finfo         = ftext[53];                // index is 53 because the file saved has other lines before the Debugger output
  otext        = split(finfo, ":");
  mOffset   =parseInt(otext[1]);   // testing:   print("Offset = "+mOffset);

 // now open the image using the Raw method, to allow use of the Virtual Stack facility.

run("Raw...", "open="+path+infile+" image=[16-bit Unsigned] width="+srcCols+" height="+Wsize+"  \\ offset="+mOffset+" number="+NumChunks+" gap=0 little-endian use");

A bit of jiggery-pokery but it seems to work! Wayne thinks I might accomplish the same using the File>Import>TIFF Virtual Stack command (it would certainly be more elegant than my kludge!).

Thanks again.

  Mark

Reply | Threaded
Open this post in threaded view
|

Re: Access File Info in macro?

Michael Schmid
On Jul 23, 2013, at 15:48, xchopp wrote:

> Wayne thinks I might
> accomplish the same using the File>Import>TIFF Virtual Stack command (it
> would certainly be more elegant than my kludge!).
>
> Thanks again.
>
>  Mark

Hi Mark,

sorry, I don't understand:
What is the point of using your complicated code instead of simply
  File>Import>TIFF Virtual Stack

As I understand, your code does the same, but works only for a few special TIFF stacks (i.e., only for 16 bits, one byte order, no gap between the slices).  

Michael

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

Re: Access File Info in macro?

Gabriel Landini
In reply to this post by xchopp
> It's embedded in the TIFF file.  You need to know it in order to use
> run("Raw..."...) with the "use virtual" option. I found a rather inelegant
> workaround:

There is a tiff tag plugin reader in the IJ site. I wonder if that might be
useful to get values, if you know the tag.
http://rsbweb.nih.gov/ij/plugins/tiff-tags.html

Sorry I did not understand why you need to open as raw and not as a virtual
stack...

Cheers
Gabriel

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

Re: Access File Info in macro?

xchopp
In reply to this post by Michael Schmid
Hi Michael,

What is the point of using your complicated code instead of simply
  File>Import>TIFF Virtual Stack

I am only opening one file and I had thought that File>Import>TIFF Virtual Stack was for opening a sequence of images, as implied by the name -- but  this does not seem to be the case. I will look into changing to the more elegant solution!

Best,

 Mark
Reply | Threaded
Open this post in threaded view
|

Re: Access File Info in macro?

ctrueden
Hi Mark,

> I am only opening one file and I had thought that File>Import>TIFF
> Virtual Stack was for opening a sequence of images, as implied by the
> name -- but this does not seem to be the case. I will look into
> changing to the more elegant solution!

Also note that the Bio-Formats Importer plugin (part of Fiji;
http://fiji.sc/) can import any of 125+ supported file formats (including
TIFF) as a virtual stack, by checking the "Use virtual stack" option. And
the "Group files with similar names" option allows you to read in multiple
numbered files into a single dataset. For more info, see:
http://fiji.sc/Bio-Formats

Regards,
Curtis


On Tue, Jul 23, 2013 at 10:09 AM, xchopp <[hidden email]> wrote:

> Hi Michael,
>
> What is the point of using your complicated code instead of simply
> >   File>Import>TIFF Virtual Stack
> >
>
> I am only opening one file and I had thought that File>Import>TIFF Virtual
> Stack was for opening a sequence of images, as implied by the name -- but
> this does not seem to be the case. I will look into changing to the more
> elegant solution!
>
> Best,
>
>  Mark
>
>
>
>
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/Access-File-Info-in-macro-tp5004079p5004104.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> 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: Access File Info in macro?

xchopp
Hi Curtis,

Also note that the Bio-Formats Importer plugin (part of Fiji;
http://fiji.sc/) can import any of 125+ supported file formats (including
TIFF) as a virtual stack, by checking the "Use virtual stack" option. And
the "Group files with similar names" option allows you to read in multiple
numbered files into a single dataset. For more info, see:
http://fiji.sc/Bio-Formats

Thanks!   (I guess this can be called from a macro, right?).

--Mark

Reply | Threaded
Open this post in threaded view
|

Re: Access File Info in macro?

ctrueden
Hi Mark,

> I guess this can be called from a macro, right?

Sure! Run Plugins > Macros > Record... to open the Macro Recorder first.
Then run File > Import > Bio-Formats and open a file with the desired
settings. It will record the corresponding macro command for you in the
Recorder window.

Regards,
Curtis


On Tue, Jul 23, 2013 at 11:55 AM, xchopp <[hidden email]> wrote:

> Hi Curtis,
>
> Also note that the Bio-Formats Importer plugin (part of Fiji;
> > http://fiji.sc/) can import any of 125+ supported file formats
> (including
> > TIFF) as a virtual stack, by checking the "Use virtual stack" option. And
> > the "Group files with similar names" option allows you to read in
> multiple
> > numbered files into a single dataset. For more info, see:
> > http://fiji.sc/Bio-Formats
> >
>
> Thanks!   (I guess this can be called from a macro, right?).
>
> --Mark
>
>
>
>
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/Access-File-Info-in-macro-tp5004079p5004108.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> 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: Access File Info in macro?

xchopp
Great -- thank you!