Hello!
I’m looking for a macro with which I can a) measure an angle, or distance (line tool) or area (oval or polygon selection tool) b) display the result of that measurement (i.e. angle, or area or length) c) adds this selection to the overlay in yellow. So far especially b proved to be difficult most macros I found just lable with A,B,C or numbers not with the result. So I found this one but it does not work.. macro "Measure and Label [m]" { run("Measure"); label = "" + getResult("Length", nResults-1); if (label=="NaN" || label=="0") label = "" + getResult("Area", nResults-1); label = "" + getResult("Angle", nResults-1); Roi.setName(label); Overlay.addSelection; } Maybe someone can help to debug? Thanks, Till -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Till,
below is a modification of your macro, based on my understanding of your specifications. It can be expanded if different selections/measures want to be included. Everything is handled through overlays, including the labeling. ITH, Giovanni macro "measure and label" { if (nImages==0) { exit("No images are open"); } imageTitle = getTitle(); type = selectionType(); // in case the user forgot to make a selection if (type == -1) { waitForUser("Draw a ROI on the image " + imageTitle + " and press OK"); } type = selectionType(); // check selection type and measure to perform if (type==1 || type==2) { field = "Area"; } else if (type==5) { field = "Length"; } else if (type==8) { field = "Angle"; } else { exit("I don't know what to do"); } run("Measure"); label = "" + getResult(field, nResults-1); // get top left coordinates of bounding box getSelectionBounds(x, y, width, height); // add selection and measure as overlays Overlay.addSelection; Overlay.drawString(label, x, y) } -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of OMANSEN, Till Frederik Sent: Dienstag, 17. Oktober 2017 11:50 To: [hidden email] Subject: Measure + label with result macro Hello! I’m looking for a macro with which I can a) measure an angle, or distance (line tool) or area (oval or polygon selection tool) b) display the result of that measurement (i.e. angle, or area or length) c) adds this selection to the overlay in yellow. So far especially b proved to be difficult most macros I found just lable with A,B,C or numbers not with the result. So I found this one but it does not work.. macro "Measure and Label [m]" { run("Measure"); label = "" + getResult("Length", nResults-1); if (label=="NaN" || label=="0") label = "" + getResult("Area", nResults-1); label = "" + getResult("Angle", nResults-1); Roi.setName(label); Overlay.addSelection; } Maybe someone can help to debug? Thanks, Till -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thanks so much for this Giovanni. Works perfectly.
-----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Cardone, Giovanni Sent: 17 October 2017 14:07 To: [hidden email] Subject: Re: Measure + label with result macro Hi Till, below is a modification of your macro, based on my understanding of your specifications. It can be expanded if different selections/measures want to be included. Everything is handled through overlays, including the labeling. ITH, Giovanni macro "measure and label" { if (nImages==0) { exit("No images are open"); } imageTitle = getTitle(); type = selectionType(); // in case the user forgot to make a selection if (type == -1) { waitForUser("Draw a ROI on the image " + imageTitle + " and press OK"); } type = selectionType(); // check selection type and measure to perform if (type==1 || type==2) { field = "Area"; } else if (type==5) { field = "Length"; } else if (type==8) { field = "Angle"; } else { exit("I don't know what to do"); } run("Measure"); label = "" + getResult(field, nResults-1); // get top left coordinates of bounding box getSelectionBounds(x, y, width, height); // add selection and measure as overlays Overlay.addSelection; Overlay.drawString(label, x, y) } -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of OMANSEN, Till Frederik Sent: Dienstag, 17. Oktober 2017 11:50 To: [hidden email] Subject: Measure + label with result macro Hello! I’m looking for a macro with which I can a) measure an angle, or distance (line tool) or area (oval or polygon selection tool) b) display the result of that measurement (i.e. angle, or area or length) c) adds this selection to the overlay in yellow. So far especially b proved to be difficult most macros I found just lable with A,B,C or numbers not with the result. So I found this one but it does not work.. macro "Measure and Label [m]" { run("Measure"); label = "" + getResult("Length", nResults-1); if (label=="NaN" || label=="0") label = "" + getResult("Area", nResults-1); label = "" + getResult("Angle", nResults-1); Roi.setName(label); Overlay.addSelection; } Maybe someone can help to debug? Thanks, Till -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |