Posted by
xchopp on
Jul 23, 2013; 1:35pm
URL: http://imagej.273.s1.nabble.com/Access-File-Info-in-macro-tp5004079p5004096.html
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