Digital business

Let's Use CNNs to Classify Malaria-Infected Cells

Written by Pattanan Numpong | May 16, 2025 6:04:06 AM

As many of you might already know, malaria is a serious disease transmitted by the Anopheles mosquito. It is especially common in tropical regions and among people living near forests and hills. Alarmingly, malaria remains one of the leading causes of death in many parts of the world.

Alright! Let’s not waste any more time and dive right in.

According to the dataset we’ll be working with, there are a total of 27,558 cell images, neatly divided into two classes:

  • Infected – cells that show signs of malaria

  • Uninfected – healthy, non-infected cells

    Wait, What is CNN Again?

    Before we jump into the modeling part, it’s important to understand what a CNN (Convolutional Neural Network) actually is.

    CNN is a specialized type of neural network designed primarily for image data. Inspired by the way humans process visual information, CNNs are excellent at learning spatial hierarchies of features — meaning they start by learning simple shapes like edges and gradually combine them to understand more complex structures like textures or objects.

    If you’re new to Neural Networks, I highly recommend reading our earlier post by P’Wynn explaining the basics in a very beginner-friendly way.
    [Click here to read that post!]


    Components of a CNN

     

    A CNN typically consists of three main components:

    1. Convolutional Layers – These use filters to detect patterns such as lines, corners, or textures in the image.

    2. Pooling Layers – These reduce the size of the feature maps, helping the network generalize better and run faster.

    3. Fully Connected Layers – These interpret the extracted features and make predictions, like classifying if a cell is infected or not.

    Usually, convolutional and pooling layers are stacked alternately, gradually transforming the raw image into meaningful insights.

    Visualizing the Process

     

    Imagine this: a convolution layer uses something called a filter (or kernel) to slide across an input image. This filter multiplies its values with the underlying pixel values to generate a new image (called a feature map). This resulting map highlights the brighter and darker regions — typically with values between 0 and 1, where 1 indicates the brightest area.

    The filters act like little magnifying glasses that focus on specific visual patterns. By stacking several of these layers, CNNs learn what an infected cell "looks like" by themselves!

🧹 Step 1: Preprocess the Malaria Cell Images

Before we train a CNN, we need to prepare the data properly. The dataset typically comes in two folders: Parasitized/ and Uninfected/. Each folder contains .png images of individual blood cells.

Here's how we can prepare the data:

🔧 Image Preprocessing Steps

🧪 Shuffle and Split the Dataset

✨ Conclusion

By applying CNNs to malaria cell images, we’ve:

  • Preprocessed the image dataset

  • Built and trained a CNN for binary classification

  • Evaluated model performance

  • Visualized model focus using Grad-CAM

This is a great first step into medical AI and computer vision. With further tuning and more advanced architectures like ResNet or EfficientNet, you can push the accuracy even further!