# Lecture 39 (Sherriff) - Images 3

Lecture Date: Monday, April 20

Another day of image algorithms! These are a bit trickier than the last few days…

The algorithms for today are:

• Edge Detection
• Image Subtraction

#### Edge Detection

The edge detection algorithm will show us where the edges of objects are in an image and highlight them. The basic idea is that we can look at every pixel and then see if the pixels next to it are substantially different in intensity. To do this, we will apply a set of convolution matrices called Sobel operators to each pixel. The set consists of two matrices: one that looks for differences on the x axis and one on the y axis. The steps of the algorithm are:

• Convert the original image to grayscale
• Create an empty image of the same size as the original
• Then, for each pixel:

• Convolve the pixel with the `x_mask`, resulting in an `int` called `gX`

• Convolve the pixel with the `y_mask`, resulting in an `int` called `yY`
• Compute the square root of the sum of squares of `gX` and `gY` called `g`
• Based on the value of `g`, assign the corresponding pixel in the new image to black or white

One example would be if `g` > 175, make the pixel black and otherwise white.

#### Image Subtraction

Image subtraction shows us the difference between two images, highlighting what has changed. The `Pixel` class provides a method to determine the distance between two colors. We can use this to loop over the images.