Only count cells that contain nuclei (or holes in the binarized image)

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

Only count cells that contain nuclei (or holes in the binarized image)

Christopher Coulon-2
This macro utilizes the analyzeParticles routine with and without the “include holes” option.

// intended for the binary image

setAutoThreshold("Default");

run("Set Measurements...", "area redirect=None decimal=5");
run("Analyze Particles...", "size=100-Infinity display exclude clear");

noHoles = newArray(nResults);
holes = newArray(nResults);

for (i = 0; i < nResults; i++) noHoles[i] = getResult("Area", i);

run("Analyze Particles...", "size=100-Infinity display exclude clear include");

print("Particles Containg Holes");

for (i = 0; i < nResults; i++) {
        n = i+1;
        holes[i] = getResult("Area", i);
        a = holes[i] - noHoles[i];
        if(a > 0) print(n + " area of hole = " + a);
}


> On Oct 15, 2015, at 8:38 AM, kirbyfloss <[hidden email] <mailto:[hidden email]>> wrote:
>
> Hi - is there a way to only count the cells in the attached binarized image
> that contain "holes"?
> <http://imagej.1557.x6.nabble.com/file/n5014650/workingCopy.png <http://imagej.1557.x6.nabble.com/file/n5014650/workingCopy.png>>
>
> I am trying to analyze slides with muscle stained with H&E - and would like
> to count the number of regenerating muscle fibers, which are distinguished
> by dark nuclei in the interior of the cell bodies (rather than on the
> periphery).
>
> This is the pipeline I have set up thus far:
> 1) Apply colour deconvolution (using plugin by G. Landini)
> 2) Set threshold to binarize the resulting image in channel 2
> 3) Analyze particles
>
> This works reasonably well to count all the cells in an image, but is there
> any way to only count the cells that contain a hole (or multiple holes)
> automatically? I'm aware of more manual tools, like Cell Counter, but was
> hoping for the most automated solution possible.
>
> Thanks!
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Only-count-cells-that-contain-nuclei-or-holes-in-the-binarized-image-tp5014650.html <http://imagej.1557.x6.nabble.com/Only-count-cells-that-contain-nuclei-or-holes-in-the-binarized-image-tp5014650.html>
> Sent from the ImageJ mailing list archive at Nabble.com <http://nabble.com/>.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html <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: Only count cells that contain nuclei (or holes in the binarized image)

kirbyfloss
Thanks so much! I tested the code and it runs perfectly - the solution of using include/exclude to distinguish the two populations is great.

Just one more thing, is it possible to show outlines for just the particles that contained holes? So I know which particles were counted.

This is the macro I have set up so far with the helpful suggestions of the community:
// run on the original image
run("Duplicate...", "title=workingCopy.png");
selectWindow("workingCopy.png");
run("Colour Deconvolution", "vectors=[H&E 2]");
selectWindow("workingCopy.png-(Colour_2)");
setAutoThreshold("Minimum");
run("Convert to Mask");
run("Set Measurements...", "area redirect=None decimal=5");
run("Analyze Particles...", "size=100-Infinity display exclude clear");
noHoles = newArray(nResults);
holes = newArray(nResults);
for (i = 0; i < nResults; i++) noHoles[i] = getResult("Area", i);
run("Analyze Particles...", "size=100-Infinity display exclude clear include");
print("Particles Containing Holes");
for (i = 0; i < nResults; i++) {
        n = i+1;
        holes[i] = getResult("Area", i);
        a = holes[i] - noHoles[i];
        if(a > 0) print(n + " area of hole = " + a);
}
Reply | Threaded
Open this post in threaded view
|

Re: Only count cells that contain nuclei (or holes in the binarized image)

G. Esteban Fernandez
You can try the "Add to Manager" option in Analyze Particles, then go
through the list of ROIs and draw only those with holes onto a new
blank image.

-Esteban

On Thu, Oct 15, 2015 at 12:11 PM, kirbyfloss <[hidden email]> wrote:

> Thanks so much! I tested the code and it runs perfectly - the solution of
> using include/exclude to distinguish the two populations is great.
>
> Just one more thing, is it possible to show outlines for just the particles
> that contained holes? So I know which particles were counted.
>
> This is the macro I have set up so far with the helpful suggestions of the
> community:
> // run on the original image
> run("Duplicate...", "title=workingCopy.png");
> selectWindow("workingCopy.png");
> run("Colour Deconvolution", "vectors=[H&E 2]");
> selectWindow("workingCopy.png-(Colour_2)");
> setAutoThreshold("Minimum");
> run("Convert to Mask");
> run("Set Measurements...", "area redirect=None decimal=5");
> run("Analyze Particles...", "size=100-Infinity display exclude clear");
> noHoles = newArray(nResults);
> holes = newArray(nResults);
> for (i = 0; i < nResults; i++) noHoles[i] = getResult("Area", i);
> run("Analyze Particles...", "size=100-Infinity display exclude clear
> include");
> print("Particles Containing Holes");
> for (i = 0; i < nResults; i++) {
>         n = i+1;
>         holes[i] = getResult("Area", i);
>         a = holes[i] - noHoles[i];
>         if(a > 0) print(n + " area of hole = " + a);
> }
>
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Only-count-cells-that-contain-nuclei-or-holes-in-the-binarized-image-tp5014654p5014655.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> 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: Only count cells that contain nuclei (or holes in the binarized image)

G. Esteban Fernandez
newImage("Outlines with holes", "8-bit black", x, y, 1);

for(i = 0; i < roiManager("count"); i++){
a = holes[i] - noHoles[i];
        if(a > 0){
              roiManager("Select", i);
              roiManager("Draw");
        }
}

On Thu, Oct 15, 2015 at 1:53 PM, G. Esteban Fernandez
<[hidden email]> wrote:

> You can try the "Add to Manager" option in Analyze Particles, then go
> through the list of ROIs and draw only those with holes onto a new
> blank image.
>
> -Esteban
>
> On Thu, Oct 15, 2015 at 12:11 PM, kirbyfloss <[hidden email]> wrote:
>> Thanks so much! I tested the code and it runs perfectly - the solution of
>> using include/exclude to distinguish the two populations is great.
>>
>> Just one more thing, is it possible to show outlines for just the particles
>> that contained holes? So I know which particles were counted.
>>
>> This is the macro I have set up so far with the helpful suggestions of the
>> community:
>> // run on the original image
>> run("Duplicate...", "title=workingCopy.png");
>> selectWindow("workingCopy.png");
>> run("Colour Deconvolution", "vectors=[H&E 2]");
>> selectWindow("workingCopy.png-(Colour_2)");
>> setAutoThreshold("Minimum");
>> run("Convert to Mask");
>> run("Set Measurements...", "area redirect=None decimal=5");
>> run("Analyze Particles...", "size=100-Infinity display exclude clear");
>> noHoles = newArray(nResults);
>> holes = newArray(nResults);
>> for (i = 0; i < nResults; i++) noHoles[i] = getResult("Area", i);
>> run("Analyze Particles...", "size=100-Infinity display exclude clear
>> include");
>> print("Particles Containing Holes");
>> for (i = 0; i < nResults; i++) {
>>         n = i+1;
>>         holes[i] = getResult("Area", i);
>>         a = holes[i] - noHoles[i];
>>         if(a > 0) print(n + " area of hole = " + a);
>> }
>>
>>
>>
>>
>> --
>> View this message in context: http://imagej.1557.x6.nabble.com/Only-count-cells-that-contain-nuclei-or-holes-in-the-binarized-image-tp5014654p5014655.html
>> Sent from the ImageJ mailing list archive at Nabble.com.
>>
>> --
>> 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: Only count cells that contain nuclei (or holes in the binarized image)

Gabriel Landini
In reply to this post by kirbyfloss
There is a further way of computing those relations using region connection
calculus:
http://www.mecourse.com/landinig/software/spatial/rcc8d.html

See the references listed in that page for specific examples. You perhaps are
interested in the relations of RCC8D logic that describe TPP(nucleus, cell)
(for nuclei that touch the cell boundary), and NTPP(nucleus, cell) (for nuclei
that are inside the cells but not touching the boundary), or the relation
PP(nucleus, cell) in the RCC5D logic (both are supported by the plugins).

However, I think the image you posted will probably not return accurate
results (with any method) due to many cells appearing to be merged into
clusters and also there are many small areas which are not cells and many
small nuceli which are not strictly so.

Before doing further processing you will benefit from cleaning the images of
those small regions and holes and separate the touching cells. You might want
to try opening and closing, or median filtering.
 
You could use a region labelling plugin to see what are the connected regions
and check if they are one or multiple cells, See the attached image, clusters
with the same colour will count as "one cell" but are in fact many.

The watershed separation might be useful to separate those clustered cells,
but you will have to fill the holes first.
Hope it helps.

Gabriel


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

Labelled.png (23K) Download Attachment