I am trying to write a macro to run a simple function on a stack and write the output to a new stack or to save to a series of tiff files (whichever is easier). Can someone point me to a macro I can use as an example to copy the general scheme from? Thanks- Dave
Professor David Knecht Beatson Institute for Cancer Research Switchback Road, Bearsden Glasgow Scotland G61 1BD UK |
On Monday 10 Oct 2011 10:25:09 you wrote:
> I am trying to write a macro to run a simple function on a stack and write > the output to a new stack or to save to a series of tiff files (whichever > is easier). Can someone point me to a macro I can use as an example to > copy the general scheme from? Thanks- Dave You could first duplicate the whole stack and then apply the function each slice of that copy. run("Duplicate...", "title=NewStack.tif duplicate"); Cheers Gabriel |
On Monday 10 Oct 2011 10:37:14 I should have written:
> You could first duplicate the whole stack and then apply the function to > each slice of that copy. run("Duplicate...", "title=NewStack.tif duplicate"); for (i=1; i<=nSlices; i++) { setSlice(i); // apply your transformation here, run("Invert", "slice"); } |
In reply to this post by Knecht, David
On 10/10/11 11:25 AM, Knecht, David wrote:
> I am trying to write a macro to run a simple function on a stack and write the output to a new stack or to save to a series of tiff files (whichever is easier). Can someone point me to a macro I can use as an example to copy the general scheme from? Thanks- Dave > Here is an example of a macro that runs CLAHE local contrast enhancement on a stack which is already open. You can do what you want inseide th loops, and it will work separately on frames and slices, so that you can separate the time and Z dimensions. inputId = getImageID(); // gets active image inputTitle = getTitle(); Stack.getDimensions(width, height, channels, slices, frames); for (i=1; i<frames+1; i++){ Stack.setFrame(i); for (j=1; j<slices+1; j++) { Stack.setSlice(j); run("Enhance Local Contrast (CLAHE)", "blocksize=127 histogram=256 maximum=3 mask=*None*"); } } Notice that we loop over both slices and frames. Some plugins make this distinction, and will appear to work on multi-frame images but not multi-slice or the other way around. Also, often my time lapse images are read in as multi-slice instead of multi-frame. More specifically, this recently occurred with OIB images. I used the following macro command to work around this: run("Properties...", "channels=1 slices=1 frames="+d2s(N_IMAGES,0)+" unit=pixel pixel_width=1 pixel_height=1 voxel_depth=1.0000000 frame=[1 sec] origin=0,0"); Where N_IMAGES was previously defined as 640 (but it could have been obtained from getDimensions). Regards, --aryeh -- Aryeh Weiss School of Engineering Bar Ilan University Ramat Gan 52900 Israel Ph: 972-3-5317638 FAX: 972-3-7384051 |
In reply to this post by Gabriel Landini
The responses have been useful, but I think I was not clear enough in my question. I need to explicitly save the window generated from each image of the stack. I am trying to give the 3D Interactive Surface Plot plugin the ability to process data from a time lapse sequence. I want to have the plugin process a series of images from the time stack to show changes in intensity of cells over time. So for each slice of the image stack, I want to generate an image from the plugin and then save the image to a file using the save function in the window before moving to the next time point of the stack and repeating. I thought this would be possible to do as a macro, so I am making an effort to actually learn the macro language better so I can do this kind of thing myself in the future (one of my sabbatical projects). Thanks- Dave
On Oct 10, 2011, at 10:37 AM, Gabriel Landini wrote: > On Monday 10 Oct 2011 10:25:09 you wrote: >> I am trying to write a macro to run a simple function on a stack and write >> the output to a new stack or to save to a series of tiff files (whichever >> is easier). Can someone point me to a macro I can use as an example to >> copy the general scheme from? Thanks- Dave > > You could first duplicate the whole stack and then apply the function each > slice of that copy. > > run("Duplicate...", "title=NewStack.tif duplicate"); > > Cheers > Gabriel Professor David Knecht Beatson Institute for Cancer Research Switchback Road, Bearsden Glasgow Scotland G61 1BD UK |
On Monday 10 Oct 2011 13:20:37 Knecht, David wrote:
> I am trying to give the 3D Interactive Surface Plot plugin > the ability to process data from a time lapse sequence. I want to have > the plugin process a series of images from the time stack to show changes > in intensity of cells over time. So for each slice of the image stack, I How to call the plugin from a macro is covered in the page of the plugin. http://rsbweb.nih.gov/ij/plugins/surface-plot-3d.html I adapted that to this macro whcih will produce a stack of 3D projections (mind the line breaks inserted by the mail client). //------------8<--------------- setBatchMode(true); a=getTitle(); slices=nSlices; stack=0; for (i=1; i<=slices; i++) { showProgress(i, slices); selectImage(a); setSlice(i); run("Interactive 3D Surface Plot", "plotType=3 smooth=11 colorType=3 snapshot=1 " ); run("Copy"); w = getWidth; h = getHeight; close(); if (stack==0) { newImage("Plots", "RGB", w, h, 1); stack = getImageID; } else { selectImage(stack); run("Add Slice"); } run("Paste"); } selectImage(a); setSlice(1); selectImage(stack); setSlice(1); run("Select None"); setBatchMode(false); //------------8<--------------- You can then save the stack or convert it to images and save those. Cheers Gabriel |
Free forum by Nabble | Edit this page |