LoslegenKostenlos loslegen

An image processing pipeline

Your colleague has written a preprocessing function to use on the American sign language images in order to boost your machine learning model's accuracy. This function will take a grayscale image and run Canny edge detection on it. Canny edge detection is commonly used in classical computer vision and highlights the edges of objects in an image. You want to apply it to all of the images in your dataset.

The function your colleague has written is available in your environment as compute_edges(), and it takes an image that has dimensions (1, h, w) where the height h and the width w can be any integers.

The Dask array of your images is available in the environment as image_array. This array has shape (N, h, w, 3) where N is the number of images, and there are 3 channels for red, blue, and green.

dask.array has been imported for you as da.

Diese Übung ist Teil des Kurses

Parallel Programming with Dask in Python

Kurs anzeigen

Anleitung zur Übung

  • Convert the image from color to grayscale by taking the mean along the last dimension.
  • Use the grayscale image arrays's .map_blocks() method to apply the compute_edges() function to to each image.
  • Select the zeroth edge image only and compute it.
  • Use plt.imshow() to plot the edges.

Interaktive Übung

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

# Convert the color photos to grayscale
grayscale_images = ____

# Apply the edge detection function
edge_images = ____.____(____)

# Select the zeroth image and compute its values
sample_image = ____

# Show the result
____(____, cmap='gray')
plt.show()
Code bearbeiten und ausführen