AndroidImageProcessing/AndroidBacteriaImageProcessing — Issue #21: Find colonies
Author: pakdel
Created: 2011-12-04 16:20:25+00:00
State: open

Find and count bacteria colonies.

```python
def filtercolonies(img):
red=numpy.compress([False, False, True], img, 2)
red=192-red.clip(0,192)

# Remove green and blue
green=numpy.compress([False, True, False], img, 2)
blue=numpy.compress([True, False, False], img, 2)
greenblue=numpy.minimum(192-green.clip(0,192), 192-blue.clip(0,192))+64
col=(greenblue-red).clip(64,255)-64
col=255-((col*3).clip(0,255))
return col

def findcolonies(col):
thrs=cv2.adaptiveThreshold(col, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 5, 30)
cv2.findContours(thrs, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
cv2.imshow('img', thrs)
cv2.waitKey()

```

https://github.com/AndroidImageProcessing/AndroidBacteriaImageProcessing/blob/master/data/stage5colonies.png