Image Recognition Using Edge Detection

Image for post
Image for post

Image recognition is a popular technology that can detect, understand, and distinguish images from one another. Technologies such as text recognition and facial recognition are all specific applications of image recognition.

Image for post
Image for post

How is it done?

Understanding the way we perceive objects and images has always been a hot topic for research. Researchers globally have observed that the human eye is very sensitive to the edges of an object. Typically, a person identifies an object by first determining the outline of the object and then processing this information in the visual cortex. Computer scientists have designed sophisticated image recognition systems by emulating the way we recognize images.

Image for post
Image for post

The example below is based on a paper by Adit Deshpande, a student at The University of California, titled A Beginner’s Guide To Understanding Convolutional Neural Networks. In this paper, he introduces a simple algorithm as the basis of image recognition.

Image for post
Image for post

Unlike the human eye, a computer can only recognize images as numbers. The above image helps us understand the differences in image perception by a human and a computer. A computer will then perform “image recognition” techniques by determining a pattern from this large matrix of numbers.

Generally, in edge detection, we can convert the color information of every pixel into its grayscale value. To minimize interference, we can downsize the image (such as downsizing the image to 49x49 pixels), thus resulting in a 49x49 matrix.

We can then analyze the matrix section-by-section starting from the top left corner.

Image for post
Image for post

Next, we take some existing edge models, such as verticals, right angles, circles, acute angles and so on. The figure below shows a 7x7 matrix of an edge model and its corresponding visualized curve.

Image for post
Image for post

Observe how the value of the matrix is nonzero whenever the pixels overlap with the rounded curve.

Now that we have determined an edge filter, let us take it a step higher. The figure below shows a grayscale image of a mouse.

Image for post
Image for post

Take a section of the image starting from the upper-left corner and obtain its pixel representation. We can then convolve this matrix with the edge filter matrix.

Image for post
Image for post

The result is 6,600. What does this value indicate? Let’s analyze a different section. Move the sampling matrix towards the head of the mouse and perform the same calculations.

Image for post
Image for post

Convolving the two matrices produces a value of 0.

By visual comparison, we can see that the resulting value is high if the edges of the sampled section and the edge filter closely match. Mathematically, the greater the value, the closer the images match.

In this example, we can conclude that the shape of the image in the first section is a rounded corner. We can determine the object of the image by matching different patterns for each section and ultimately collating the entire image.

Conclusion

Written by

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store