/* Basic macro written by Jan Brocher/BioVoxxel * and published on imageJ mailing list on 04/02/2014. * This macro allowed to capture changes in ROI position starting * on each image with the ROI position of the first image of the stack. * * Further developed to automatically update all following * ROIs to the new position by registering the mouse click. * * In this version of the macro a left mouse click outside the ROI * will update the ROI manager. * * If you notice that this is too sensitive or too slow you * can chance the wait(50) at line 67. * After updating the ROI manager the macro automatically selects the * next image in the stack * * Kees Straatman, University of Leicester, 06/02/2014 * NO WARRENTY of functionality and no liability for any damages. */ macro move_ROI{ leftButton=16; insideROI=32; title=getTitle(); getDimensions(width, height, channels, slices, frames); Dialog.create("ROI setup"); Dialog.addChoice("label:", newArray( "frames", "slices", "channels"), "frames"); Dialog.show(); dimension = Dialog.getChoice(); color = toHex(getValue("rgb.foreground")); run("Overlay Options...", "stroke="+color+" width=0 fill=none set"); if(dimension=="frames"){ if(frames<2) exit("no multiple frames available"); else Nlabel = frames; }else if(dimension=="slices"){ if(slices<2)exit("no multiple slices available"); else Nlabel = slices; }else if(dimension=="channels"){ if(channels<2)exit("no multiple channels available"); else Nlabel = channels; } roiManager("reset"); for(i=1; i<=Nlabel; i++){ if(dimension=="frames") Stack.setFrame(i); else if(dimension=="slices") Stack.setSlice(i); else Stack.setChannel(i); run("Add Selection..."); } run("To ROI Manager"); roiManager("Associate", "true"); roiManager("Show All with labels"); roiManager("Show All"); selectWindow(title); //reset Stack position if(dimension=="frames") Stack.setFrame(1); else if(dimension=="slices") Stack.setSlice(1); else Stack.setChannel(1); count=1; roiManager('select', count-1); //enable adjustments to the ROIs while(count<(Nlabel-1)){ Stack.getPosition(channel, slice, frame); getCursorLoc(x, y, z, flags); wait(50); // Move ROI if ((flags&leftButton==0)&&(flags&insideROI==32)) getSelectionBounds(dx, dy, dw, dh); // Update ROIs when right mouse click outside the ROI if ((flags&leftButton!=0)&&(flags&insideROI!=32)){ if(dimension=="frames") count = frame; else if(dimension=="slices") count = slice; else count = channel; for (i=count-1; i