macro "Oriented ROIs" { scalelength_def = 1; // length in µm scalewidth_def = 0.8; // thickness in µm AREA_DEF = true; UPDA_DEF = true; DUPLI_DEF = true; CONCAT_DEF = true; inID=getImageID(); getPixelSize(unit, pixelWidth, pixelHeight); roinumber = roiManager("count"); // Creation of the dialog box Dialog.create("Oriented ROIs Options"); Dialog.addNumber(" Fixed ROI length:", scalelength_def, 2, 4, "µm"); Dialog.addNumber(" Fixed ROI thickness:", scalewidth_def, 2, 4, "µm"); Dialog.addCheckbox("Convert lines to rotated rectangles", AREA_DEF); Dialog.addCheckbox("Update input line ROIs rather than adding new ones", UPDA_DEF); Dialog.addCheckbox("Generate output ROIs duplicated images", DUPLI_DEF); Dialog.addCheckbox("Close input image and concatenate ROIs into stack", CONCAT_DEF); Dialog.show(); // Feeding variables from dialog choices scalelength = Dialog.getNumber(); scalewidth = Dialog.getNumber(); AREA = Dialog.getCheckbox(); UPDA = Dialog.getCheckbox(); DUPLI = Dialog.getCheckbox(); CONCAT = Dialog.getCheckbox(); setBatchMode(true); rawlength = scalelength/pixelWidth; rawwidth = scalewidth/pixelWidth; // Loop on ROIs, take line ROIs one by one for (l=0; l 0 && recdist[r] < mindist) { mindist = recdist[r]; minindex = r; } } // print("mindist=" + mindist + " minindex=" + minindex); // Take the closest rectangle ROI, get its center roiManager("select", minindex); Roi.getCoordinates(xrpoints, yrpoints); xrcenter = (xrpoints[0]+xrpoints[2])/2; yrcenter = (yrpoints[0]+yrpoints[2])/2; // Draw a line ROI parrallel to the current line ROI centered on the rectangle ROI center with given length and width xhalf = rawlength/(2*Math.sqrt(lslope*lslope + 1)); xend = xrcenter + xhalf; yend = yrcenter + lslope*xhalf; xbegin = xrcenter - xhalf; ybegin = yrcenter - lslope*xhalf; makeLine(xbegin, ybegin, xend, yend, rawwidth); // Convert output line ROI to rotated rectangle (optional, obligatory if duplication) if (AREA == true || DUPLI == true) run("Line to Area"); // Add or update the output ROI if (UPDA == true) { roiManager("select", l); run("Restore Selection"); roiManager("update"); } else roiManager("add"); } } // duplicate each rotated rectangle and merge them into a stack (requires closing input image) if (DUPLI == true) { for (l=0; l