Hi all,
I am writing a macro to count cells in images I've taken of slides. Does anyone know what code I could use to have the macro threshold each image at the top 2% of each histogram, rather than at a set number value on each histogram? Thanks in advance, Natalie Morel University of Wisconsin -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear Natalie,
I guess you are looking for a code like this: nBins = 256; ratio = 0.5; run("Blobs (25K)"); getHistogram(values, counts, nBins); Array.getStatistics(values, valuesMin, valuesMax, valuesMean, valuesStdDev); setThreshold(0, ratio * valuesMax ); setOption("BlackBackground", true); run("Convert to Mask"); with in your case ratio = 0.98; My best regards. Philippe Philippe CARL Laboratoire de Biophotonique et Pharmacologie UMR 7213 CNRS - Université de Strasbourg Faculté de Pharmacie 74 route du Rhin 67401 ILLKIRCH Tel : +33(0)3 68 85 41 84 -----Message d'origine----- De : ImageJ Interest Group [mailto:[hidden email]] De la part de Natalie M Envoyé : lundi 29 février 2016 18:43 À : [hidden email] Objet : macro threshold values Hi all, I am writing a macro to count cells in images I've taken of slides. Does anyone know what code I could use to have the macro threshold each image at the top 2% of each histogram, rather than at a set number value on each histogram? Thanks in advance, Natalie Morel University of Wisconsin -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Natalie M
Hi Natalie,
Do you want to select 2% of the total number pixels (those that are the most intense) or a population comprising of the most intense pixels that make up 2% of the total intensity above background, or something else ? This may not be a good approach for counting cells if the number of cells is variable. -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Natalie M Sent: den 29 februari 2016 18:43 To: [hidden email] Subject: macro threshold values Hi all, I am writing a macro to count cells in images I've taken of slides. Does anyone know what code I could use to have the macro threshold each image at the top 2% of each histogram, rather than at a set number value on each histogram? Thanks in advance, Natalie Morel University of Wisconsin -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by CARL Philippe (LBP)
Hi Natalie,
If you want to get the top 2% of the pixel population, there is a possibly related thread on the forum, where the poster is trying to get the top 2% of the pixel population using a cumulative sum. http://forum.imagej.net/t/thresholding-as-a-percentage-of-intensity-histogram-in-a-macro/923/ However, I agree with Jeremy that differing amounts of positive staining per image will change the shape of the histogram, so the population approach may not be robust. Philippe’s solution gives you a threshold = 98% of the maximum value in the image, which would seem to be robust to differing amounts of positive signal per image, as well as to inconsistent staining levels. Hope this helps, Theresa On Mar 2, 2016, at 3:19 AM, Philippe CARL <[hidden email]<mailto:[hidden email]>> wrote: Dear Natalie, I guess you are looking for a code like this: nBins = 256; ratio = 0.5; run("Blobs (25K)"); getHistogram(values, counts, nBins); Array.getStatistics(values, valuesMin, valuesMax, valuesMean, valuesStdDev); setThreshold(0, ratio * valuesMax ); setOption("BlackBackground", true); run("Convert to Mask"); with in your case ratio = 0.98; My best regards. Philippe Philippe CARL Laboratoire de Biophotonique et Pharmacologie UMR 7213 CNRS - Université de Strasbourg Faculté de Pharmacie 74 route du Rhin 67401 ILLKIRCH Tel : +33(0)3 68 85 41 84 -----Message d'origine----- De : ImageJ Interest Group [mailto:[hidden email]] De la part de Natalie M Envoyé : lundi 29 février 2016 18:43 À : [hidden email]<mailto:[hidden email]> Objet : macro threshold values Hi all, I am writing a macro to count cells in images I've taken of slides. Does anyone know what code I could use to have the macro threshold each image at the top 2% of each histogram, rather than at a set number value on each histogram? Thanks in advance, Natalie Morel University of Wisconsin -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html ------------------------------------ Theresa Swayne, Ph.D. Manager Confocal and Specialized Microscopy Shared Resource<http://hiccc.columbia.edu/research/sharedresources/confocal> Herbert Irving Comprehensive Cancer Center Columbia University Medical Center 1130 St. Nicholas Ave., Room 222A New York, NY 10032 Phone: 212-851-4613 [hidden email]<mailto:[hidden email]> -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
From a statistics point of view, measures based on ranges (i.e., maximum values) are often not recommended because sample ranges depend on sample sizes. You might be able to parameterize your distribution via its moments, and then take the predicted 98% upper confidence interval as a threshold.
- Jim > On Mar 2, 2016, at 10:28 AM, Swayne, Theresa C. <[hidden email]> wrote: > > Hi Natalie, > > > If you want to get the top 2% of the pixel population, there is a possibly related thread on the forum, where the poster is trying to get the top 2% of the pixel population using a cumulative sum. > http://forum.imagej.net/t/thresholding-as-a-percentage-of-intensity-histogram-in-a-macro/923/ > > However, I agree with Jeremy that differing amounts of positive staining per image will change the shape of the histogram, so the population approach may not be robust. > > Philippe’s solution gives you a threshold = 98% of the maximum value in the image, which would seem to be robust to differing amounts of positive signal per image, as well as to inconsistent staining levels. > > Hope this helps, > Theresa > > On Mar 2, 2016, at 3:19 AM, Philippe CARL <[hidden email]<mailto:[hidden email]>> wrote: > > Dear Natalie, > I guess you are looking for a code like this: > nBins = 256; > ratio = 0.5; > run("Blobs (25K)"); > getHistogram(values, counts, nBins); > Array.getStatistics(values, valuesMin, valuesMax, valuesMean, valuesStdDev); > setThreshold(0, ratio * valuesMax ); > setOption("BlackBackground", true); > run("Convert to Mask"); > with in your case ratio = 0.98; > My best regards. > Philippe > > Philippe CARL > Laboratoire de Biophotonique et Pharmacologie > UMR 7213 CNRS - Université de Strasbourg > Faculté de Pharmacie > 74 route du Rhin > 67401 ILLKIRCH > Tel : +33(0)3 68 85 41 84 > > -----Message d'origine----- > De : ImageJ Interest Group [mailto:[hidden email]] De la part de Natalie M > Envoyé : lundi 29 février 2016 18:43 > À : [hidden email]<mailto:[hidden email]> > Objet : macro threshold values > > Hi all, > I am writing a macro to count cells in images I've taken of slides. Does anyone know what code I could use to have the macro threshold each image at the top 2% of each histogram, rather than at a set number value on each histogram? > Thanks in advance, > Natalie Morel > University of Wisconsin > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > ------------------------------------ > Theresa Swayne, Ph.D. > Manager > Confocal and Specialized Microscopy Shared Resource<http://hiccc.columbia.edu/research/sharedresources/confocal> > > Herbert Irving Comprehensive Cancer Center > Columbia University Medical Center > 1130 St. Nicholas Ave., Room 222A > New York, NY 10032 > Phone: 212-851-4613 > [hidden email]<mailto:[hidden email]> > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thank you all for your feedback! The reason I am thresholding the values to
count the cells is because the cells I want to count have been stained with fluorescent dye, and I want to count only cells with the brightest fluorescence (i.e., only the cells which are positive for the actin I am measuring). Instead of counting them by hand, I thought setting a global threshold would eliminate any bias on my part and allow me to choose which cells are the most brightly stained in each image. Does this still seem like an accurate way of achieving the cell count, or would something different be recommended? -Natalie On Wed, Mar 2, 2016 at 9:53 AM, Ewing James <[hidden email]> wrote: > From a statistics point of view, measures based on ranges (i.e., maximum > values) are often not recommended because sample ranges depend on sample > sizes. You might be able to parameterize your distribution via its > moments, and then take the predicted 98% upper confidence interval as a > threshold. > > - Jim > > > > On Mar 2, 2016, at 10:28 AM, Swayne, Theresa C. <[hidden email]> > wrote: > > > > Hi Natalie, > > > > > > If you want to get the top 2% of the pixel population, there is a > possibly related thread on the forum, where the poster is trying to get the > top 2% of the pixel population using a cumulative sum. > > > http://forum.imagej.net/t/thresholding-as-a-percentage-of-intensity-histogram-in-a-macro/923/ > > > > However, I agree with Jeremy that differing amounts of positive staining > per image will change the shape of the histogram, so the population > approach may not be robust. > > > > Philippe’s solution gives you a threshold = 98% of the maximum value in > the image, which would seem to be robust to differing amounts of positive > signal per image, as well as to inconsistent staining levels. > > > > Hope this helps, > > Theresa > > > > On Mar 2, 2016, at 3:19 AM, Philippe CARL <[hidden email] > <mailto:[hidden email]>> wrote: > > > > Dear Natalie, > > I guess you are looking for a code like this: > > nBins = 256; > > ratio = 0.5; > > run("Blobs (25K)"); > > getHistogram(values, counts, nBins); > > Array.getStatistics(values, valuesMin, valuesMax, valuesMean, > valuesStdDev); > > setThreshold(0, ratio * valuesMax ); > > setOption("BlackBackground", true); > > run("Convert to Mask"); > > with in your case ratio = 0.98; > > My best regards. > > Philippe > > > > Philippe CARL > > Laboratoire de Biophotonique et Pharmacologie > > UMR 7213 CNRS - Université de Strasbourg > > Faculté de Pharmacie > > 74 route du Rhin > > 67401 ILLKIRCH > > Tel : +33(0)3 68 85 41 84 > > > > -----Message d'origine----- > > De : ImageJ Interest Group [mailto:[hidden email]] De la part de > Natalie M > > Envoyé : lundi 29 février 2016 18:43 > > À : [hidden email]<mailto:[hidden email]> > > Objet : macro threshold values > > > > Hi all, > > I am writing a macro to count cells in images I've taken of slides. Does > anyone know what code I could use to have the macro threshold each image at > the top 2% of each histogram, rather than at a set number value on each > histogram? > > Thanks in advance, > > Natalie Morel > > University of Wisconsin > > > > -- > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > > -- > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > > ------------------------------------ > > Theresa Swayne, Ph.D. > > Manager > > Confocal and Specialized Microscopy Shared Resource< > http://hiccc.columbia.edu/research/sharedresources/confocal> > > > > Herbert Irving Comprehensive Cancer Center > > Columbia University Medical Center > > 1130 St. Nicholas Ave., Room 222A > > New York, NY 10032 > > Phone: 212-851-4613 > > [hidden email]<mailto:[hidden email]> > > > > > > -- > > 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 |
Hi Natalie, It’s absolutely right to try to set a threshold in an unbiased way. It’s faster (in the long run) and more reproducible. The only difference folks are having is in how to find the most accurate method to select the threshold for this experiment. You could use the same number for every image, or you could use a histogram-based method as you proposed, or you could use one of the automatic thresholding or trainable segmentation methods available in ImageJ. The best approach will depend on your particular data — e.g. difference between signal and background, variability of the positive staining level, and variability in positive cell numbers, from one image to the next. In the end, you will need to test your method empirically on several representative images from different groups. --Theresa On Mar 2, 2016, at 2:15 PM, Natalie M <[hidden email]<mailto:[hidden email]>> wrote: Thank you all for your feedback! The reason I am thresholding the values to count the cells is because the cells I want to count have been stained with fluorescent dye, and I want to count only cells with the brightest fluorescence (i.e., only the cells which are positive for the actin I am measuring). Instead of counting them by hand, I thought setting a global threshold would eliminate any bias on my part and allow me to choose which cells are the most brightly stained in each image. Does this still seem like an accurate way of achieving the cell count, or would something different be recommended? -Natalie On Wed, Mar 2, 2016 at 9:53 AM, Ewing James <[hidden email]<mailto:[hidden email]>> wrote: ------------------------------------ Theresa Swayne, Ph.D. Manager Confocal and Specialized Microscopy Shared Resource<http://hiccc.columbia.edu/research/sharedresources/confocal> Herbert Irving Comprehensive Cancer Center Columbia University Medical Center 1130 St. Nicholas Ave., Room 222A New York, NY 10032 Phone: 212-851-4613 [hidden email]<mailto:[hidden email]> -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |