About me

Image preprocessing

⏳ 1 mins read time

Revealjs presentation available in GitPitch

Image preprocessing

  • Many traditional computer vision image classification algorithms follow this pipeline
  • Deep Learning based algorithms bypass the feature extraction step completely



Align an image to a reference assits the classification algorithm 1, 2.

Deskewing simple grayscale images can be achieved using image moments (distance and intensity of pixels).

def deskew(img):
    m = cv2.moments(img)
    if abs(m['mu02']) < 1e-2:
        # no deskewing needed. 
        return img.copy()
    # Calculate skew based on central momemts. 
    skew = m['mu11']/m['mu02']
    # Calculate affine transform to correct skewness. 
    M = np.float32([[1, skew, -0.5*SZ*skew], [0, 1, 0]])
    # Apply affine transform
    img = cv2.warpAffine(img, M, (SZ, SZ), flags=cv2.WARP_INVERSE_MAP | cv2.INTER_LINEAR)
    return img

This deskewing of simple grayscale images can be achieved using image moments. OpenCV has an implementation of moments and it comes in handy while calculating useful information like centroid, area, skewness of simple images with black backgrounds.

It turns out that a measure of the skewness is the given by the ratio of the two central moments ( mu11 / mu02 ). The skewness thus calculated can be used in calculating an affine transform that deskews the image.

Histogram equalization

Increase image contrast using the image’s histogram.


  • Image preprocessing can significantly increase the performance of a classification algorithm.
  • A feature descriptor represents a simplified version of an image by extracting useful information and throwing away extraneous information.
  • Using feature description increases training speed compared with raw images.

In relation with 🏷️ opencv, python:

Intelligent Video Analytics using SSD mobilenet on NVIDIA's Jetson Nano

This project implements a deep learning model on a Jetson Nano to count and track people passing in front of a video camera.

Real time motion detection in Raspberry Pi

In this article I show how to use a Raspberry Pi with motion detection algorithms and schedule task to detect objects using SSD Mobilenet and Yolo models.

Object detection using a Raspberry Pi with Yolo and SSD Mobilenet

This post how how to implement a light object detection algorithm

Document detection

This post shows how to implemented a simple algorithm to detect a document inside and scanned image using python and the image processing library opencv

📅 Dec 3, 2017   opencv   python
Subscribe to my newsletter 📰

and share it with your friends: