I suspect my imagej macro problem is quite trivial but I have no experience in the basic coding to figure it out. I’ve found many discussion threads about using the ROI manager to loop through all its indices and do manipulations on each individually, but not my specific problem;
I have microscopy images where each subject is two circular objects (one big, one small) which sit atop each other in various conformations. These objects are marked as individual ROIs using freehand lines in a consistent order (big, small, big, small, etc) across all of my files.
I want to make a macro which
- select the two ROIs of each subject (e.g. ROI index “0, 1” for the first subject)
- do an OR (combine),
- fit a rectangle,
- scale the rectangle slightly (so it encompasses all the pixels of the subject)
- duplicate the rectangle to a new image
- export the duplicated field as the original filename+the subject number
- select the two ROIs of the next subject (e.g ROI index “2, 3”)
- proceed through the entire ROI manager list
I have a macro that will do this for the first two ROI indexes in each list (without the automatically appended filename)
roiManager("Select", newArray(0,1)); roiManager("Combine"); run("Fit Rectangle"); run("Scale... ", "x=1.05 y=1.05 centered"); run("Duplicate...", "duplicate"); saveAs("Tiff", "xxfilepathxx/1.tif");
here is an image showing the result of the above macro and annotations.
I wonder if anyone could please point me in the correct direction with this?
I guess I have to define each subject (ROIs 0, 1; then 2, 3; then 4,5; etc) as an array, and get the manager to skip between them, at the same time using those arrays to define the filename for export (e.g subject 1, 2, 3, etc).
Unfortunately I lack the coding experience to really understand whether this is the correct terminology or sensible!
Thanks in advance!