MASTERCLASS

# Further topics in image processing

### Lessons

#### Share

#### Transcript

Another variation on mathematical morphology is what's called the hit-or-miss transform. Now in this case, the structuring element contains pixels which have three possible values. The value could be zero, which means that the pixel that it sits over must be zero. It could be one, which means the pixel that it sits over must be equal to one or it can have a value of don't care, so it doesn't matter what pixel value is underneath.

Let's illustrate this with some simple examples.

Here are two input pixel patterns, and we're going to overlay this particular hit-and-miss transform on top of each of them. Now in the first case, we see that the result is true. The red pixels in the structuring element lay over zero pixels in the import image and blue pixels in the structuring element lay over input pixels which are all equal to one. So the result is true. We don't care about the other two pixels here, what values they have, they do not participate.

Now let's have a look at this example.

The red pixels in the structuring element lay over pixels, which in this case are not all equal to zero. The blue pixels in the structuring element lay over input pixels which are all one, so that's good. But in this case, the result is false because of this one valued input pixel over here.

The hit-and-miss transform can be used for a lot of really useful and interesting applications.

Consider this input image here, it's a synthetic image that I created using a bitmap editor, but we could think of it perhaps as an aerial photograph of a road network or something like that. Now, by applying a particular sequence of hit-and-miss transforms over and over again, it's possible to perform an operation called skeletonization. And what we've done is to convert our input image which contains a number of lines of arbitrary thickness into a skeleton of that image; contains a number of lines and each line is guaranteed to be only one pixel wide. Now we can perform this skeletonization operation using the toolbox function called ithin and you pass into it a binary image. Now this operation is quite slow because this hit-and-miss transform is relatively expensive to compute in its own right and to do skeletonization we have to apply the hit-and-miss transform over and over again to the image in order to obtain the skeleton.

Another really interesting application of the hit-and-miss transform is to find intersections. So let's assume that we have the skeletonized figure created in the previous slide and I want to find the intersection points. An intersection point I'm going to define as a place where three line segments come together at a single point.

And in this case, there are five intersection points. So I want to find the pixel coordinates where these three single pixel wide lines meet. I want to find these intersections and again we can perform this function using the hit-and-miss transform. In the right hand image we see the five intersection points highlighted and each of these is just a single pixel.

The pixel is set at the coordinate where those three line segments meet and we can compute this intersection using the toolbox function itriplepoint. The input is a binary image that contains a single pixel wide skeleton type image.

Once again, this triple point function is quite slow to execute because the hit-and-miss transforms have to be executed iteratively until there are only these few isolated pixels remaining.

Here's the synthetic image that I introduced to you earlier, it's loaded into the workspace. It’s a six hundred by eight hundred logical image so the values are either zero or one, so I can create a thinned version of this image using the toolbox function ithin, I pass in the logical image and it will compute for quite a while, almost a minute, and here it is.

If I display this in a new window. Display the thinned image, we can zoom in on this image to show that it is indeed a single pixel wide. Zoom in again and we can see that it is just a single pixel wide line. A whole bunch of white blocks stacked end to end. Alright, unzoom that one.

Now I can compute the triple points and I do that using itriplepoint function from the toolbox and this function and I'm going passes in the thinned image.

This function's a lot quicker than the last one. Here's the result, so I will put that on figure one and display the triple points and little hard to see, there are only single pixels are set here and if I can zoom in there's one of the triple points.

In mathematical morphology the values of the structuring element were either zero or one. The hit and miss transform extends this to also include a ‘don’t care’ value. We can use this transform to solve complex problems like finding the skeleton of an object or the intersection point of lines.

### Skill level

MATLAB experience

This content assumes an understanding of high school level mathematics; for example, trigonometry, algebra, calculus, physics (optics) and experience with MATLAB command line and programming, for example workspace, variables, arrays, types, functions and classes.