LoslegenKostenlos loslegen

Detect edges (1)

Filters can also be used as "detectors." If a part of the image fits the weighting pattern, the returned value will be very high (or very low).

In the case of edge detection, that pattern is a change in intensity along a plane. A filter detecting horizontal edges might look like this:

weights = [[+1, +1, +1],
           [ 0,  0,  0],
           [-1, -1, -1]]

For this exercise, create a vertical edge detector and see how well it performs on the hand x-ray (im).

Diese Übung ist Teil des Kurses

Biomedical Image Analysis in Python

Kurs anzeigen

Anleitung zur Übung

  • Create a 3x3 array of filter weights that detects when intensity changes from the left to right. Use only the values 1, 0 and -1.
  • Convolve im with the edge detector.
  • Plot the horizontal edges with the seismic colormap. Use vmin=-150 and vmax=150 to control adjust your colormap scale.
  • Add a colorbar and render the results.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Set weights to detect vertical edges
weights = [[____], [____], [____]]

# Convolve "im" with filter weights
edges = ____

# Draw the image in color
plt.imshow(____, ____, vmin=-150, vmax=150)
____
format_and_render_plot()
Code bearbeiten und ausführen