Skip to main content

Count and Label DNA strands

Sample DNA Image
Sample DNA Image
This is a proof of concept (POC) developed using Python3, NumPy, and OpenCV, to count and label the number of DNA strands from an image of combed DNA molecules.

The technique of Adaptive Mean Thresholding is used here.

There are several Thresholding algorithms available.
Global Thresholding will not apply here as the image has different lighting conditions in different areas.

Adaptive Mean Thresholding calculates a threshold value for small regions of the image. This gives us different threshold values for different areas of the image, which give better results.

There are two approaches for this:
  1. Mean Thresholding - threshold value is the mean of the surrounding area
  2. Gaussian Thresholding - threshold value is the weighted sum of values of surrounding areas
An example can be seen on OpenCV website. The example image clearly shows the difference:
Thresholding sample from OpenCV site
Source: OpenCV website
In this case, Adaptive Mean Thresholding was giving better results than Adaptive Gaussian Thresholding.
The intermediate image produced after thresholding looked like:
Image after thresholding
Image after thresholding
We ignored the smaller contours and focused on the larger ones. Redrawing contours on another image and labeling them resulted in the following image:
Image with Labels
Image after adding labels
The source code, sample images, and Jupyter Notebook is available in the GitHub Repository.
Happy Coding!
- Vivek


Popular posts from this blog

Build Windows 8

Most of us are aware that Microsoft is promoting Windows 8 heavily. Windows 8 adoption is very important for the Redmond based company. Microsoft knows that developers play a very important role in this process. iOS developers have already proved this fact by writing Apple's success story.

Windows 8 - Network Configuration

Microsoft might have given a huge face-lift to its Windows Operating System but the truth is that somewhere somehow it is the same old core with new visual user interface. Many of us who have been running Windows 8 Pro for sometime may tell this easily.

Assembla hit by a virus?

Today hosted task management site Assembla was hit by some virus. Around 3 hours back we got Service Unavailable - DNS failure error when trying to access the portal.
Trying to call any API from Assembla returns with the following unwanted HTML code prepended to the response:
<html><head><meta http-equiv="refresh" content="0; URL="></head><body><a href="">Please click here</a></body></html>
We have logged a ticket with them. The response was quick but when we tried to post a reply comment we consistently got error - Your CAPTCHA words didn't match We'll keep on chasing them for updates and hope safety for Assembla users.

- Vivek