Saturday, December 31, 2016

Measuring the dimension of an object using OpenCV and Python: BACKGROUND

"Cheer up everyone! We can make it!" said one of my colleagues in the lab. This happened back when I was in South Korea in 2015. I was a researcher in one of the biggest medical institutes in South Korea. At that time we were trying to map the so-called mechanoreceptor in human elbow ligament and human finger tips.
Step-by-step modified gold chloride staining to stain or paint the tissues, so that we could identify the mechanoreceptor in each tissue under the microscope. 
I am not going to discuss about what the mechanoreceptor is nor which ligament that I am talking about, but I am going to tell you one of the applications of Python-OpenCV in determining the dimension (length and width) of an object. At that time, we needed to measure the dimension of each mechanoreceptor tissue in each slide. It was a tremendous, laborious, boring, and super-crazy work. Here is the example of the object that we need to measure the dimension.
Example of tissues on the slide that we need to measure the dimensions
Those are just from a few slides. We had more than 20 boxes of slides! Each box contained 100 slides! Please do the math.
HOLY! 20k tissues! NO JOKE!
I bet you are going to say, "Holy crap! Research is no fun!" Yes, you are right! It was no fun if we measured each tissue one by one by use of digital caliper.


Even when you are doing sampling, we still need to measure the dimension of 2 thousand tissues!
Indeed we could save a lot of times by doing sampling instead of measuring all the mechanoreceptors. However. it still required huge amount of times, approximately 2 months for completely measuring all the 2 thousand tissues.
The big picture of using Python in automating the work.
Not until Python came into play. The work suddenly became fun, so fun, easy and breezy. How come? Please look at the short video below.



WOW! How to do that? How to measure an object's dimension using Python? To be honest, it is almost impossible if we are just solely using Python, we need another libraries called OpenCV and SciPy to do this. Nevertheless, using the super combo Python-OpenCV-SciPy we could automate as well as significantly reduce the required time to complete the work.

I will share the code in the next post. The code is free to download and reuse as long as it meets your needs. Further, I will also dive in to line-by-line of the program in my next post. Should you have any query, comment, or anything, please leave them below in the comment section. Thanks for reading and see you guys! Happy new year!

No comments:

Post a Comment