//============================================================================= // Modified 20140113 for single channel stacks. // Crop out the stack and then take the stacks and combine them. // calls function clipCellAndPopOnStack(original, clipstack); // macro "clip all ROIs in Roi Manager each as a stack [F4]" { if (Stack.isHyperstack) exit('Expecting a single channel stack.'); if (nImages() > 1) exit('Only one stack should be open.'); original = getImageID; // add command to get scale so that it may be restored before the final save. run("Set Scale...", "distance=1 known=1 pixel=1 unit=px"); Stack.getDimensions(width, height, channels, slices, frames); Stack.getDisplayMode(displaymode); title = getTitle; bits = bitDepth(); if (bits == 24) bitstring="RGB"; else bitstring = ""+bits+"-bit"; clipsize = getNumber("Enter side of square box in pixels: ", clipsize); clipstackID=newArray(roiManager("count")); // The Image ID of each clipped stack will be stored here. clipstackTitle=newArray(roiManager("count")); // The Image Title of each clipped stack will be stored here. run("Set Measurements...", " centroid area redirect=None decimal=0"); for (i=0; i nImages()) { n = nImages(); // nImages will change, so fixed here. for (i=0; i<((cols * rows)-n); i++) newImage("dummy"+i, "" + type + " " + bgColor, x, y, s); } // end if // get titles for combine() command n = nImages(); titles = newArray(n); for(i=1; i<=n; i++) { selectImage(i); titles[i-1] = getTitle(); } // Do the montage. t = 0; for (Y=0; Y0) run("Combine...", "stack1=Comb"+ (Y-1) + " stack2=Comb"+ Y + " combine"); rename("Comb"+Y); } // for Y } // end combineStacks() } //========================================================= macro "combineStacks" { combineStacks(); } macro "make test stacks"{ newImage("test", "8-bit ramp", 100, 100, 3); run("Rotate 90 Degrees Right"); newImage("test", "8-bit ramp", 100, 100, 3); newImage("test", "8-bit white", 100, 100, 3); newImage("test", "8-bit black", 100, 100, 3); } // Modified 20121001 for composite color hyperstacks. // The ROI of the cell is selected and the original image is active before this function is called. // clipstack contains the imageID of the clipped stacks window. //======================================================================= function clipCellAndPopOnStack(original, clipstack, chan) { requires("1.45m"); run("Set Scale...", "distance=1 known=1 pixel=1 unit=px"); run("Set Measurements...", " centroid area redirect=None decimal=0"); run("Measure"); xc = getResult("X", nResults-1); yc = getResult("Y", nResults-1); selectWindow("Results"); run("Close"); selectImage(original); Stack.setChannel(chan); makeRectangle(xc-(clipsize/2), yc-(clipsize/2), clipsize, clipsize); run("Copy"); run("Select None"); setPasteMode("Copy"); selectImage(clipstack); run("Paste"); run("Add Slice"); } // clip cell