I have a series of file entries of the following form to make a custom time stamp for a stack of images.
T_174359.bmp 60 T_174391.bmp 92 etc... At the same time in ImageJ, I have an open stack of images named "stack". I want to: 1. Open the file entries. 2. parse the file entries and stamp the text of the second item on each line. I.e., 60, 92 etc...to the corresponding slice in the image stack. Notice the ImageJ TimeStamper cannot do this, so I must use some sort of macro code. My for loops indexes to text, stacks are not working for some reason. Ethan. Ethan Cohen, Ph.D. FDA Center for Devices and Radiological Health Office: Rm 1204 WO62 White Oak Federal Res Ctr. 10903 New Hampshire Ave. Silver Spring, MD 20993 |
On Mar 26, 2012, at 3:34 AM, Cohen, Ethan D wrote:
> I have a series of file entries of the following form to make a custom time stamp for a stack of images. > T_174359.bmp 60 > T_174391.bmp 92 etc... > > > At the same time in ImageJ, I have an open stack of images named "stack". > I want to: > 1. Open the file entries. > 2. parse the file entries and stamp the text of the second item on each line. I.e., 60, 92 etc...to the corresponding slice in the image stack. > > Notice the ImageJ TimeStamper cannot do this, so I must use some sort of macro code. My for loops indexes to text, stacks are not working for some reason. Here is a macro that does this. It requires at least ImageJ 1.46e, which adds the "Label" format (draw slice labels) to the Image>Stacks>Label command. -wayne requires("1.46e"); list = File.openAsString(""); entries = split(list, "\n"); n = entries.length; newImage("Untitled", "8-bit Black", 512, 512, n); for (i=1; i<=n; i++) { setSlice(i); items = split(entries[i-1]); setMetadata("label", items[1]); } run("Label...", "format=Label x=5 y=20 font=18 use"); |
Wayne:
Thanks for your help...I got my time stamper to read the "timestamp" text file (ex. T_174359.bmp 60) and stamp time points on stack slices...but it has an odd bug. 1. When I run this macro the first time..no time points appear on the slices in the stack. 2. It only prints out time points like 9:56 on the stack slices, when I use the "text tool" to draw text on a stack slice. 3. Then running the macro is fine and the time label metadata appear on all the stack slices. 4. Have I missed something? Ethan. // "Label series using time stamps in DateLog.txt in local director requires("1.43"); print("\\Clear"); //empties the Log dir = getDirectory("Choose a Directory ");//sets path = dir list = File.openAsString(dir+"Timelog.txt"); // opens file entries = split(list, "\n"); // splits into lines of text n = entries.length;// line length value of Timelog.txt run("Colors...", "foreground=white background=black selection=white"); selectWindow("stack"); //select Log-window for (i=1; i<=n; i++) { setSlice(i); // select slice number items = split(entries[i-1]); j = parseInt(items[1]); // floor - largest value of j under 60 that is an integer s = ""+pad(floor((j/60)%60))+":"+pad(j%60); // time sec/60 stuff setMetadata("Label", s); } selectWindow("stack"); //select Log-window setTool("text"); run("Label...", "format=Label x=20 y=200 font=32 use"); function pad(n) { str = toString(n); // decimal rep of number j if (lengthOf(str)==1) str="0"+str; return str; On Mar 26, 2012, at 3:34 AM, Cohen, Ethan D wrote: > I have a series of file entries of the following form to make a custom time stamp for a stack of images. > > T_174391.bmp 92 etc... > > > At the same time in ImageJ, I have an open stack of images named "stack". > I want to: > 1. Open the file entries. > 2. parse the file entries and stamp the text of the second item on each line. I.e., 60, 92 etc...to the corresponding slice in the image stack. > > Notice the ImageJ TimeStamper cannot do this, so I must use some sort of macro code. My for loops indexes to text, stacks are not working for some reason. Here is a macro that does this. It requires at least ImageJ 1.46e, which adds the "Label" format (draw slice labels) to the Image>Stacks>Label command. -wayne requires("1.46e"); list = File.openAsString(""); entries = split(list, "\n"); n = entries.length; newImage("Untitled", "8-bit Black", 512, 512, n); for (i=1; i<=n; i++) { setSlice(i); items = split(entries[i-1]); setMetadata("label", items[1]); } run("Label...", "format=Label x=5 y=20 font=18 use"); |
Free forum by Nabble | Edit this page |