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:
- Threshold the image using an empirically determined threshold (or Ohtsu's method)
- 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"
- Determine outlines using
cv.FindContours
- Optionally, paint the contours
- 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)
- Optionally, paint in the nuclei
- 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).