Detecting edges is a common image processing problem. For example, digital cameras often feature face detection. Or, some robotic competitions require robots to find a ball using a digital camera. In both cases, it is important for the computers to see the line between different objects.
One way to accomplish this is to compare the color at the current pixel with the pixel in the next column to the right. If the colors differ by more than some specified amount, then and 'edge' has been detected. The program sets the current pixel to black. Otherwise, the current pixel isn't on an edge, and so it is set to white. You can see this in action in Figure 12.
The formula for determining the 'distance' between two colors is similar to the one for finding the distance between two points:
Luckily for you, this formula is already coded into the colorDistance method in the Pixel class. It takes a pixel as its implicit parameter and a color as its explicit parameter.
The edgeDetection method implements that algorithm. Note that the nested for loop stops before reaching the last column. This is crucial for preventing an error. Can you figure out what error that is, and how this fixes it?