top of page

Image Processing

Image Files

Searching Images



Edge Detection

Template Matching


Edge Detection


In the previous section, we picked out objects of interest (i.e., the flowers) by focusing on the brightest regions, since we know that the flowers are lighter than the other parts of the image. Another way you can pick out an object of interest from image is through edge detection. The basic idea behind edge detection methods is that they check how quickly intensity values change across an image. This assumes that within a single object, the intensity does not change too much, but the intensities change a lot between objects. For example, within a single flower petal, there are small variations in color, but the pixels are mostly similar in intensity to one another. But when you cross over to a leaf, the pixels suddenly become much darker.

One widely-used edge detection method is called the Roberts algorithm, which is also included as a function in the scikit-image library. We apply this algorithm to the same image of flowers we analyzed in the previous section, and we see that the processed image mostly consists of the edges of the flowers, with some contribution from the wooden frame on the side and the leaves on the bottom of the image.

1  #import image processing package

 from skimage import io

 from skimage.filters import roberts

 #import plotting package

 import matplotlib.pyplot as plt

 #read in image

 imagefile = io.imread("Flowers.jpg", as_gray = True)


 #find object edges

10 edges = roberts(imagefile)

11 plt.imshow(edges, cmap = "gray")

12 plt.savefig("floweredges.jpg")

bottom of page