Salient Features of Blurred Images

Wisnu Adi Pradana
HARA Engineering
Published in
8 min readOct 3, 2018

Introduction

As HARA sought to collect data from farmers, there is a need to verify each farmer identity by collecting images of their ID card (also known as Kartu Tanda Penduduk or KTP). Then it is necessary to make sure that the KTP images are readable, i.e. the images aren’t blurred. Typically the KTP images are taken with mobile phone camera which is digital. We will first briefly described the fundamental principle of digital image processing, followed by the analysis of blurred images and how to apply it to our problem.

Note that what is projected on the image plane (a plane behind optical lenses where image formed) of a camera is essentially a continuous distribution of light energy. This continuously changing light distribution is processed by computer to obtain a digital snapshot. Light distribution is spatially sampled in in the time domain and the resulting values is then quantized to a finite set of numeric values (for example 256=2⁸) so that they are representable within the computer. The result of such processes is a description of the image in the form of a two-dimensional, ordered matrix of integers (Fig. 1).

Formally, a digital image I is a two-dimensional function of integer coordinates that maps to a range of possible image (pixel) values. The size of an image is determined directly from the width M (number of columns) and the height N (number of rows) of the image matrix I.

Figure 1. Transformation of a continuous intensity function F(x,y) to discrete digital image I(u,v). Image source: W. Burger and M.J. Burge, Principles of Digital Image Processing : Fundamental Techniques, Springer-Verlag.

Color images are based on three primary colors : red, green and blue (RGB). It is typical that each primary color component make use of 8 bit representation. In color images, each pixel requires 24 bits (8 bits for each color) to encode all three components and the range of each individual color component is [0 …255].

An (digital) image is of good quality if

  1. it is not blurred;
  2. it has high resolution;
  3. it has good contrast.

This article will focus particularly on blurred images. Image blurring is caused by incorrect image capturing conditions. For example, out of focus camera, or relative motion of the camera and the imaged object. The rest part of this article will focus on how to build key feature of blurred images and classify whether a given image is blurred or not based on such feature.

Blurred Detection via Edge Detection

Convolution of Digital Image with Linear Filter

In order to detect blurred images, it is important to precisely understand the process of transforming digital images. Note that a good quality image (non-blurred) can be turned into blurred image by a simple mathematical operation. Images look sharp if the local intensity rises or drops sharply, i.e. where the difference between neighboring pixel is large. We perceive an image as blurred where the local intensity function is smooth.

Thus, a simple idea for smoothing an image is to replace every pixel by the average of its neighboring pixels. This means that to determine the new pixel value in the smoothed image, the original pixel is used plus its eight neighboring pixels to compute the arithmetic mean of these nine values. Suppose I⁰(u,v) and I(u,v) represent the original image and the smoothed image, respectively. Then the smoothing process can expressed mathematically as follow

which is equivalent to

In particular, such mathematical operation is called linear filter where the resulting pixel is computed from a set of source pixel by a linear expression. The size of a filter is an important parameter since it specifies how many original pixels contribute to each resulting pixel value. The above smoothing filter uses a 3 x 3 region of support that is centered at the current coordinate (u,v). Similar filter with larger support would have stronger smoothing effects.

It is also possible to assign different weights to the pixels in the support region, such as to give stronger emphasis to pixels that are closer to the center of the region. For any linear filter, the size and shape of the support region are specified by the filter matrix or filter mask H(i,j) where the size of the matrix H equals the size of the filter region and every element H(i,j) specifies the weight of the corresponding pixels in the summation. Mathematically, the application of linear filter H(i,j) on image I⁰ is known as convolution (Fig. 2).

Figure 2. Convolution between linear filter H and the image I⁰(u,v) result in new pixel value I(u,v). Image source: W. Burger and M.J. Burge, Principles of Digital Image Processing : Fundamental Techniques, Springer-Verlag.

Feature of Blurred Image

Edges can roughly be describe as image position where the local intensity changes distinctly along a particular orientation. Mathematically we can detect this change with respect to spatial distance as the first derivative of a function. In order to apply derivative to detect edges, the derivative must be discretize. The weight (coefficient) of each term of discrete derivative equation will form the element of the filter matrix H. Another approach in edge detection is to use second derivative instead of first derivative. A well known filter in this class is Laplacian filter.

Note that when using second derivative approach, an edge is detected when the curve (as measured by second order derivative) crosses zero (Fig. 3).

Figure 3. The thin line represent first order derivative and the thick line represent second order derivative. Image Source: http://aishack.in/tutorials/sobel-laplacian-edge-detectors/

It is not difficult to see that when an image is not blurred, the edge must be sharp, which imply that the curve must be steep around the zero axis. In other words, the curve has high variation around the zero axis. This motivate the notion of Variance of Laplacian (VoL) of an image. The claim is that non-blurred image has high value of VoL, while blurred image has low value of VoL. This operator shall measure the feature of blurred image.

Detecting Blurred ID Card Image

The above method that has been described is applied to the detection of blurred ID card image. In Indonesia, the official ID card issued by the government is known as KTP (Kartu Tanda Penduduk). Our dataset of KTP images consist of 514 images (454 non-blur and 60 blur). We split them into 70% training data and 30% testing data. This result in 360 images (318 non-blur and 42 blur) for training data and 154 images (136 non-bur and 18 blur) for testing data. Note that we maintain the 7:3 ratio for non-blurred and blurred KTP images for both training and testing dataset.

The goal of data analysis in this case is to come up with a simple classification rule. Let T be a specific VoL value, then the rule can be expressed as follow : if VoL of a given image is larger than T, then it is a non-blurred image. Otherwise it is a blurred image.

It is not surprising that VoL value of a set of images (whether is blurred or not) spread across some interval. Histogram for both non-blurred and blurred KTP images from the training set are plotted to better analyze the data (Fig. 4).

Figure 4. Histogram of VoL.

The histogram shows that VoL of blurred KTP images indeed have much lower value compared to non-blurred one. The maximum VoL value of non-blurred KTP images is arounfd 11,385 while maximum VoL value of blurred KTP image is only around 295. However, the VoL from both type of images seems to intersect at some low values. Note that from the histogram of blurred KTP image, the data point is roughly concentrated in the interval [0,50]. Lets look closer at the histogram of both blurred and non-blurred KTP image at these interval (Fig. 5).

Figure 5. Histogram of VoL in the interval [0,50].

Note that although VoL value of both non-blurred and blurred KTP images have some intersection in this interval, the difference is still obvious since VoL of non-blurred KTP images is increasing while blurred KTP images is somewhat decreasing. In this interval, the mode for non-blurred image is above 40, while the mode for blurred image is below 10. A threshold value is sought after between 10 to 40. After some tedious experiment with various threshold value, a threshold T=35 give the best results. The threshold value is then used to classify KTP images from the test data and the performance is shown by confusion matrix (Fig. 6).

Figure 6. Confusion matrix resulted from test dataset.

Note that both false negative error (non-blurred classified as blurred) and false positive error (blurred classified as non-blurred) is nonzero. This is caused by the fact that the set of VoL value from both type of images are not strictly separable. This phenomenon might be due to noise in the data that came from manual data labeling process.

Conclusion and Future Works

An approach to characterize blurred image has been explored in this article. To detect blurrynes, Laplacian-based edge detection operator is applied to a given image and then followed by variance operator which result in the so-called Variance of Laplacian. It is claimed that VoL value of blurred image is lower compared to that of non-blurred image. The method is used to detect blurred KTP images. The histogram of VoL value of KTP images tend to favor the claim, although there is some problem from the fact that some small VoL values are actually intersect at some interval. Training data is used to search for a threshold value T that seek to minimize both false negative and false positive error as reported by the confusion matrix from test data.

The method that has been described is still far from being rigorous and efficient. Future development might consider using optimization and statistical learning. A cost function can be formulated which quantify error classification where the parameter is the threshold value. A gradient-based algorithm will find the optimal threshold such that the cost function reach its minimum (or near minimum). Such strategy will eliminate tedious experiment and the designer can focus more time on model building. Also more data is needed for blurred images. Ideally there should be roughly the same amount of blurred images as well as non-blurred images. This will help to evaluate whether the classifier is better than a weak learner (classifier that is not much better than random guess).

References :

  1. W. Burger and M.J. Burge, Principles of Digital Image Processing : Fundamental Techniques, Springer-Verlag, 2009.
  2. M. Petrou and C. Petrou, Image Processing : The Fundamental, John Wiley & Sons, 2010.
  3. http://aishack.in/tutorials/sobel-laplacian-edge-detectors/

Join our community on Telegram!

--

--