/* 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 by Kees Straatman, University of Leicester, * to automatically update all following ROIs to the new position * by registering the mouse click. If you notice that this is too * sensitive or too slow you can chance the wait(350) at line 62. * After updating the ROI manager the macro automatically selects the * next image in the stack * * 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)){ getCursorLoc(x, y, z, flags); wait(350); // This can be changed if you find that more than one ROI is adjusted if ((flags&leftButton==16)&&(flags&insideROI==32)){ Stack.getPosition(channel, slice, frame); if(dimension=="frames") count = frame; else if(dimension=="slices") count = slice; else count = channel; getSelectionBounds(dx, dy, dw, dh); for (i=count-1; i