POSTS

My Way to Digital Image Processing

Reading time: 4 min Written by Marco Tschannett

Hi, I’m Marco from Austria. I’m a software engineer, sometimes designer. Somebody surely would call me a fullstack developer ^^

I love to develop, finding Solutions for problems I care about and learning new technologies. This has driven me into a domain, which I never really thought about and never imagined of learning and using while coding.

Image processing

Wikipedia tells us this about image processing:

This article is about mathematical processing of digital images. For artistic processing of images, see Image editing.
In computer science, digital image processing is the use of computer algorithms to perform image processing on digital images.[1] As a subcategory or field of digital signal processing, digital image processing has many advantages over analog image processing. It allows a much wider range of algorithms to be applied to the input data and can avoid problems such as the build-up of noise and signal distortion during processing. Since images are defined over two dimensions (perhaps more) digital image processing may be modeled in the form of multidimensional systems.

Source: https://en.wikipedia.org/wiki/Digital_image_processing

tl;dr

Use mathematics to find things in an image.

tl;dr2

I should have been more careful at school

So what I tried to accomplish was finding rectangles in an image for a simple app which I was programming in flutter (see ^^ new tech everywhere).

Digital image processing is a field of Computer Science which has began in the 60s and is really important in many fields of our modern lifes.

From medical images like x-ray to astronomy where it is used to process images from not visible light into something we can see.

Finding lines. Easy right?!

For a human it is extremly easy to find lines and patterns. Our brains is oustandingly good in finding patterns.

But the problem with all of this is: The computer is not our brain.

There is a huge number of attempts to find patterns in images. These are leading from AI to processing images pixel by pixel and trying to calculate some patterns out of that.

So how can we try to do this?

One way is to use a algorithm called Hough-Transformation. This is a algorithm to find geometric forms in images.

It works by calculating the angles and distances from the source (This is called the polar coordinate system) and then voting for points where a other line is met.

Polar Coordinate System

At the end we get a list of angles and radiuses (which are used in the polar coordinate system to show the position of a point)

The most upvoted entries in that list are the longest lines. With this we have successfully found lines in our images.

The procedure

The procedure for finding lines is sequence of different processing steps.

  1. grayscale
  2. blur
  3. canny edge detection
  4. hough transform

The first step is to grayscale the image, this reduces it a little bit in size and we have a easier time telling which color our edges will be in the end.

Then we blur the image a little bit (just a tick). This is important to reduce noice in the image which would be false positives at the end. Also this reduces memory consumption in the end, because the list of hough points can get pretty large.

The third step is to find edges in our image. For this we use canny edge detection. There are others, maybe I make a comparison sometimes.

The last step is to actually find the lines. Here our hough transform comes into play.

It is important to know, that the first three steps are needed, because otherwise we would get pretty bad results.

Why tho?

  • We wouldn’t exactly know which colors our edges have. Are they black? Is that the background? Maybe grey? White?
    • To get around this, we grayscale our image.

Summary

I hope I gave a small introduction into image processing.

I try to show some code (because I found myself stuck with bad examples and I want to have a Dart lang example for this).

And I also try to make a few easy-to-understand posts about each algorithm and/or step used here.

Have a good time and feel free to write a comment.

Tags

comments powered by Disqus