Login  Register

Re: Access File Info in macro?

Posted by xchopp on Jul 23, 2013; 1:47pm
URL: http://imagej.273.s1.nabble.com/Access-File-Info-in-macro-tp5004079p5004098.html

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