Image Processing: Trivialized



Original Source Here

Image Processing: Trivialised

Deep learning, for everything, WHY?

Photo by Jem Sahagun on Unsplash

The significance of image processing is diminishing, and it is replaced by deep learning for many tasks such as image classification and object detection. For some, I would agree that deep learning provides far better results than image processing. But for others, I would deny it. In machine learning, it can’t be one size fits all. In my experience, machine learning tasks are all about finding a solution that is simple and close to accurate. Neither client nor manager is interested in dealing with complex and rigid solutions unless they are far better than simple ones.

A similar scenario occurs when deep learning is employed in place of image processing. It becomes a classic case of over-engineering. I recently crossed my path with a similar scenario when I was working on the Surface Crack Detection dataset. It is under the “CC by 4.0” license. The datasets contain images of various concrete surfaces with and without cracks. The objective of the dataset is to classify the images. I love going through the work published by others. In doing so, I was astonished by observing that most of them implemented convolutional neural networks for image classification. The impromptu question raised in my mind was,

Why convolutional neural network? Why not image processing?

This raised self-doubt about my decision to implement image processing as the majority of them implemented the convolutional neural networks for image classification. Therefore, I decided to dive deep to understand the problem statement and design an appropriate image processing algorithm to crack it. In this article, we will go through the complete process I undertook.

Table of Content

  1. Current Industrial Approach
  2. Overview of Dataset
  3. Available Solutions
  4. Image Processing Algorithm
  5. Conclusion

Current Industrial Approach

Cracks are an important aspect in monitoring the structural health of the concrete structure and diagnosing its deterioration. If cracks are detected at an earlier stage, further steps can be taken for the betterment of structural health.

Inspection of the concrete structure transpires every five to ten years to evaluate the rigidity and tensile strength. During this process, experienced civil engineers visually check for cracks and their features, such as length, shape, and depth. Next, they sketch all cracks and prepare the inspection report. This process is time-consuming, costly, and prone to human errors. The industries have recently started using cameras to conduct image-based inspections to overcome such issues. Public datasets are available, consisting of images of concrete structures with cracks and without cracks.

Overview of Dataset

The dataset used for the problem statement is “Surface Crack Detection”. It is available on Kaggle as well. The datasets contain images of various concrete surfaces with cracks and without cracks. The image data are divided into two categories, namely negative(without crack) and positive(with crack), in a separate folder for image classification. Each class has 20000 RGB images, and the dimension of each image is 227 x 227 pixels. High-resolution images have high variance in terms of surface finish and illumination condition.

Available Solutions

Most of the notebooks available for this dataset on Kaggle are either applying custom CNN architecture or fine-tuning a pre-trained model. That’s good, but why not keep it simple. Image processing is an aspect that is highly underrated in our domain. A deep understanding of image processing can help to solve several problems.

I have developed an image processing algorithm using OpenCV to crack the problem of classifying the images. For those who are unaware of OpenCV, it is a python library that provides functionalities to tune the image and perform several mathematical operations on it.

Image Processing Algorithm

This section of the blog will depict a code walkthrough of the algorithm which will provide an understanding of the solution. Firstly, I have compared the number of images of both classes to confirm that I have enough samples to test my algorithm.

Total number of positive images are 20000
Total number of negative images are 20000

Data augmentation techniques such as flipping, rotation, and color augmentation can be implemented to increase the data quantity, but it seems unnecessary with image processing. Firstly, we’ll look at a few samples of the negative and positive classes.

Positive Images from Concrete Crack Images for Classification
Negative Images from Concrete Crack Images for Classification

I have created an image processing algorithm using OpenCV in the next step. I have divided the process into four simple steps.

  1. Sharpening: Every image passed through the algorithm will be initially sharpened. The motive of this step is to make sure that every edge in the image is evidently visible.
  2. Blurring: We are only interested in capturing the big edges as they represent cracks. If sharpening is applied without blurring, it will also capture small edges. Therefore, I have blurred the image in the second step to eradicate small edges. The intensity of sharpening must be higher than blurring to ensure that big edges are not blurred in this step.
  3. Thresholding: Firstly, the image is converted to a grayscale image(single channel), followed by converting the grayscale image to a binary image. The binary images are the ones that have either 0 or 255 as pixel values. It can be regarded as a black and white image in layman’s terms. I have used a simple thresholding technique with a base threshold of 230.
  4. Contour detection: Contours are detected from the binary image obtained from the third step. For every image, I have extracted the contour having maximum pixel points. Two key conditions for image classification are as follows:
  • A positive image’s largest contour is expected to have more than N pixels.
  • A negative image’s largest contour is expected to have less than N pixels.

The algorithm works well if the score of the positive class is close to zero and the score of the negative class is close to 20000. In this case, we have taken N as 100. It can be optimized to obtain better results. The above-defined method is implemented on all the images of the dataset.

{'Positive': 1582, 'Negative': 19962}

The result mentioned above can be interpreted as follows:

  • 1582 positive images are misclassified
  • 19962 negative images are correctly classified

I have computed the accuracy of the algorithm as well.

Accuracy is 95.95%

Conclusion

After the code walkthrough, you would be thinking, “That’s easy. I could have done that too”. That’s true. More than detecting cracks, I am much more interested in spreading awareness about the significance of image processing. Deep learning is not an answer to every problem. Several use cases can be solved with image processing, like finding a parking slot, evaluating the MCQ exam, etc. Additionally, there are many perks, as listed below.

Image Processing Perks. Source: Image by Author

Apart from OpenCV, Scikit-image is also a famous library for performing operations on images. I hope that through this article, you learned the importance of image processing. Some resources to learn image processing through OpenCV are listed below,

That’s all, folks. Happy learning.

AI/ML

Trending AI/ML Article Identified & Digested via Granola by Ramsey Elbasheer; a Machine-Driven RSS Bot

%d bloggers like this: