Hello,
I have a macro which detects cell spheroids (i.e. compact cellular aggregats) in pictures taken with a confocal microscope. Is it possible to write additional lines of code to display Feret's diameter for each spheroid on the analyzed image? Thank you, Mikael F. |
> On Jul 16, 2015, at 11:21 AM, mikael.f <[hidden email]> wrote:
> > Hello, > > I have a macro which detects cell spheroids (i.e. compact cellular > aggregats) in pictures taken with a confocal microscope. Is it possible to > write additional lines of code to display Feret's diameter for each spheroid > on the analyzed image? The following example macro uses the particle analyzer to outline and measure objects in the Blobs sample image and then uses the “FeretX”, “FeretY”, “Feret” and “FeretAngle” values from the Results Table to display the Feret's diameter on each object. -wayne run("Blobs (25K)"); setAutoThreshold("Default"); run("Set Measurements...", "area mean feret's decimal=4"); run("Analyze Particles...", " show=[Overlay Outlines] display exclude clear"); resetThreshold(); Overlay.drawLabels(false); for (i=0; i<nResults; i++) { x1 = getResult("FeretX",i); y1 = getResult("FeretY",i); length = getResult("Feret",i); degrees = getResult("FeretAngle",i); if (degrees>90) degrees -= 180; angle = degrees*PI/180; x2 = x1 + cos(angle)*length; y2 = y1 - sin(angle)*length; makeLine(x1, y1, x2, y2); Overlay.addSelection("red"); } -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thank you so much for your help. When I try to integrate that code in my original program, it can not display the line despite doing all the calculations needed. Here is the most recent version of my macro:
*open picture // Analysis run("8-bit Color", "number=256"); run("Set Scale...", "distance=247.25 known=750 pixel=1 unit=um"); run("Set Measurements...", "area mean feret's redirect=None decimal=3"); run("Auto Threshold", "method=Otsu white"); setOption("BlackBackground", false); run("Make Binary"); run("Median...", "radius=1"); run("Analyze Particles...", "size=40000-Infinity show=[Overlay Outlines] display exclude include add"); // Displaying Feret's diameter resetThreshold(); Overlay.drawLabels(false); for (i=0; i<nResults; i++) { x1 = getResult("FeretX",i); y1 = getResult("FeretY",i); length = getResult("Feret",i); degrees = getResult("FeretAngle",i); if (degrees>90) degrees -= 180; angle = degrees*PI/180; x2 = x1 + cos(angle)*length; y2 = y1 - sin(angle)*length; makeLine(x1, y1, x2, y2); Overlay.addSelection("red"); } |
Hi Mikael,
it's not a good idea to convert an image to 8-bit Color before thresholding; the results are unpredictable and usually you won't get anything that is suitable for thresholding. It may easily happen that 'Analyze Particles' fails with such an image because the background is one big particle. If you start with an RGB image, here are better methods: - Before thresholding (1) convert it to greyscale, or (2) convert it to HSB, Lab or RGB channels and use one of the channels or a combination thereof (Image Calculator), or (3) use Gabriel Landini's color deconvolution, or - use one of these steps instead of thresholding the grayscale image: (4) Image>Adjust>Color Threshold, or (5) in Fiji the Trainable Weka Segmentation, or (6) the Versatile Wand plugin and convert the selection to a mask. By the way, in your macro it seems that many quote characters (") got replaced by " and the mailer has introduced a line feed in the "Analyze Particles" line. One more remark: you can use the built-in ImageJ setAutoThreshold("Otsu") [it assumes white background unless you add 'dark' to the argument string]; you don't need the external "Auto Threshold" plugin any more. Michael ________________________________________________________________ On Jul 17, 2015, at 14:45, mikael.f wrote: > Thank you so much for your help. When I try to integrate that code in my > original program, it can not display the line despite doing all the > calculations needed. Here is the most recent version of my macro: > > *open picture > // Analysis > run("8-bit Color", "number=256"); > run("Set Scale...", "distance=247.25 known=750 pixel=1 unit=um"); > run("Set Measurements...", "area mean feret's redirect=None decimal=3"); > run("Auto Threshold", "method=Otsu white"); > ... -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |