Analyze particles Exclude edge particles not working when automated

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Analyze particles Exclude edge particles not working when automated

Mariam Shirdel
Hi!
I'm trying to analyse images of particles similar to the image I have attached. When I do this manually in ImageJ exclude edge particles in Analyze Particles works fine. When I try to use a macro I've modified everything works except for exclude edge particles. I can use the command and Analyze Particles works and I get all of the results, it's just that exclude edge particles is ignored. I've tried to figure out what I'm doing wrong, but I really can't find it. Does anyone know what could be wrong?

The whole macro is:

requires("1.33s"); //display a message and aborts the macro if the ImageJ version is less than the one specified.

print("\\Clear");
run("Clear Results");

//Set the correct measurements
run("Set Measurements...", "area perimeter fit shape area_fraction redirect=None decimal=3");
setBatchMode(false);
rolling = 50; // the rolling ball background subtraction diameter
sigma = 1.0; // the sigma diameter for Gaussian blur
thresholdMethod = newArray("Default", "Huang", "Intermodes", "IsoData", "Li", "MaxEntropy", "Mean", "MinError(I)", "Minimum", "Moments", "Otsu", "Percentile", "RenyiEntropy", "Shanbhag", "Triangle", "Yen"); // the threshold method applied by Multithresholder
minCirc = 0.00; // the minimum circularity for a particle
maxCirc = 1.00; // the maximum circularity for a particle
excludeEdge = true;
APExclude = "";
watershed = false;

//Prompt for a folder that contains the images and text files from the ESEM
dir = getDirectory("Choose a Directory ");

//Get the correct values to set the scale
distance_pixels = getNumber("Distance in pixels?", 313);
known_um = getNumber("Known distance?", 200);
minArea = (known_um/distance_pixels)^2; // the minimum area to be considered as a particle in um, one pixel in um
maxArea = 10000; // the maximum area to be considered as a particle in um, equations only relevant for diameter of particle below 100 um

Dialog.create("Segmentation parameters");
Dialog.addNumber("Rolling ball diameter (0=don't subtract):", rolling); //1
Dialog.addNumber("Gaussian blur diameter (0=don't blur):", sigma); //2
Dialog.addChoice("Threshold method:", thresholdMethod); //3
//Dialog.addNumber("Minimum particle area (um):", minArea); //4
//Dialog.addString("Maximum particle area (um):", maxArea); //5
Dialog.addNumber("Minimum particle circularity:", minCirc); //6
Dialog.addNumber("Maximum particle circularity:", maxCirc); //7
Dialog.addCheckbox("Run watershed", watershed); //8
Dialog.addCheckbox("Exclude edge particles", excludeEdge); //9
Dialog.show();
rolling = Dialog.getNumber(); //1
sigma = Dialog.getNumber(); //2
thresholdMethod = Dialog.getChoice(); //3
//minArea = Dialog.getNumber(); //4
//maxArea = Dialog.getString(); //5
minCirc = Dialog.getNumber(); //6
maxCirc = Dialog.getNumber(); //7
watershed = Dialog.getCheckbox(); //8
excludeEdge = Dialog.getCheckbox(); //9

if (excludeEdge) //will be used later when Analyze Particle is run
                             APExclude = "exclude";

filenames = getFileList(dir);
for (i=0; i<filenames.length; i++){
                             imagefile = filenames[i];

                             //Open the image and set the scale for the image
                             open(dir + imagefile);
                             run("Set Scale...", "distance=distance_pixels known=known_um pixel=1 unit=um global");

                             //Subtract the background to minimize noise. 50 seems to work well.
                             if (rolling > 0)
                                                          run("Subtract Background...", "rolling=" + rolling); // + " light"

                             //Blur the image a bit.
                             if (sigma > 0)
                                                          run("Gaussian Blur...", "sigma=" + sigma);

                             //Use thresholding, IsoData (1) or Otsu (2) for CT, MaxEntropy (2) or RényiEntropy (1) for PC.
                             setAutoThreshold(thresholdMethod + " dark");
                             run("Threshold...");
                             setOption("BlackBackground", false);
                             run("Convert to Mask");

                             //Close the particles and fill the holes that might arise from closing.
                             run("Close-");
                             run("Fill Holes");

                             //Watershed gets a few more particles and segments particles that are supposed to be divided.
                             if (watershed)
                                                          run("Watershed");

                             //Analyze the particles in the image.
                             run("Analyze Particles...", "size=" + minArea + "-" + maxArea + " circularity=" + minCirc + "-" + maxCirc + " show=Outlines display " + APExclude + " clear summarize");

                             //Select the Results window
                             selectWindow("Results");
                             //Save the Results to a file both as .txt and .xls
                             //.txt
                             saveAs("text", dir + "Results_" + imagefile);
                             //.xls
                             index = lastIndexOf(imagefile, ".");
                             if (index!=-1)
                                                          imagefilenew = substring(imagefile, 0, index);
                             imagefilenew = imagefilenew + ".xls";
                             saveAs("Results", dir + "Results_" + imagefilenew);

                             //Select the particle outlines window
                             outlines = "Drawing of " + imagefile;
                             selectWindow(outlines);
                             //Save the outline drawing produced by the particle analysis
                             saveAs("tiff", dir + outlines);

                             //Copy the particle outlines window and add it to the original image file
                             close(imagefile);
                             open(dir + imagefile);
                             selectWindow(imagefile);
                             run("RGB Color"); //original image file is changed from 8-bit to RGB color
                             imageCalculator('AND', imagefile, outlines);
                             saveAs("tiff", dir + "Overlay_" + imagefile);

                             print("\\Clear");
                             run("Clear Results");
}

//Select the Summary window
selectWindow("Summary");
//Save the Summary to a txt file
saveAs("text", dir + "Summary");

//Create a file with all the information about how the image has been manipulated
criteriaPath = dir + "PSA_criteria.csv";
criteriaFile = File.open(criteriaPath);
print(criteriaFile, "rolling, sigma, thresholdMethod, minArea, maxArea, minCirc, maxCirc, excludeEdge, watershed, distance, known"); //writes to the open file criteriaFile
print(criteriaFile, rolling + ", " + sigma + ", " + thresholdMethod + ", " + minArea + ", " + maxArea + ", " + minCirc + ", " + maxCirc + ", " + excludeEdge + ", " + watershed + ", " + distance_pixels + ", " + known_um); //writes to the open file criteriaFile
File.close(criteriaFile);

//Close all open windows
close("\\Others");
close();
list = getList("window.titles");
for (j=0; j<list.length; j++){
     windowname = list[j];
     selectWindow(windowname);
     run("Close");
}

Best regards,
Mariam

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

PC3940_Compo_02.tif (1M) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Analyze particles Exclude edge particles not working when automated

Michael Schmid
Hi Miriam,

in Process>Binary>Options, there is an option "Pad edges when eroding"; your macro requires this.
(use Plugins>Macros>Record to see the macro code).
Without that option, the 'Close-' operation, which dilates and erodes the image, leaves a 1-pixel line at the border free, and your particles don't touch the edge any more.

Michael
________________________________________________________________
On Feb 18, 2015, at 13:57, Mariam Shirdel wrote:

> Hi!
> I'm trying to analyse images of particles similar to the image I have attached. When I do this manually in ImageJ exclude edge particles in Analyze Particles works fine. When I try to use a macro I've modified everything works except for exclude edge particles. I can use the command and Analyze Particles works and I get all of the results, it's just that exclude edge particles is ignored. I've tried to figure out what I'm doing wrong, but I really can't find it. Does anyone know what could be wrong?
>
> The whole macro is:
>
> requires("1.33s"); //display a message and aborts the macro if the ImageJ version is less than the one specified.
>
> print("\\Clear");
> run("Clear Results");
>
> //Set the correct measurements
> run("Set Measurements...", "area perimeter fit shape area_fraction redirect=None decimal=3");
> setBatchMode(false);
> rolling = 50; // the rolling ball background subtraction diameter
> sigma = 1.0; // the sigma diameter for Gaussian blur
> thresholdMethod = newArray("Default", "Huang", "Intermodes", "IsoData", "Li", "MaxEntropy", "Mean", "MinError(I)", "Minimum", "Moments", "Otsu", "Percentile", "RenyiEntropy", "Shanbhag", "Triangle", "Yen"); // the threshold method applied by Multithresholder
> minCirc = 0.00; // the minimum circularity for a particle
> maxCirc = 1.00; // the maximum circularity for a particle
> excludeEdge = true;
> APExclude = "";
> watershed = false;
>
> //Prompt for a folder that contains the images and text files from the ESEM
> dir = getDirectory("Choose a Directory ");
>
> //Get the correct values to set the scale
> distance_pixels = getNumber("Distance in pixels?", 313);
> known_um = getNumber("Known distance?", 200);
> minArea = (known_um/distance_pixels)^2; // the minimum area to be considered as a particle in um, one pixel in um
> maxArea = 10000; // the maximum area to be considered as a particle in um, equations only relevant for diameter of particle below 100 um
>
> Dialog.create("Segmentation parameters");
> Dialog.addNumber("Rolling ball diameter (0=don't subtract):", rolling); //1
> Dialog.addNumber("Gaussian blur diameter (0=don't blur):", sigma); //2
> Dialog.addChoice("Threshold method:", thresholdMethod); //3
> //Dialog.addNumber("Minimum particle area (um):", minArea); //4
> //Dialog.addString("Maximum particle area (um):", maxArea); //5
> Dialog.addNumber("Minimum particle circularity:", minCirc); //6
> Dialog.addNumber("Maximum particle circularity:", maxCirc); //7
> Dialog.addCheckbox("Run watershed", watershed); //8
> Dialog.addCheckbox("Exclude edge particles", excludeEdge); //9
> Dialog.show();
> rolling = Dialog.getNumber(); //1
> sigma = Dialog.getNumber(); //2
> thresholdMethod = Dialog.getChoice(); //3
> //minArea = Dialog.getNumber(); //4
> //maxArea = Dialog.getString(); //5
> minCirc = Dialog.getNumber(); //6
> maxCirc = Dialog.getNumber(); //7
> watershed = Dialog.getCheckbox(); //8
> excludeEdge = Dialog.getCheckbox(); //9
>
> if (excludeEdge) //will be used later when Analyze Particle is run
>                             APExclude = "exclude";
>
> filenames = getFileList(dir);
> for (i=0; i<filenames.length; i++){
>                             imagefile = filenames[i];
>
>                             //Open the image and set the scale for the image
>                             open(dir + imagefile);
>                             run("Set Scale...", "distance=distance_pixels known=known_um pixel=1 unit=um global");
>
>                             //Subtract the background to minimize noise. 50 seems to work well.
>                             if (rolling > 0)
>                                                          run("Subtract Background...", "rolling=" + rolling); // + " light"
>
>                             //Blur the image a bit.
>                             if (sigma > 0)
>                                                          run("Gaussian Blur...", "sigma=" + sigma);
>
>                             //Use thresholding, IsoData (1) or Otsu (2) for CT, MaxEntropy (2) or RényiEntropy (1) for PC.
>                             setAutoThreshold(thresholdMethod + " dark");
>                             run("Threshold...");
>                             setOption("BlackBackground", false);
>                             run("Convert to Mask");
>
>                             //Close the particles and fill the holes that might arise from closing.
>                             run("Close-");
>                             run("Fill Holes");
>
>                             //Watershed gets a few more particles and segments particles that are supposed to be divided.
>                             if (watershed)
>                                                          run("Watershed");
>
>                             //Analyze the particles in the image.
>                             run("Analyze Particles...", "size=" + minArea + "-" + maxArea + " circularity=" + minCirc + "-" + maxCirc + " show=Outlines display " + APExclude + " clear summarize");
>
>                             //Select the Results window
>                             selectWindow("Results");
>                             //Save the Results to a file both as .txt and .xls
>                             //.txt
>                             saveAs("text", dir + "Results_" + imagefile);
>                             //.xls
>                             index = lastIndexOf(imagefile, ".");
>                             if (index!=-1)
>                                                          imagefilenew = substring(imagefile, 0, index);
>                             imagefilenew = imagefilenew + ".xls";
>                             saveAs("Results", dir + "Results_" + imagefilenew);
>
>                             //Select the particle outlines window
>                             outlines = "Drawing of " + imagefile;
>                             selectWindow(outlines);
>                             //Save the outline drawing produced by the particle analysis
>                             saveAs("tiff", dir + outlines);
>
>                             //Copy the particle outlines window and add it to the original image file
>                             close(imagefile);
>                             open(dir + imagefile);
>                             selectWindow(imagefile);
>                             run("RGB Color"); //original image file is changed from 8-bit to RGB color
>                             imageCalculator('AND', imagefile, outlines);
>                             saveAs("tiff", dir + "Overlay_" + imagefile);
>
>                             print("\\Clear");
>                             run("Clear Results");
> }
>
> //Select the Summary window
> selectWindow("Summary");
> //Save the Summary to a txt file
> saveAs("text", dir + "Summary");
>
> //Create a file with all the information about how the image has been manipulated
> criteriaPath = dir + "PSA_criteria.csv";
> criteriaFile = File.open(criteriaPath);
> print(criteriaFile, "rolling, sigma, thresholdMethod, minArea, maxArea, minCirc, maxCirc, excludeEdge, watershed, distance, known"); //writes to the open file criteriaFile
> print(criteriaFile, rolling + ", " + sigma + ", " + thresholdMethod + ", " + minArea + ", " + maxArea + ", " + minCirc + ", " + maxCirc + ", " + excludeEdge + ", " + watershed + ", " + distance_pixels + ", " + known_um); //writes to the open file criteriaFile
> File.close(criteriaFile);
>
> //Close all open windows
> close("\\Others");
> close();
> list = getList("window.titles");
> for (j=0; j<list.length; j++){
>     windowname = list[j];
>     selectWindow(windowname);
>     run("Close");
> }
>
> Best regards,
> Mariam
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> <PC3940_Compo_02.tif>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Analyze particles Exclude edge particles not working when automated

Mariam Shirdel
It worked! Thank you :)

Is it possible to change the colour of Outlines in Analyze particles to red?

Best regards,
Mariam

----------------------------------------------------------------
Mariam Shirdel
PhD student
Phone nr: +4690 785 2755
                  +4676 820 5076
Address:  Occupational and Environmental Medicine
                 Umeå University
                 901 87 Umeå

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid
Sent: den 18 februari 2015 16:13
To: [hidden email]
Subject: Re: Analyze particles Exclude edge particles not working when automated

Hi Miriam,

in Process>Binary>Options, there is an option "Pad edges when eroding"; your macro requires this.
(use Plugins>Macros>Record to see the macro code).
Without that option, the 'Close-' operation, which dilates and erodes the image, leaves a 1-pixel line at the border free, and your particles don't touch the edge any more.

Michael
________________________________________________________________
On Feb 18, 2015, at 13:57, Mariam Shirdel wrote:

> Hi!
> I'm trying to analyse images of particles similar to the image I have attached. When I do this manually in ImageJ exclude edge particles in Analyze Particles works fine. When I try to use a macro I've modified everything works except for exclude edge particles. I can use the command and Analyze Particles works and I get all of the results, it's just that exclude edge particles is ignored. I've tried to figure out what I'm doing wrong, but I really can't find it. Does anyone know what could be wrong?
>
> The whole macro is:
>
> requires("1.33s"); //display a message and aborts the macro if the ImageJ version is less than the one specified.
>
> print("\\Clear");
> run("Clear Results");
>
> //Set the correct measurements
> run("Set Measurements...", "area perimeter fit shape area_fraction
> redirect=None decimal=3"); setBatchMode(false); rolling = 50; // the
> rolling ball background subtraction diameter sigma = 1.0; // the sigma
> diameter for Gaussian blur thresholdMethod = newArray("Default",
> "Huang", "Intermodes", "IsoData", "Li", "MaxEntropy", "Mean",
> "MinError(I)", "Minimum", "Moments", "Otsu", "Percentile",
> "RenyiEntropy", "Shanbhag", "Triangle", "Yen"); // the threshold
> method applied by Multithresholder minCirc = 0.00; // the minimum
> circularity for a particle maxCirc = 1.00; // the maximum circularity
> for a particle excludeEdge = true; APExclude = ""; watershed = false;
>
> //Prompt for a folder that contains the images and text files from the
> ESEM dir = getDirectory("Choose a Directory ");
>
> //Get the correct values to set the scale distance_pixels =
> getNumber("Distance in pixels?", 313); known_um = getNumber("Known
> distance?", 200); minArea = (known_um/distance_pixels)^2; // the
> minimum area to be considered as a particle in um, one pixel in um
> maxArea = 10000; // the maximum area to be considered as a particle in
> um, equations only relevant for diameter of particle below 100 um
>
> Dialog.create("Segmentation parameters"); Dialog.addNumber("Rolling
> ball diameter (0=don't subtract):", rolling); //1
> Dialog.addNumber("Gaussian blur diameter (0=don't blur):", sigma); //2
> Dialog.addChoice("Threshold method:", thresholdMethod); //3
> //Dialog.addNumber("Minimum particle area (um):", minArea); //4
> //Dialog.addString("Maximum particle area (um):", maxArea); //5
> Dialog.addNumber("Minimum particle circularity:", minCirc); //6
> Dialog.addNumber("Maximum particle circularity:", maxCirc); //7
> Dialog.addCheckbox("Run watershed", watershed); //8
> Dialog.addCheckbox("Exclude edge particles", excludeEdge); //9
> Dialog.show(); rolling = Dialog.getNumber(); //1 sigma =
> Dialog.getNumber(); //2 thresholdMethod = Dialog.getChoice(); //3
> //minArea = Dialog.getNumber(); //4 //maxArea = Dialog.getString();
> //5 minCirc = Dialog.getNumber(); //6 maxCirc = Dialog.getNumber();
> //7 watershed = Dialog.getCheckbox(); //8 excludeEdge =
> Dialog.getCheckbox(); //9
>
> if (excludeEdge) //will be used later when Analyze Particle is run
>                             APExclude = "exclude";
>
> filenames = getFileList(dir);
> for (i=0; i<filenames.length; i++){
>                             imagefile = filenames[i];
>
>                             //Open the image and set the scale for the image
>                             open(dir + imagefile);
>                             run("Set Scale...",
> "distance=distance_pixels known=known_um pixel=1 unit=um global");
>
>                             //Subtract the background to minimize noise. 50 seems to work well.
>                             if (rolling > 0)
>                                                          run("Subtract Background...", "rolling=" + rolling); // + " light"
>
>                             //Blur the image a bit.
>                             if (sigma > 0)
>                                                          run("Gaussian
> Blur...", "sigma=" + sigma);
>
>                             //Use thresholding, IsoData (1) or Otsu (2) for CT, MaxEntropy (2) or RényiEntropy (1) for PC.
>                             setAutoThreshold(thresholdMethod + " dark");
>                             run("Threshold...");
>                             setOption("BlackBackground", false);
>                             run("Convert to Mask");
>
>                             //Close the particles and fill the holes that might arise from closing.
>                             run("Close-");
>                             run("Fill Holes");
>
>                             //Watershed gets a few more particles and segments particles that are supposed to be divided.
>                             if (watershed)
>                                                          
> run("Watershed");
>
>                             //Analyze the particles in the image.
>                             run("Analyze Particles...", "size=" +
> minArea + "-" + maxArea + " circularity=" + minCirc + "-" + maxCirc +
> " show=Outlines display " + APExclude + " clear summarize");
>
>                             //Select the Results window
>                             selectWindow("Results");
>                             //Save the Results to a file both as .txt and .xls
>                             //.txt
>                             saveAs("text", dir + "Results_" + imagefile);
>                             //.xls
>                             index = lastIndexOf(imagefile, ".");
>                             if (index!=-1)
>                                                          imagefilenew = substring(imagefile, 0, index);
>                             imagefilenew = imagefilenew + ".xls";
>                             saveAs("Results", dir + "Results_" +
> imagefilenew);
>
>                             //Select the particle outlines window
>                             outlines = "Drawing of " + imagefile;
>                             selectWindow(outlines);
>                             //Save the outline drawing produced by the particle analysis
>                             saveAs("tiff", dir + outlines);
>
>                             //Copy the particle outlines window and add it to the original image file
>                             close(imagefile);
>                             open(dir + imagefile);
>                             selectWindow(imagefile);
>                             run("RGB Color"); //original image file is changed from 8-bit to RGB color
>                             imageCalculator('AND', imagefile, outlines);
>                             saveAs("tiff", dir + "Overlay_" +
> imagefile);
>
>                             print("\\Clear");
>                             run("Clear Results"); }
>
> //Select the Summary window
> selectWindow("Summary");
> //Save the Summary to a txt file
> saveAs("text", dir + "Summary");
>
> //Create a file with all the information about how the image has been
> manipulated criteriaPath = dir + "PSA_criteria.csv"; criteriaFile =
> File.open(criteriaPath); print(criteriaFile, "rolling, sigma,
> thresholdMethod, minArea, maxArea, minCirc, maxCirc, excludeEdge,
> watershed, distance, known"); //writes to the open file criteriaFile
> print(criteriaFile, rolling + ", " + sigma + ", " + thresholdMethod +
> ", " + minArea + ", " + maxArea + ", " + minCirc + ", " + maxCirc + ",
> " + excludeEdge + ", " + watershed + ", " + distance_pixels + ", " +
> known_um); //writes to the open file criteriaFile
> File.close(criteriaFile);
>
> //Close all open windows
> close("\\Others");
> close();
> list = getList("window.titles");
> for (j=0; j<list.length; j++){
>     windowname = list[j];
>     selectWindow(windowname);
>     run("Close");
> }
>
> Best regards,
> Mariam
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> <PC3940_Compo_02.tif>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Analyze particles Exclude edge particles not working when automated

Romain Guiet
Hi Mariam,
in Edit -> Options -> Colors...  , you can change "selection" color from yellow to the one you wish.
Cheers,
Romain

---------------------------------------------------------------
Dr. Romain Guiet
Bioimaging and Optics Platform (PT-BIOP)
Ecole Polytechnique Fédérale de Lausanne (EPFL)
Faculty of Life Sciences
Station 19, AI 0140
CH-1015 Lausanne

Phone: [+4121 69] 39629
http://biop.epfl.ch/
---------------------------------------------------------------

________________________________________
De : ImageJ Interest Group [[hidden email]] de la part de Mariam Shirdel [[hidden email]]
Envoyé : jeudi 19 février 2015 12:08
À : [hidden email]
Objet : Re: Analyze particles Exclude edge particles not working when automated

It worked! Thank you :)

Is it possible to change the colour of Outlines in Analyze particles to red?

Best regards,
Mariam

----------------------------------------------------------------
Mariam Shirdel
PhD student
Phone nr: +4690 785 2755
                  +4676 820 5076
Address:  Occupational and Environmental Medicine
                 Umeå University
                 901 87 Umeå

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid
Sent: den 18 februari 2015 16:13
To: [hidden email]
Subject: Re: Analyze particles Exclude edge particles not working when automated

Hi Miriam,

in Process>Binary>Options, there is an option "Pad edges when eroding"; your macro requires this.
(use Plugins>Macros>Record to see the macro code).
Without that option, the 'Close-' operation, which dilates and erodes the image, leaves a 1-pixel line at the border free, and your particles don't touch the edge any more.

Michael
________________________________________________________________
On Feb 18, 2015, at 13:57, Mariam Shirdel wrote:

> Hi!
> I'm trying to analyse images of particles similar to the image I have attached. When I do this manually in ImageJ exclude edge particles in Analyze Particles works fine. When I try to use a macro I've modified everything works except for exclude edge particles. I can use the command and Analyze Particles works and I get all of the results, it's just that exclude edge particles is ignored. I've tried to figure out what I'm doing wrong, but I really can't find it. Does anyone know what could be wrong?
>
> The whole macro is:
>
> requires("1.33s"); //display a message and aborts the macro if the ImageJ version is less than the one specified.
>
> print("\\Clear");
> run("Clear Results");
>
> //Set the correct measurements
> run("Set Measurements...", "area perimeter fit shape area_fraction
> redirect=None decimal=3"); setBatchMode(false); rolling = 50; // the
> rolling ball background subtraction diameter sigma = 1.0; // the sigma
> diameter for Gaussian blur thresholdMethod = newArray("Default",
> "Huang", "Intermodes", "IsoData", "Li", "MaxEntropy", "Mean",
> "MinError(I)", "Minimum", "Moments", "Otsu", "Percentile",
> "RenyiEntropy", "Shanbhag", "Triangle", "Yen"); // the threshold
> method applied by Multithresholder minCirc = 0.00; // the minimum
> circularity for a particle maxCirc = 1.00; // the maximum circularity
> for a particle excludeEdge = true; APExclude = ""; watershed = false;
>
> //Prompt for a folder that contains the images and text files from the
> ESEM dir = getDirectory("Choose a Directory ");
>
> //Get the correct values to set the scale distance_pixels =
> getNumber("Distance in pixels?", 313); known_um = getNumber("Known
> distance?", 200); minArea = (known_um/distance_pixels)^2; // the
> minimum area to be considered as a particle in um, one pixel in um
> maxArea = 10000; // the maximum area to be considered as a particle in
> um, equations only relevant for diameter of particle below 100 um
>
> Dialog.create("Segmentation parameters"); Dialog.addNumber("Rolling
> ball diameter (0=don't subtract):", rolling); //1
> Dialog.addNumber("Gaussian blur diameter (0=don't blur):", sigma); //2
> Dialog.addChoice("Threshold method:", thresholdMethod); //3
> //Dialog.addNumber("Minimum particle area (um):", minArea); //4
> //Dialog.addString("Maximum particle area (um):", maxArea); //5
> Dialog.addNumber("Minimum particle circularity:", minCirc); //6
> Dialog.addNumber("Maximum particle circularity:", maxCirc); //7
> Dialog.addCheckbox("Run watershed", watershed); //8
> Dialog.addCheckbox("Exclude edge particles", excludeEdge); //9
> Dialog.show(); rolling = Dialog.getNumber(); //1 sigma =
> Dialog.getNumber(); //2 thresholdMethod = Dialog.getChoice(); //3
> //minArea = Dialog.getNumber(); //4 //maxArea = Dialog.getString();
> //5 minCirc = Dialog.getNumber(); //6 maxCirc = Dialog.getNumber();
> //7 watershed = Dialog.getCheckbox(); //8 excludeEdge =
> Dialog.getCheckbox(); //9
>
> if (excludeEdge) //will be used later when Analyze Particle is run
>                             APExclude = "exclude";
>
> filenames = getFileList(dir);
> for (i=0; i<filenames.length; i++){
>                             imagefile = filenames[i];
>
>                             //Open the image and set the scale for the image
>                             open(dir + imagefile);
>                             run("Set Scale...",
> "distance=distance_pixels known=known_um pixel=1 unit=um global");
>
>                             //Subtract the background to minimize noise. 50 seems to work well.
>                             if (rolling > 0)
>                                                          run("Subtract Background...", "rolling=" + rolling); // + " light"
>
>                             //Blur the image a bit.
>                             if (sigma > 0)
>                                                          run("Gaussian
> Blur...", "sigma=" + sigma);
>
>                             //Use thresholding, IsoData (1) or Otsu (2) for CT, MaxEntropy (2) or RényiEntropy (1) for PC.
>                             setAutoThreshold(thresholdMethod + " dark");
>                             run("Threshold...");
>                             setOption("BlackBackground", false);
>                             run("Convert to Mask");
>
>                             //Close the particles and fill the holes that might arise from closing.
>                             run("Close-");
>                             run("Fill Holes");
>
>                             //Watershed gets a few more particles and segments particles that are supposed to be divided.
>                             if (watershed)
>
> run("Watershed");
>
>                             //Analyze the particles in the image.
>                             run("Analyze Particles...", "size=" +
> minArea + "-" + maxArea + " circularity=" + minCirc + "-" + maxCirc +
> " show=Outlines display " + APExclude + " clear summarize");
>
>                             //Select the Results window
>                             selectWindow("Results");
>                             //Save the Results to a file both as .txt and .xls
>                             //.txt
>                             saveAs("text", dir + "Results_" + imagefile);
>                             //.xls
>                             index = lastIndexOf(imagefile, ".");
>                             if (index!=-1)
>                                                          imagefilenew = substring(imagefile, 0, index);
>                             imagefilenew = imagefilenew + ".xls";
>                             saveAs("Results", dir + "Results_" +
> imagefilenew);
>
>                             //Select the particle outlines window
>                             outlines = "Drawing of " + imagefile;
>                             selectWindow(outlines);
>                             //Save the outline drawing produced by the particle analysis
>                             saveAs("tiff", dir + outlines);
>
>                             //Copy the particle outlines window and add it to the original image file
>                             close(imagefile);
>                             open(dir + imagefile);
>                             selectWindow(imagefile);
>                             run("RGB Color"); //original image file is changed from 8-bit to RGB color
>                             imageCalculator('AND', imagefile, outlines);
>                             saveAs("tiff", dir + "Overlay_" +
> imagefile);
>
>                             print("\\Clear");
>                             run("Clear Results"); }
>
> //Select the Summary window
> selectWindow("Summary");
> //Save the Summary to a txt file
> saveAs("text", dir + "Summary");
>
> //Create a file with all the information about how the image has been
> manipulated criteriaPath = dir + "PSA_criteria.csv"; criteriaFile =
> File.open(criteriaPath); print(criteriaFile, "rolling, sigma,
> thresholdMethod, minArea, maxArea, minCirc, maxCirc, excludeEdge,
> watershed, distance, known"); //writes to the open file criteriaFile
> print(criteriaFile, rolling + ", " + sigma + ", " + thresholdMethod +
> ", " + minArea + ", " + maxArea + ", " + minCirc + ", " + maxCirc + ",
> " + excludeEdge + ", " + watershed + ", " + distance_pixels + ", " +
> known_um); //writes to the open file criteriaFile
> File.close(criteriaFile);
>
> //Close all open windows
> close("\\Others");
> close();
> list = getList("window.titles");
> for (j=0; j<list.length; j++){
>     windowname = list[j];
>     selectWindow(windowname);
>     run("Close");
> }
>
> Best regards,
> Mariam
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> <PC3940_Compo_02.tif>

--
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
Reply | Threaded
Open this post in threaded view
|

Re: Analyze particles Exclude edge particles not working when automated

Mariam Shirdel
Hi!
That doesn't work for me, am I doing it wrong? The outlines from Analyze particles when I choose Show:Outlines gives me black outlines and red numbering, even when I make the suggested change in Edit -> Options -> Colors.

Best regards,
Mariam

----------------------------------------------------------------
Mariam Shirdel
PhD student
Phone nr: +4690 785 2755
                  +4676 820 5076
Address:  Occupational and Environmental Medicine
                 Umeå University
                 901 87 Umeå

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Guiet Romain
Sent: den 19 februari 2015 12:56
To: [hidden email]
Subject: Re: Analyze particles Exclude edge particles not working when automated

Hi Mariam,
in Edit -> Options -> Colors...  , you can change "selection" color from yellow to the one you wish.
Cheers,
Romain

---------------------------------------------------------------
Dr. Romain Guiet
Bioimaging and Optics Platform (PT-BIOP) Ecole Polytechnique Fédérale de Lausanne (EPFL) Faculty of Life Sciences Station 19, AI 0140
CH-1015 Lausanne

Phone: [+4121 69] 39629
http://biop.epfl.ch/
---------------------------------------------------------------

________________________________________
De : ImageJ Interest Group [[hidden email]] de la part de Mariam Shirdel [[hidden email]] Envoyé : jeudi 19 février 2015 12:08 À : [hidden email] Objet : Re: Analyze particles Exclude edge particles not working when automated

It worked! Thank you :)

Is it possible to change the colour of Outlines in Analyze particles to red?

Best regards,
Mariam

----------------------------------------------------------------
Mariam Shirdel
PhD student
Phone nr: +4690 785 2755
                  +4676 820 5076
Address:  Occupational and Environmental Medicine
                 Umeå University
                 901 87 Umeå

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid
Sent: den 18 februari 2015 16:13
To: [hidden email]
Subject: Re: Analyze particles Exclude edge particles not working when automated

Hi Miriam,

in Process>Binary>Options, there is an option "Pad edges when eroding"; your macro requires this.
(use Plugins>Macros>Record to see the macro code).
Without that option, the 'Close-' operation, which dilates and erodes the image, leaves a 1-pixel line at the border free, and your particles don't touch the edge any more.

Michael
________________________________________________________________
On Feb 18, 2015, at 13:57, Mariam Shirdel wrote:

> Hi!
> I'm trying to analyse images of particles similar to the image I have attached. When I do this manually in ImageJ exclude edge particles in Analyze Particles works fine. When I try to use a macro I've modified everything works except for exclude edge particles. I can use the command and Analyze Particles works and I get all of the results, it's just that exclude edge particles is ignored. I've tried to figure out what I'm doing wrong, but I really can't find it. Does anyone know what could be wrong?
>
> The whole macro is:
>
> requires("1.33s"); //display a message and aborts the macro if the ImageJ version is less than the one specified.
>
> print("\\Clear");
> run("Clear Results");
>
> //Set the correct measurements
> run("Set Measurements...", "area perimeter fit shape area_fraction
> redirect=None decimal=3"); setBatchMode(false); rolling = 50; // the
> rolling ball background subtraction diameter sigma = 1.0; // the sigma
> diameter for Gaussian blur thresholdMethod = newArray("Default",
> "Huang", "Intermodes", "IsoData", "Li", "MaxEntropy", "Mean",
> "MinError(I)", "Minimum", "Moments", "Otsu", "Percentile",
> "RenyiEntropy", "Shanbhag", "Triangle", "Yen"); // the threshold
> method applied by Multithresholder minCirc = 0.00; // the minimum
> circularity for a particle maxCirc = 1.00; // the maximum circularity
> for a particle excludeEdge = true; APExclude = ""; watershed = false;
>
> //Prompt for a folder that contains the images and text files from the
> ESEM dir = getDirectory("Choose a Directory ");
>
> //Get the correct values to set the scale distance_pixels =
> getNumber("Distance in pixels?", 313); known_um = getNumber("Known
> distance?", 200); minArea = (known_um/distance_pixels)^2; // the
> minimum area to be considered as a particle in um, one pixel in um
> maxArea = 10000; // the maximum area to be considered as a particle in
> um, equations only relevant for diameter of particle below 100 um
>
> Dialog.create("Segmentation parameters"); Dialog.addNumber("Rolling
> ball diameter (0=don't subtract):", rolling); //1
> Dialog.addNumber("Gaussian blur diameter (0=don't blur):", sigma); //2
> Dialog.addChoice("Threshold method:", thresholdMethod); //3
> //Dialog.addNumber("Minimum particle area (um):", minArea); //4
> //Dialog.addString("Maximum particle area (um):", maxArea); //5
> Dialog.addNumber("Minimum particle circularity:", minCirc); //6
> Dialog.addNumber("Maximum particle circularity:", maxCirc); //7
> Dialog.addCheckbox("Run watershed", watershed); //8
> Dialog.addCheckbox("Exclude edge particles", excludeEdge); //9
> Dialog.show(); rolling = Dialog.getNumber(); //1 sigma =
> Dialog.getNumber(); //2 thresholdMethod = Dialog.getChoice(); //3
> //minArea = Dialog.getNumber(); //4 //maxArea = Dialog.getString();
> //5 minCirc = Dialog.getNumber(); //6 maxCirc = Dialog.getNumber();
> //7 watershed = Dialog.getCheckbox(); //8 excludeEdge =
> Dialog.getCheckbox(); //9
>
> if (excludeEdge) //will be used later when Analyze Particle is run
>                             APExclude = "exclude";
>
> filenames = getFileList(dir);
> for (i=0; i<filenames.length; i++){
>                             imagefile = filenames[i];
>
>                             //Open the image and set the scale for the image
>                             open(dir + imagefile);
>                             run("Set Scale...",
> "distance=distance_pixels known=known_um pixel=1 unit=um global");
>
>                             //Subtract the background to minimize noise. 50 seems to work well.
>                             if (rolling > 0)
>                                                          run("Subtract Background...", "rolling=" + rolling); // + " light"
>
>                             //Blur the image a bit.
>                             if (sigma > 0)
>                                                          run("Gaussian
> Blur...", "sigma=" + sigma);
>
>                             //Use thresholding, IsoData (1) or Otsu (2) for CT, MaxEntropy (2) or RényiEntropy (1) for PC.
>                             setAutoThreshold(thresholdMethod + " dark");
>                             run("Threshold...");
>                             setOption("BlackBackground", false);
>                             run("Convert to Mask");
>
>                             //Close the particles and fill the holes that might arise from closing.
>                             run("Close-");
>                             run("Fill Holes");
>
>                             //Watershed gets a few more particles and segments particles that are supposed to be divided.
>                             if (watershed)
>
> run("Watershed");
>
>                             //Analyze the particles in the image.
>                             run("Analyze Particles...", "size=" +
> minArea + "-" + maxArea + " circularity=" + minCirc + "-" + maxCirc +
> " show=Outlines display " + APExclude + " clear summarize");
>
>                             //Select the Results window
>                             selectWindow("Results");
>                             //Save the Results to a file both as .txt and .xls
>                             //.txt
>                             saveAs("text", dir + "Results_" + imagefile);
>                             //.xls
>                             index = lastIndexOf(imagefile, ".");
>                             if (index!=-1)
>                                                          imagefilenew = substring(imagefile, 0, index);
>                             imagefilenew = imagefilenew + ".xls";
>                             saveAs("Results", dir + "Results_" +
> imagefilenew);
>
>                             //Select the particle outlines window
>                             outlines = "Drawing of " + imagefile;
>                             selectWindow(outlines);
>                             //Save the outline drawing produced by the particle analysis
>                             saveAs("tiff", dir + outlines);
>
>                             //Copy the particle outlines window and add it to the original image file
>                             close(imagefile);
>                             open(dir + imagefile);
>                             selectWindow(imagefile);
>                             run("RGB Color"); //original image file is changed from 8-bit to RGB color
>                             imageCalculator('AND', imagefile, outlines);
>                             saveAs("tiff", dir + "Overlay_" +
> imagefile);
>
>                             print("\\Clear");
>                             run("Clear Results"); }
>
> //Select the Summary window
> selectWindow("Summary");
> //Save the Summary to a txt file
> saveAs("text", dir + "Summary");
>
> //Create a file with all the information about how the image has been
> manipulated criteriaPath = dir + "PSA_criteria.csv"; criteriaFile =
> File.open(criteriaPath); print(criteriaFile, "rolling, sigma,
> thresholdMethod, minArea, maxArea, minCirc, maxCirc, excludeEdge,
> watershed, distance, known"); //writes to the open file criteriaFile
> print(criteriaFile, rolling + ", " + sigma + ", " + thresholdMethod +
> ", " + minArea + ", " + maxArea + ", " + minCirc + ", " + maxCirc + ",
> " + excludeEdge + ", " + watershed + ", " + distance_pixels + ", " +
> known_um); //writes to the open file criteriaFile
> File.close(criteriaFile);
>
> //Close all open windows
> close("\\Others");
> close();
> list = getList("window.titles");
> for (j=0; j<list.length; j++){
>     windowname = list[j];
>     selectWindow(windowname);
>     run("Close");
> }
>
> Best regards,
> Mariam
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> <PC3940_Compo_02.tif>

--
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

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Analyze particles Exclude edge particles not working when automated

Romain Guiet
My fault, I misunderstood your request...
my suggestion works if in ''analyze particles'' , you choose Show : Nothing and you select ''Add to Manager''.
Thus the ROIs will be colored as chooson in Edit -> Options -> Colors.
Cheers,
Romain


---------------------------------------------------------------
Dr. Romain Guiet
Bioimaging and Optics Platform (PT-BIOP)
Ecole Polytechnique Fédérale de Lausanne (EPFL)
Faculty of Life Sciences
Station 19, AI 0140
CH-1015 Lausanne

Phone: [+4121 69] 39629
http://biop.epfl.ch/
---------------------------------------------------------------

________________________________________
De : ImageJ Interest Group [[hidden email]] de la part de Mariam Shirdel [[hidden email]]
Envoyé : jeudi 19 février 2015 13:05
À : [hidden email]
Objet : Re: Analyze particles Exclude edge particles not working when automated

Hi!
That doesn't work for me, am I doing it wrong? The outlines from Analyze particles when I choose Show:Outlines gives me black outlines and red numbering, even when I make the suggested change in Edit -> Options -> Colors.

Best regards,
Mariam

----------------------------------------------------------------
Mariam Shirdel
PhD student
Phone nr: +4690 785 2755
                  +4676 820 5076
Address:  Occupational and Environmental Medicine
                 Umeå University
                 901 87 Umeå

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Guiet Romain
Sent: den 19 februari 2015 12:56
To: [hidden email]
Subject: Re: Analyze particles Exclude edge particles not working when automated

Hi Mariam,
in Edit -> Options -> Colors...  , you can change "selection" color from yellow to the one you wish.
Cheers,
Romain

---------------------------------------------------------------
Dr. Romain Guiet
Bioimaging and Optics Platform (PT-BIOP) Ecole Polytechnique Fédérale de Lausanne (EPFL) Faculty of Life Sciences Station 19, AI 0140
CH-1015 Lausanne

Phone: [+4121 69] 39629
http://biop.epfl.ch/
---------------------------------------------------------------

________________________________________
De : ImageJ Interest Group [[hidden email]] de la part de Mariam Shirdel [[hidden email]] Envoyé : jeudi 19 février 2015 12:08 À : [hidden email] Objet : Re: Analyze particles Exclude edge particles not working when automated

It worked! Thank you :)

Is it possible to change the colour of Outlines in Analyze particles to red?

Best regards,
Mariam

----------------------------------------------------------------
Mariam Shirdel
PhD student
Phone nr: +4690 785 2755
                  +4676 820 5076
Address:  Occupational and Environmental Medicine
                 Umeå University
                 901 87 Umeå

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid
Sent: den 18 februari 2015 16:13
To: [hidden email]
Subject: Re: Analyze particles Exclude edge particles not working when automated

Hi Miriam,

in Process>Binary>Options, there is an option "Pad edges when eroding"; your macro requires this.
(use Plugins>Macros>Record to see the macro code).
Without that option, the 'Close-' operation, which dilates and erodes the image, leaves a 1-pixel line at the border free, and your particles don't touch the edge any more.

Michael
________________________________________________________________
On Feb 18, 2015, at 13:57, Mariam Shirdel wrote:

> Hi!
> I'm trying to analyse images of particles similar to the image I have attached. When I do this manually in ImageJ exclude edge particles in Analyze Particles works fine. When I try to use a macro I've modified everything works except for exclude edge particles. I can use the command and Analyze Particles works and I get all of the results, it's just that exclude edge particles is ignored. I've tried to figure out what I'm doing wrong, but I really can't find it. Does anyone know what could be wrong?
>
> The whole macro is:
>
> requires("1.33s"); //display a message and aborts the macro if the ImageJ version is less than the one specified.
>
> print("\\Clear");
> run("Clear Results");
>
> //Set the correct measurements
> run("Set Measurements...", "area perimeter fit shape area_fraction
> redirect=None decimal=3"); setBatchMode(false); rolling = 50; // the
> rolling ball background subtraction diameter sigma = 1.0; // the sigma
> diameter for Gaussian blur thresholdMethod = newArray("Default",
> "Huang", "Intermodes", "IsoData", "Li", "MaxEntropy", "Mean",
> "MinError(I)", "Minimum", "Moments", "Otsu", "Percentile",
> "RenyiEntropy", "Shanbhag", "Triangle", "Yen"); // the threshold
> method applied by Multithresholder minCirc = 0.00; // the minimum
> circularity for a particle maxCirc = 1.00; // the maximum circularity
> for a particle excludeEdge = true; APExclude = ""; watershed = false;
>
> //Prompt for a folder that contains the images and text files from the
> ESEM dir = getDirectory("Choose a Directory ");
>
> //Get the correct values to set the scale distance_pixels =
> getNumber("Distance in pixels?", 313); known_um = getNumber("Known
> distance?", 200); minArea = (known_um/distance_pixels)^2; // the
> minimum area to be considered as a particle in um, one pixel in um
> maxArea = 10000; // the maximum area to be considered as a particle in
> um, equations only relevant for diameter of particle below 100 um
>
> Dialog.create("Segmentation parameters"); Dialog.addNumber("Rolling
> ball diameter (0=don't subtract):", rolling); //1
> Dialog.addNumber("Gaussian blur diameter (0=don't blur):", sigma); //2
> Dialog.addChoice("Threshold method:", thresholdMethod); //3
> //Dialog.addNumber("Minimum particle area (um):", minArea); //4
> //Dialog.addString("Maximum particle area (um):", maxArea); //5
> Dialog.addNumber("Minimum particle circularity:", minCirc); //6
> Dialog.addNumber("Maximum particle circularity:", maxCirc); //7
> Dialog.addCheckbox("Run watershed", watershed); //8
> Dialog.addCheckbox("Exclude edge particles", excludeEdge); //9
> Dialog.show(); rolling = Dialog.getNumber(); //1 sigma =
> Dialog.getNumber(); //2 thresholdMethod = Dialog.getChoice(); //3
> //minArea = Dialog.getNumber(); //4 //maxArea = Dialog.getString();
> //5 minCirc = Dialog.getNumber(); //6 maxCirc = Dialog.getNumber();
> //7 watershed = Dialog.getCheckbox(); //8 excludeEdge =
> Dialog.getCheckbox(); //9
>
> if (excludeEdge) //will be used later when Analyze Particle is run
>                             APExclude = "exclude";
>
> filenames = getFileList(dir);
> for (i=0; i<filenames.length; i++){
>                             imagefile = filenames[i];
>
>                             //Open the image and set the scale for the image
>                             open(dir + imagefile);
>                             run("Set Scale...",
> "distance=distance_pixels known=known_um pixel=1 unit=um global");
>
>                             //Subtract the background to minimize noise. 50 seems to work well.
>                             if (rolling > 0)
>                                                          run("Subtract Background...", "rolling=" + rolling); // + " light"
>
>                             //Blur the image a bit.
>                             if (sigma > 0)
>                                                          run("Gaussian
> Blur...", "sigma=" + sigma);
>
>                             //Use thresholding, IsoData (1) or Otsu (2) for CT, MaxEntropy (2) or RényiEntropy (1) for PC.
>                             setAutoThreshold(thresholdMethod + " dark");
>                             run("Threshold...");
>                             setOption("BlackBackground", false);
>                             run("Convert to Mask");
>
>                             //Close the particles and fill the holes that might arise from closing.
>                             run("Close-");
>                             run("Fill Holes");
>
>                             //Watershed gets a few more particles and segments particles that are supposed to be divided.
>                             if (watershed)
>
> run("Watershed");
>
>                             //Analyze the particles in the image.
>                             run("Analyze Particles...", "size=" +
> minArea + "-" + maxArea + " circularity=" + minCirc + "-" + maxCirc +
> " show=Outlines display " + APExclude + " clear summarize");
>
>                             //Select the Results window
>                             selectWindow("Results");
>                             //Save the Results to a file both as .txt and .xls
>                             //.txt
>                             saveAs("text", dir + "Results_" + imagefile);
>                             //.xls
>                             index = lastIndexOf(imagefile, ".");
>                             if (index!=-1)
>                                                          imagefilenew = substring(imagefile, 0, index);
>                             imagefilenew = imagefilenew + ".xls";
>                             saveAs("Results", dir + "Results_" +
> imagefilenew);
>
>                             //Select the particle outlines window
>                             outlines = "Drawing of " + imagefile;
>                             selectWindow(outlines);
>                             //Save the outline drawing produced by the particle analysis
>                             saveAs("tiff", dir + outlines);
>
>                             //Copy the particle outlines window and add it to the original image file
>                             close(imagefile);
>                             open(dir + imagefile);
>                             selectWindow(imagefile);
>                             run("RGB Color"); //original image file is changed from 8-bit to RGB color
>                             imageCalculator('AND', imagefile, outlines);
>                             saveAs("tiff", dir + "Overlay_" +
> imagefile);
>
>                             print("\\Clear");
>                             run("Clear Results"); }
>
> //Select the Summary window
> selectWindow("Summary");
> //Save the Summary to a txt file
> saveAs("text", dir + "Summary");
>
> //Create a file with all the information about how the image has been
> manipulated criteriaPath = dir + "PSA_criteria.csv"; criteriaFile =
> File.open(criteriaPath); print(criteriaFile, "rolling, sigma,
> thresholdMethod, minArea, maxArea, minCirc, maxCirc, excludeEdge,
> watershed, distance, known"); //writes to the open file criteriaFile
> print(criteriaFile, rolling + ", " + sigma + ", " + thresholdMethod +
> ", " + minArea + ", " + maxArea + ", " + minCirc + ", " + maxCirc + ",
> " + excludeEdge + ", " + watershed + ", " + distance_pixels + ", " +
> known_um); //writes to the open file criteriaFile
> File.close(criteriaFile);
>
> //Close all open windows
> close("\\Others");
> close();
> list = getList("window.titles");
> for (j=0; j<list.length; j++){
>     windowname = list[j];
>     selectWindow(windowname);
>     run("Close");
> }
>
> Best regards,
> Mariam
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> <PC3940_Compo_02.tif>

--
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

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Analyze particles Exclude edge particles not working when automated

Michael Schmid
In reply to this post by Mariam Shirdel
Hi Miriam,

in a macro, there is no option to set the default colors of the PartzicleAnalyzer's 'Outlines' image.

You can manipulate the color lookup table (LUT) afterwards, however. index [0] corresponds to the outlines, index [1] to the labels, and index [255] to the white background.

Select the 'Outlines' image so that it is in the foreground, then:
  getLut(reds, greens, blues);
  reds[0] = 255;  //red outlines
  setLut(reds, greens, blues);

Michael
________________________________________________________________
On Feb 19, 2015, at 12:08, Mariam Shirdel wrote:

> It worked! Thank you :)
>
> Is it possible to change the colour of Outlines in Analyze particles to red?
>
> Best regards,
> Mariam
>
> ----------------------------------------------------------------
> Mariam Shirdel
> PhD student
> Phone nr: +4690 785 2755
>                  +4676 820 5076
> Address:  Occupational and Environmental Medicine
>                  Umeå University
>                  901 87 Umeå
>
> -----Original Message-----
> From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid
> Sent: den 18 februari 2015 16:13
> To: [hidden email]
> Subject: Re: Analyze particles Exclude edge particles not working when automated
>
> Hi Miriam,
>
> in Process>Binary>Options, there is an option "Pad edges when eroding"; your macro requires this.
> (use Plugins>Macros>Record to see the macro code).
> Without that option, the 'Close-' operation, which dilates and erodes the image, leaves a 1-pixel line at the border free, and your particles don't touch the edge any more.
>
> Michael
> ________________________________________________________________
> On Feb 18, 2015, at 13:57, Mariam Shirdel wrote:
>
>> Hi!
>> I'm trying to analyse images of particles similar to the image I have attached. When I do this manually in ImageJ exclude edge particles in Analyze Particles works fine. When I try to use a macro I've modified everything works except for exclude edge particles. I can use the command and Analyze Particles works and I get all of the results, it's just that exclude edge particles is ignored. I've tried to figure out what I'm doing wrong, but I really can't find it. Does anyone know what could be wrong?
>>
>> The whole macro is:
>>
>> requires("1.33s"); //display a message and aborts the macro if the ImageJ version is less than the one specified.
>>
>> print("\\Clear");
>> run("Clear Results");
>>
>> //Set the correct measurements
>> run("Set Measurements...", "area perimeter fit shape area_fraction
>> redirect=None decimal=3"); setBatchMode(false); rolling = 50; // the
>> rolling ball background subtraction diameter sigma = 1.0; // the sigma
>> diameter for Gaussian blur thresholdMethod = newArray("Default",
>> "Huang", "Intermodes", "IsoData", "Li", "MaxEntropy", "Mean",
>> "MinError(I)", "Minimum", "Moments", "Otsu", "Percentile",
>> "RenyiEntropy", "Shanbhag", "Triangle", "Yen"); // the threshold
>> method applied by Multithresholder minCirc = 0.00; // the minimum
>> circularity for a particle maxCirc = 1.00; // the maximum circularity
>> for a particle excludeEdge = true; APExclude = ""; watershed = false;
>>
>> //Prompt for a folder that contains the images and text files from the
>> ESEM dir = getDirectory("Choose a Directory ");
>>
>> //Get the correct values to set the scale distance_pixels =
>> getNumber("Distance in pixels?", 313); known_um = getNumber("Known
>> distance?", 200); minArea = (known_um/distance_pixels)^2; // the
>> minimum area to be considered as a particle in um, one pixel in um
>> maxArea = 10000; // the maximum area to be considered as a particle in
>> um, equations only relevant for diameter of particle below 100 um
>>
>> Dialog.create("Segmentation parameters"); Dialog.addNumber("Rolling
>> ball diameter (0=don't subtract):", rolling); //1
>> Dialog.addNumber("Gaussian blur diameter (0=don't blur):", sigma); //2
>> Dialog.addChoice("Threshold method:", thresholdMethod); //3
>> //Dialog.addNumber("Minimum particle area (um):", minArea); //4
>> //Dialog.addString("Maximum particle area (um):", maxArea); //5
>> Dialog.addNumber("Minimum particle circularity:", minCirc); //6
>> Dialog.addNumber("Maximum particle circularity:", maxCirc); //7
>> Dialog.addCheckbox("Run watershed", watershed); //8
>> Dialog.addCheckbox("Exclude edge particles", excludeEdge); //9
>> Dialog.show(); rolling = Dialog.getNumber(); //1 sigma =
>> Dialog.getNumber(); //2 thresholdMethod = Dialog.getChoice(); //3
>> //minArea = Dialog.getNumber(); //4 //maxArea = Dialog.getString();
>> //5 minCirc = Dialog.getNumber(); //6 maxCirc = Dialog.getNumber();
>> //7 watershed = Dialog.getCheckbox(); //8 excludeEdge =
>> Dialog.getCheckbox(); //9
>>
>> if (excludeEdge) //will be used later when Analyze Particle is run
>>                            APExclude = "exclude";
>>
>> filenames = getFileList(dir);
>> for (i=0; i<filenames.length; i++){
>>                            imagefile = filenames[i];
>>
>>                            //Open the image and set the scale for the image
>>                            open(dir + imagefile);
>>                            run("Set Scale...",
>> "distance=distance_pixels known=known_um pixel=1 unit=um global");
>>
>>                            //Subtract the background to minimize noise. 50 seems to work well.
>>                            if (rolling > 0)
>>                                                         run("Subtract Background...", "rolling=" + rolling); // + " light"
>>
>>                            //Blur the image a bit.
>>                            if (sigma > 0)
>>                                                         run("Gaussian
>> Blur...", "sigma=" + sigma);
>>
>>                            //Use thresholding, IsoData (1) or Otsu (2) for CT, MaxEntropy (2) or RényiEntropy (1) for PC.
>>                            setAutoThreshold(thresholdMethod + " dark");
>>                            run("Threshold...");
>>                            setOption("BlackBackground", false);
>>                            run("Convert to Mask");
>>
>>                            //Close the particles and fill the holes that might arise from closing.
>>                            run("Close-");
>>                            run("Fill Holes");
>>
>>                            //Watershed gets a few more particles and segments particles that are supposed to be divided.
>>                            if (watershed)
>>
>> run("Watershed");
>>
>>                            //Analyze the particles in the image.
>>                            run("Analyze Particles...", "size=" +
>> minArea + "-" + maxArea + " circularity=" + minCirc + "-" + maxCirc +
>> " show=Outlines display " + APExclude + " clear summarize");
>>
>>                            //Select the Results window
>>                            selectWindow("Results");
>>                            //Save the Results to a file both as .txt and .xls
>>                            //.txt
>>                            saveAs("text", dir + "Results_" + imagefile);
>>                            //.xls
>>                            index = lastIndexOf(imagefile, ".");
>>                            if (index!=-1)
>>                                                         imagefilenew = substring(imagefile, 0, index);
>>                            imagefilenew = imagefilenew + ".xls";
>>                            saveAs("Results", dir + "Results_" +
>> imagefilenew);
>>
>>                            //Select the particle outlines window
>>                            outlines = "Drawing of " + imagefile;
>>                            selectWindow(outlines);
>>                            //Save the outline drawing produced by the particle analysis
>>                            saveAs("tiff", dir + outlines);
>>
>>                            //Copy the particle outlines window and add it to the original image file
>>                            close(imagefile);
>>                            open(dir + imagefile);
>>                            selectWindow(imagefile);
>>                            run("RGB Color"); //original image file is changed from 8-bit to RGB color
>>                            imageCalculator('AND', imagefile, outlines);
>>                            saveAs("tiff", dir + "Overlay_" +
>> imagefile);
>>
>>                            print("\\Clear");
>>                            run("Clear Results"); }
>>
>> //Select the Summary window
>> selectWindow("Summary");
>> //Save the Summary to a txt file
>> saveAs("text", dir + "Summary");
>>
>> //Create a file with all the information about how the image has been
>> manipulated criteriaPath = dir + "PSA_criteria.csv"; criteriaFile =
>> File.open(criteriaPath); print(criteriaFile, "rolling, sigma,
>> thresholdMethod, minArea, maxArea, minCirc, maxCirc, excludeEdge,
>> watershed, distance, known"); //writes to the open file criteriaFile
>> print(criteriaFile, rolling + ", " + sigma + ", " + thresholdMethod +
>> ", " + minArea + ", " + maxArea + ", " + minCirc + ", " + maxCirc + ",
>> " + excludeEdge + ", " + watershed + ", " + distance_pixels + ", " +
>> known_um); //writes to the open file criteriaFile
>> File.close(criteriaFile);
>>
>> //Close all open windows
>> close("\\Others");
>> close();
>> list = getList("window.titles");
>> for (j=0; j<list.length; j++){
>>    windowname = list[j];
>>    selectWindow(windowname);
>>    run("Close");
>> }
>>
>> Best regards,
>> Mariam
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>> <PC3940_Compo_02.tif>
>
> --
> 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
Reply | Threaded
Open this post in threaded view
|

Re: Analyze particles Exclude edge particles not working when automated

Mariam Shirdel
Thanks Michael, that did the trick!
Is it possible to set the linewidth of the Outlines? By making them red they are more visible now, but in the really dark images the red isn't visible enough. I tried with the setLineWidth(width) command, but it only worked once for one image.

Best regards,
Mariam

----------------------------------------------------------------
Mariam Shirdel
PhD student
Phone nr: +4690 785 2755
                  +4676 820 5076
Address:  Occupational and Environmental Medicine
                 Umeå University
                 901 87 Umeå

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid
Sent: den 19 februari 2015 15:56
To: [hidden email]
Subject: Re: Analyze particles Exclude edge particles not working when automated

Hi Miriam,

in a macro, there is no option to set the default colors of the PartzicleAnalyzer's 'Outlines' image.

You can manipulate the color lookup table (LUT) afterwards, however. index [0] corresponds to the outlines, index [1] to the labels, and index [255] to the white background.

Select the 'Outlines' image so that it is in the foreground, then:
  getLut(reds, greens, blues);
  reds[0] = 255;  //red outlines
  setLut(reds, greens, blues);

Michael
________________________________________________________________
On Feb 19, 2015, at 12:08, Mariam Shirdel wrote:

> It worked! Thank you :)
>
> Is it possible to change the colour of Outlines in Analyze particles to red?
>
> Best regards,
> Mariam
>
> ----------------------------------------------------------------
> Mariam Shirdel
> PhD student
> Phone nr: +4690 785 2755
>                  +4676 820 5076
> Address:  Occupational and Environmental Medicine
>                  Umeå University
>                  901 87 Umeå
>
> -----Original Message-----
> From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of
> Michael Schmid
> Sent: den 18 februari 2015 16:13
> To: [hidden email]
> Subject: Re: Analyze particles Exclude edge particles not working when
> automated
>
> Hi Miriam,
>
> in Process>Binary>Options, there is an option "Pad edges when eroding"; your macro requires this.
> (use Plugins>Macros>Record to see the macro code).
> Without that option, the 'Close-' operation, which dilates and erodes the image, leaves a 1-pixel line at the border free, and your particles don't touch the edge any more.
>
> Michael
> ________________________________________________________________
> On Feb 18, 2015, at 13:57, Mariam Shirdel wrote:
>
>> Hi!
>> I'm trying to analyse images of particles similar to the image I have attached. When I do this manually in ImageJ exclude edge particles in Analyze Particles works fine. When I try to use a macro I've modified everything works except for exclude edge particles. I can use the command and Analyze Particles works and I get all of the results, it's just that exclude edge particles is ignored. I've tried to figure out what I'm doing wrong, but I really can't find it. Does anyone know what could be wrong?
>>
>> The whole macro is:
>>
>> requires("1.33s"); //display a message and aborts the macro if the ImageJ version is less than the one specified.
>>
>> print("\\Clear");
>> run("Clear Results");
>>
>> //Set the correct measurements
>> run("Set Measurements...", "area perimeter fit shape area_fraction
>> redirect=None decimal=3"); setBatchMode(false); rolling = 50; // the
>> rolling ball background subtraction diameter sigma = 1.0; // the
>> sigma diameter for Gaussian blur thresholdMethod =
>> newArray("Default", "Huang", "Intermodes", "IsoData", "Li",
>> "MaxEntropy", "Mean", "MinError(I)", "Minimum", "Moments", "Otsu",
>> "Percentile", "RenyiEntropy", "Shanbhag", "Triangle", "Yen"); // the
>> threshold method applied by Multithresholder minCirc = 0.00; // the
>> minimum circularity for a particle maxCirc = 1.00; // the maximum
>> circularity for a particle excludeEdge = true; APExclude = "";
>> watershed = false;
>>
>> //Prompt for a folder that contains the images and text files from
>> the ESEM dir = getDirectory("Choose a Directory ");
>>
>> //Get the correct values to set the scale distance_pixels =
>> getNumber("Distance in pixels?", 313); known_um = getNumber("Known
>> distance?", 200); minArea = (known_um/distance_pixels)^2; // the
>> minimum area to be considered as a particle in um, one pixel in um
>> maxArea = 10000; // the maximum area to be considered as a particle
>> in um, equations only relevant for diameter of particle below 100 um
>>
>> Dialog.create("Segmentation parameters"); Dialog.addNumber("Rolling
>> ball diameter (0=don't subtract):", rolling); //1
>> Dialog.addNumber("Gaussian blur diameter (0=don't blur):", sigma);
>> //2 Dialog.addChoice("Threshold method:", thresholdMethod); //3
>> //Dialog.addNumber("Minimum particle area (um):", minArea); //4
>> //Dialog.addString("Maximum particle area (um):", maxArea); //5
>> Dialog.addNumber("Minimum particle circularity:", minCirc); //6
>> Dialog.addNumber("Maximum particle circularity:", maxCirc); //7
>> Dialog.addCheckbox("Run watershed", watershed); //8
>> Dialog.addCheckbox("Exclude edge particles", excludeEdge); //9
>> Dialog.show(); rolling = Dialog.getNumber(); //1 sigma =
>> Dialog.getNumber(); //2 thresholdMethod = Dialog.getChoice(); //3
>> //minArea = Dialog.getNumber(); //4 //maxArea = Dialog.getString();
>> //5 minCirc = Dialog.getNumber(); //6 maxCirc = Dialog.getNumber();
>> //7 watershed = Dialog.getCheckbox(); //8 excludeEdge =
>> Dialog.getCheckbox(); //9
>>
>> if (excludeEdge) //will be used later when Analyze Particle is run
>>                            APExclude = "exclude";
>>
>> filenames = getFileList(dir);
>> for (i=0; i<filenames.length; i++){
>>                            imagefile = filenames[i];
>>
>>                            //Open the image and set the scale for the image
>>                            open(dir + imagefile);
>>                            run("Set Scale...",
>> "distance=distance_pixels known=known_um pixel=1 unit=um global");
>>
>>                            //Subtract the background to minimize noise. 50 seems to work well.
>>                            if (rolling > 0)
>>                                                         run("Subtract Background...", "rolling=" + rolling); // + " light"
>>
>>                            //Blur the image a bit.
>>                            if (sigma > 0)
>>                                                         run("Gaussian
>> Blur...", "sigma=" + sigma);
>>
>>                            //Use thresholding, IsoData (1) or Otsu (2) for CT, MaxEntropy (2) or RényiEntropy (1) for PC.
>>                            setAutoThreshold(thresholdMethod + " dark");
>>                            run("Threshold...");
>>                            setOption("BlackBackground", false);
>>                            run("Convert to Mask");
>>
>>                            //Close the particles and fill the holes that might arise from closing.
>>                            run("Close-");
>>                            run("Fill Holes");
>>
>>                            //Watershed gets a few more particles and segments particles that are supposed to be divided.
>>                            if (watershed)
>>
>> run("Watershed");
>>
>>                            //Analyze the particles in the image.
>>                            run("Analyze Particles...", "size=" +
>> minArea + "-" + maxArea + " circularity=" + minCirc + "-" + maxCirc +
>> " show=Outlines display " + APExclude + " clear summarize");
>>
>>                            //Select the Results window
>>                            selectWindow("Results");
>>                            //Save the Results to a file both as .txt and .xls
>>                            //.txt
>>                            saveAs("text", dir + "Results_" + imagefile);
>>                            //.xls
>>                            index = lastIndexOf(imagefile, ".");
>>                            if (index!=-1)
>>                                                         imagefilenew = substring(imagefile, 0, index);
>>                            imagefilenew = imagefilenew + ".xls";
>>                            saveAs("Results", dir + "Results_" +
>> imagefilenew);
>>
>>                            //Select the particle outlines window
>>                            outlines = "Drawing of " + imagefile;
>>                            selectWindow(outlines);
>>                            //Save the outline drawing produced by the particle analysis
>>                            saveAs("tiff", dir + outlines);
>>
>>                            //Copy the particle outlines window and add it to the original image file
>>                            close(imagefile);
>>                            open(dir + imagefile);
>>                            selectWindow(imagefile);
>>                            run("RGB Color"); //original image file is changed from 8-bit to RGB color
>>                            imageCalculator('AND', imagefile, outlines);
>>                            saveAs("tiff", dir + "Overlay_" +
>> imagefile);
>>
>>                            print("\\Clear");
>>                            run("Clear Results"); }
>>
>> //Select the Summary window
>> selectWindow("Summary");
>> //Save the Summary to a txt file
>> saveAs("text", dir + "Summary");
>>
>> //Create a file with all the information about how the image has been
>> manipulated criteriaPath = dir + "PSA_criteria.csv"; criteriaFile =
>> File.open(criteriaPath); print(criteriaFile, "rolling, sigma,
>> thresholdMethod, minArea, maxArea, minCirc, maxCirc, excludeEdge,
>> watershed, distance, known"); //writes to the open file criteriaFile
>> print(criteriaFile, rolling + ", " + sigma + ", " + thresholdMethod +
>> ", " + minArea + ", " + maxArea + ", " + minCirc + ", " + maxCirc +
>> ", " + excludeEdge + ", " + watershed + ", " + distance_pixels + ", "
>> + known_um); //writes to the open file criteriaFile
>> File.close(criteriaFile);
>>
>> //Close all open windows
>> close("\\Others");
>> close();
>> list = getList("window.titles");
>> for (j=0; j<list.length; j++){
>>    windowname = list[j];
>>    selectWindow(windowname);
>>    run("Close");
>> }
>>
>> Best regards,
>> Mariam
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>> <PC3940_Compo_02.tif>
>
> --
> 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

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Analyze particles Exclude edge particles not working when automated

Michael Schmid
Hi Miriam,

as far as I know, you can't set the line width of the PartzicleAnalyzer's 'Outlines', but you can run Process>Filters>Minimum to make everything thicker. Unfortunately, this will make the labels difficult to read.

But it seems you want to have everything as an overlay to your image? Then you could also add the particles to the ROI Manager. In a macro you can iterate through all Rois in the ROI Manager and set the appearance:

Roi.setStrokeColor("red");
Roi.setStrokeWidth(2);
Roi.setFillColor("20ffff00"); //yellow, '20'= very transparent

If you create an Overlay from the ROI Manager and save the image as png, it saves the image with the ROIs superimposed.

Michael
________________________________________________________________
On Feb 19, 2015, at 23:32, Mariam Shirdel wrote:

> Thanks Michael, that did the trick!
> Is it possible to set the linewidth of the Outlines? By making them red they are more visible now, but in the really dark images the red isn't visible enough. I tried with the setLineWidth(width) command, but it only worked once for one image.
>
> Best regards,
> Mariam
>
> -----Original Message-----
> From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid
> Sent: den 19 februari 2015 15:56
> To: [hidden email]
> Subject: Re: Analyze particles Exclude edge particles not working when automated
>
> Hi Miriam,
>
> in a macro, there is no option to set the default colors of the PartzicleAnalyzer's 'Outlines' image.
>
> You can manipulate the color lookup table (LUT) afterwards, however. index [0] corresponds to the outlines, index [1] to the labels, and index [255] to the white background.
>
> Select the 'Outlines' image so that it is in the foreground, then:
> getLut(reds, greens, blues);
> reds[0] = 255;  //red outlines
> setLut(reds, greens, blues);
>
> Michael
> ________________________________________________________________
> On Feb 19, 2015, at 12:08, Mariam Shirdel wrote:
>
>> It worked! Thank you :)
>>
>> Is it possible to change the colour of Outlines in Analyze particles to red?
>>
>> Best regards,
>> Mariam
>>
>> ----------------------------------------------------------------
>> Mariam Shirdel
>> PhD student
>> Phone nr: +4690 785 2755
>>                +4676 820 5076
>> Address:  Occupational and Environmental Medicine
>>                Umeå University
>>                901 87 Umeå
>>
>> -----Original Message-----
>> From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of
>> Michael Schmid
>> Sent: den 18 februari 2015 16:13
>> To: [hidden email]
>> Subject: Re: Analyze particles Exclude edge particles not working when
>> automated
>>
>> Hi Miriam,
>>
>> in Process>Binary>Options, there is an option "Pad edges when eroding"; your macro requires this.
>> (use Plugins>Macros>Record to see the macro code).
>> Without that option, the 'Close-' operation, which dilates and erodes the image, leaves a 1-pixel line at the border free, and your particles don't touch the edge any more.
>>
>> Michael
>> ________________________________________________________________
>> On Feb 18, 2015, at 13:57, Mariam Shirdel wrote:
>>
>>> Hi!
>>> I'm trying to analyse images of particles similar to the image I have attached. When I do this manually in ImageJ exclude edge particles in Analyze Particles works fine. When I try to use a macro I've modified everything works except for exclude edge particles. I can use the command and Analyze Particles works and I get all of the results, it's just that exclude edge particles is ignored. I've tried to figure out what I'm doing wrong, but I really can't find it. Does anyone know what could be wrong?
>>>
>>> The whole macro is:
>>>
>>> requires("1.33s"); //display a message and aborts the macro if the ImageJ version is less than the one specified.
>>>
>>> print("\\Clear");
>>> run("Clear Results");
>>>
>>> //Set the correct measurements
>>> run("Set Measurements...", "area perimeter fit shape area_fraction
>>> redirect=None decimal=3"); setBatchMode(false); rolling = 50; // the
>>> rolling ball background subtraction diameter sigma = 1.0; // the
>>> sigma diameter for Gaussian blur thresholdMethod =
>>> newArray("Default", "Huang", "Intermodes", "IsoData", "Li",
>>> "MaxEntropy", "Mean", "MinError(I)", "Minimum", "Moments", "Otsu",
>>> "Percentile", "RenyiEntropy", "Shanbhag", "Triangle", "Yen"); // the
>>> threshold method applied by Multithresholder minCirc = 0.00; // the
>>> minimum circularity for a particle maxCirc = 1.00; // the maximum
>>> circularity for a particle excludeEdge = true; APExclude = "";
>>> watershed = false;
>>>
>>> //Prompt for a folder that contains the images and text files from
>>> the ESEM dir = getDirectory("Choose a Directory ");
>>>
>>> //Get the correct values to set the scale distance_pixels =
>>> getNumber("Distance in pixels?", 313); known_um = getNumber("Known
>>> distance?", 200); minArea = (known_um/distance_pixels)^2; // the
>>> minimum area to be considered as a particle in um, one pixel in um
>>> maxArea = 10000; // the maximum area to be considered as a particle
>>> in um, equations only relevant for diameter of particle below 100 um
>>>
>>> Dialog.create("Segmentation parameters"); Dialog.addNumber("Rolling
>>> ball diameter (0=don't subtract):", rolling); //1
>>> Dialog.addNumber("Gaussian blur diameter (0=don't blur):", sigma);
>>> //2 Dialog.addChoice("Threshold method:", thresholdMethod); //3
>>> //Dialog.addNumber("Minimum particle area (um):", minArea); //4
>>> //Dialog.addString("Maximum particle area (um):", maxArea); //5
>>> Dialog.addNumber("Minimum particle circularity:", minCirc); //6
>>> Dialog.addNumber("Maximum particle circularity:", maxCirc); //7
>>> Dialog.addCheckbox("Run watershed", watershed); //8
>>> Dialog.addCheckbox("Exclude edge particles", excludeEdge); //9
>>> Dialog.show(); rolling = Dialog.getNumber(); //1 sigma =
>>> Dialog.getNumber(); //2 thresholdMethod = Dialog.getChoice(); //3
>>> //minArea = Dialog.getNumber(); //4 //maxArea = Dialog.getString();
>>> //5 minCirc = Dialog.getNumber(); //6 maxCirc = Dialog.getNumber();
>>> //7 watershed = Dialog.getCheckbox(); //8 excludeEdge =
>>> Dialog.getCheckbox(); //9
>>>
>>> if (excludeEdge) //will be used later when Analyze Particle is run
>>>                          APExclude = "exclude";
>>>
>>> filenames = getFileList(dir);
>>> for (i=0; i<filenames.length; i++){
>>>                          imagefile = filenames[i];
>>>
>>>                          //Open the image and set the scale for the image
>>>                          open(dir + imagefile);
>>>                          run("Set Scale...",
>>> "distance=distance_pixels known=known_um pixel=1 unit=um global");
>>>
>>>                          //Subtract the background to minimize noise. 50 seems to work well.
>>>                          if (rolling > 0)
>>>                                                       run("Subtract Background...", "rolling=" + rolling); // + " light"
>>>
>>>                          //Blur the image a bit.
>>>                          if (sigma > 0)
>>>                                                       run("Gaussian
>>> Blur...", "sigma=" + sigma);
>>>
>>>                          //Use thresholding, IsoData (1) or Otsu (2) for CT, MaxEntropy (2) or RényiEntropy (1) for PC.
>>>                          setAutoThreshold(thresholdMethod + " dark");
>>>                          run("Threshold...");
>>>                          setOption("BlackBackground", false);
>>>                          run("Convert to Mask");
>>>
>>>                          //Close the particles and fill the holes that might arise from closing.
>>>                          run("Close-");
>>>                          run("Fill Holes");
>>>
>>>                          //Watershed gets a few more particles and segments particles that are supposed to be divided.
>>>                          if (watershed)
>>>
>>> run("Watershed");
>>>
>>>                          //Analyze the particles in the image.
>>>                          run("Analyze Particles...", "size=" +
>>> minArea + "-" + maxArea + " circularity=" + minCirc + "-" + maxCirc +
>>> " show=Outlines display " + APExclude + " clear summarize");
>>>
>>>                          //Select the Results window
>>>                          selectWindow("Results");
>>>                          //Save the Results to a file both as .txt and .xls
>>>                          //.txt
>>>                          saveAs("text", dir + "Results_" + imagefile);
>>>                          //.xls
>>>                          index = lastIndexOf(imagefile, ".");
>>>                          if (index!=-1)
>>>                                                       imagefilenew = substring(imagefile, 0, index);
>>>                          imagefilenew = imagefilenew + ".xls";
>>>                          saveAs("Results", dir + "Results_" +
>>> imagefilenew);
>>>
>>>                          //Select the particle outlines window
>>>                          outlines = "Drawing of " + imagefile;
>>>                          selectWindow(outlines);
>>>                          //Save the outline drawing produced by the particle analysis
>>>                          saveAs("tiff", dir + outlines);
>>>
>>>                          //Copy the particle outlines window and add it to the original image file
>>>                          close(imagefile);
>>>                          open(dir + imagefile);
>>>                          selectWindow(imagefile);
>>>                          run("RGB Color"); //original image file is changed from 8-bit to RGB color
>>>                          imageCalculator('AND', imagefile, outlines);
>>>                          saveAs("tiff", dir + "Overlay_" +
>>> imagefile);
>>>
>>>                          print("\\Clear");
>>>                          run("Clear Results"); }
>>>
>>> //Select the Summary window
>>> selectWindow("Summary");
>>> //Save the Summary to a txt file
>>> saveAs("text", dir + "Summary");
>>>
>>> //Create a file with all the information about how the image has been
>>> manipulated criteriaPath = dir + "PSA_criteria.csv"; criteriaFile =
>>> File.open(criteriaPath); print(criteriaFile, "rolling, sigma,
>>> thresholdMethod, minArea, maxArea, minCirc, maxCirc, excludeEdge,
>>> watershed, distance, known"); //writes to the open file criteriaFile
>>> print(criteriaFile, rolling + ", " + sigma + ", " + thresholdMethod +
>>> ", " + minArea + ", " + maxArea + ", " + minCirc + ", " + maxCirc +
>>> ", " + excludeEdge + ", " + watershed + ", " + distance_pixels + ", "
>>> + known_um); //writes to the open file criteriaFile
>>> File.close(criteriaFile);
>>>
>>> //Close all open windows
>>> close("\\Others");
>>> close();
>>> list = getList("window.titles");
>>> for (j=0; j<list.length; j++){
>>>  windowname = list[j];
>>>  selectWindow(windowname);
>>>  run("Close");
>>> }
>>>
>>> Best regards,
>>> Mariam
>>>
>>> --
>>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>> <PC3940_Compo_02.tif>
>>
>> --
>> 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
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Analyze particles Exclude edge particles not working when automated

Rasband, Wayne (NIH/NIMH) [E]
In reply to this post by Mariam Shirdel
> On Feb 19, 2015, at 6:08 AM, Mariam Shirdel <[hidden email]> wrote:
>
> It worked! Thank you :)
>
> Is it possible to change the colour of Outlines in Analyze particles to red?

Use the show=[Overlay Outlines] option and you can easy change the outline color and line width. Here is an example:

  run("Blobs (25K)");
  setAutoThreshold("Default");
  run("Analyze Particles...", "  show=[Overlay Outlines] exclude");
  resetThreshold();
  run("Overlay Options...", "stroke=red width=2 apply");
  run("Flatten");

-wayne

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html