Cell segmentation and fluorescence counting in Python [closed]
Asked Answered
M

4

16

How can I segment cells from an image taken on a microscope, along the lines of what was done here in Matlab?

http://blogs.mathworks.com/steve/2006/06/02/cell-segmentation/

Also, if I take multiple image in different fluorescent channels (after staining the cells with some antibody/maker), how can I automatically quantitate the fraction of cells positive for each marker? Has anyone done something like this in Python? Or is there a library in Python that can be used to do this?

Mime answered 6/4, 2011 at 1:24 Comment(6)
Not sure how take this off hold, but tried editing to address the (rather nitpicking and incorrect) "off-topic" flagging.Osorio
@bluefeet - why was this closed? It's a specific questions, with two specific answers below. I edited out the part asking for a recommendation.Osorio
@thouis Why was this closed? Because it's far too broad of a question and it's also asking for a library. Your edit to remove the last line basically invalidates each answer on this question which just point to a link. Closing a question doesn't mean it will be deleted, but this question as written is off-topic.Outmaneuver
@bluefeet I disagree, strongly. They asked a very specific question ("How can I segment cells..."), and followed on with some other information. The top answer has a tutorial that does exactly that. The bit asking about a library is at the very end, as an aside. If you don't like that part, just edit it out.Osorio
@thouis The post went into the reopen review queue after your edit on June 8th, and they voted that this question should remain closed. At this time, I'm not going to reopen it - it's too broad and it asks for a library. If you want to continue this discussion, then feel free to ask on meta.Outmaneuver
@bluefeet Yet another case of SO modding itself out of usefulness. I give up on this site.Osorio
P
5

Have you read the tutorial on pythonvision.org?

http://pythonvision.org/basic-tutorial

It is very similar to what you are looking for.

Philis answered 6/4, 2011 at 17:45 Comment(0)
S
7

You can do this in Python using the OpenCV library.

In particular, you'll be interested in the following features:

  • histogram stretching (cv.EqualizeHist). This is missing from the current Python API, but if you download the latest SVN release of OpenCV, you can use it. This part is for display purposes only, not required to get the same result
  • image thresholding
  • morphological operations such as erode (also dilate, open, close, etc)
  • determine the outline of a blob in a binary image using cv.FindContours -- see this question. It's using C, not Python, but the APIs are virtually the same so you can learn a lot from there
  • watershed segmentation (use cv.Watershed -- it exists, but for some reason I can't find it in the manual)

With that in mind, here's how I would use OpenCV to get the same results as in the matlab article:

  1. Threshold the image using an empirically determined threshold (or Ohtsu's method)
  2. Apply dilation to the image to fill in the gaps. Optionally, blur the image prior to the previous thresholding step -- that will also remove small "holes"
  3. Determine outlines using cv.FindContours
  4. Optionally, paint the contours
  5. Using the blob information, iterate over each blob in the original image and apply a separate threshold for each blob to separate the cell nuclei (this is what their imextendedmax operation is doing)
  6. Optionally, paint in the nuclei
  7. Apply the watershed transform

I haven't tried any of this (sorry, don't have the time now), so I can't show you any code yet. However, based on my experience with OpenCV, I'm confident that everything up to step 7 will work well. I've never used OpenCV's watershed transform before but I can't see a reason for it not to work here.

Try going through the steps I have shown and let us know if you have any problems. Be sure to post your source as that way more people will be able to help you.

Finally, to answer your question about staining cells and quantifying their presence, it's quite easy knowing the dyes that you are using. For example, to determine the cells stained with red dye, you'd extract the red channel from the image and examine areas of high intensity (perhaps by thresholding).

Stockton answered 6/4, 2011 at 2:48 Comment(0)
P
5

Have you read the tutorial on pythonvision.org?

http://pythonvision.org/basic-tutorial

It is very similar to what you are looking for.

Philis answered 6/4, 2011 at 17:45 Comment(0)
O
2

And just to add one more: cellprofiler.org (open source cell image analysis software, in python)

Osorio answered 10/4, 2011 at 21:25 Comment(0)
D
1

You may also find this library useful:

https://github.com/luispedro/pymorph/

I found it easier to get moving with than the OpenCV library.

Domini answered 6/4, 2011 at 14:19 Comment(2)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.Settlings
@AndrewSvetlov thanks buddy.. where were you 4 years ago to tell us this.Domini

© 2022 - 2024 — McMap. All rights reserved.