Cells touching image borders

We are trying to count cells and their number of neighbors in an epithelial monolayer. When we do so manually, we don’t count the cells touching the edge of the image (source_image.png) or partially cut off by the edge, but we do allow them to be counted as neighbors to cells that aren’t on the edge of the image. As far as I can see, CellProfiler can only include these cells on the edge completely, adding them to the total count of cells and using them as neighbors to other cells, or completely discard them. The problem with including them all the way is that the measurements for area, shape, and number of neighbors for these cells would be off. But, if we completely discard them, as we have been doing, we’ll get a lot of cells with fewer neighbors than actual. This can be seen in idobjects_with_color.png, where many of the cells on the border are recognized as having 2, 3, or 4 neighbors, when they in fact have 5, 6, or 7 neighbors.

Is there a way to make CellProfiler exclude the cells on the edge of image in the total count, but let them count as neighbors of other cells?


Is there any reason you couldn’t use IdentifyPrimAutomatic (or whatever you used to create the objects) twice in your pipeline, once excluding cells touching the border for your morphological measurements, and then again, including the border cells, for your neighbor measurement?

Also, it still seems that you have a similar problem even if you do include cells on the border in the neighborhood count, since (presumably) there are neighboring objects outside the field of view. Therefore, the border cells would still have a erroneously low object count due to their neighbors outside the image edges.

Indeed, it sounds like you could do an analysis like what Mark describes, but I’d also add the thought that you might need to add a Relate module (to “renumber” the edge-excluded objects to match the edge-included objects). Then perhaps some downstream data-filtering to exclude neighbor data for the edge-touching cells and only do calculations on the non-edge cells.

Anyway, these are all just clunky workarounds. We will add the request to the TODO list and post here if/when it is accomplished. What’s the timeline for your project - if this were to be done six months from now would you be able to use it?


Yes, Dr. Carpenter. I just came across this post and its what I’m looking to do and referenced in my “problem with neighbor counting when excluding borders” post. I’ll try your suggestions in this post, but including this in your next release would still be really helpful, now or 6 months from now!

Thanks again,

For those who are interested: CellProfiler 2.0 permits filtering out of boundary objects in IdentifySecondaryObjects as well as IdentifyPrimaryObjects. If desired, the associated primary objects can be removed along with the secondary objects without having to re-identify everything. You can download it from our website.