Color Blindness chart Reader

Mayank Kumar Gupta
4 min readMay 29, 2020

--

Deep learning techniques to read color blindness chart

Deeplearning is the buzzword among students, nowadays. When I was in college, I first heard this term from my senior and decided to give it a try by myself. I found many online tutorial for deeplearning. Most of them started with MNIST dataset. Handwriting analysis is like the “Hello World ” of deep learning. So, when I was starting my career in deep learning , I thought to do something different than just recognising the handwritten digits, so I thought of Color blindness chart reader.

Color blindness is a genetic disease where people can’t differentiate between colors. To test this, a color blindness chart is used. In a color blindness (CB)chart, there is a number with some color and a background with different color. A normal human eye can easily differentiate the colors and recognise the number but a color blind person can’t .

The goal of this project is to help those people test themselves in their home. This test can be an indication of presence or absence of color blindness, so that it may help the person to go for diagnosis accordingly.

So, it works something like this, the user is shown a CB chart, and he is supposed to guess the number, if the number matches the prediction of the model its probably not a color blindness. We could have used simple coded the if-else model (wherein if this is the picture then number is “xyz” and so on), but the beauty of this project is user can give any custom CB chart and our model will be able to predict most of the times the correct number!

First step is to preprocess the CB chart for our model to be able to do predictions. For preprocessing we use OpenCV-python.

Image preprocessing :

  1. Increase the Contrast of image and do median blur.
  2. Apply K-means clustering to segment image.
  3. Apply thresholding operation.
  4. Morphological opening, closing ,erosion.
  5. Median blurring.
  6. Save the image for model to act upon.

OpenCv Processing :

Install all required dependencies.

pip install opencv-python
pip install keras
pip install matplotlib
  1. Reading an image.

2. Increasing contrast of the image.

Increased contrast

3. K-means clustering. We use opencv built-in function.

After K-means

4. Thresholding.

5. Morpholgical operations and saving the image file.

This looks great. Number is pretty much visible.

Now, that we have preprocessed the image and saved it. Let’s move on to building our model to predict!

Model Building :

What is CNN ?

CNN is a type of neural network model which allows us to extract higher representations for the image c .ontent. Unlike the classical image recognition where you define the image features yourself, CNN takes the image’s raw pixel data, trains the model, then extracts the features automatically for better classification.

For more detailed explanation of CNN, do visit this awesome tutorial https://towardsdatascience.com/understanding-cnn-convolutional-neural-network-69fd626ee7d4

Without spending much time on learning the mathematics of CNN, lets move on to implementation of CNN and its application on our dataset.

Keras Model building :

  1. Dataset acquisition.
  2. Preprocessing dataset.
  3. Splitting dataset into train and test.
  4. Data Augmentation.
  5. Model training.
  6. Model testing and metrics .
  7. Model prediction on image.

For dataset, we are using MNIST dataset which has a training set of 60,000 examples, and a test set of 10,000 examples. It is a subset of a larger set available from NIST. The digits have been size-normalized and centered in a fixed-size image of size 28*28. Since its a very common dataset to use, dataset is already preprocessed for us. Even Kereas, includes it in its default package module. We can load MNIST data by keras function.

  1. Import required libraries.

2. Define parameters and split the dataset.

3. Define the model in keras and compile it.

4 . Fit the model to our dataset and save it for future use.

5. Load the saved model and do prediction on CB chart image.

Output

Future Work :

  • Develop a GUI for this model.
  • Improve the accuracy of model on our dataset.
  • Trying out different image segmentation methods on the same dataset.

I hope this tutorial has been informative on how a similar dataset can be used to make predictions on a different one. It was my first DL project, I hope it helps all those beginners who are new to Computer Vision and get familiar with OpenCv and Keras.

Please Comment out below for suggestions and feedback. Just like you, I am still learning how to become a better Data Scientist and Engineer. Please help me improve so that I could help you better in my subsequent article releases.

Thank you and Happy coding :)

--

--

Mayank Kumar Gupta
0 Followers

The goal isn’t to live forever, the goal is to create something that will.