IniziaInizia gratis

Image convolutions

The convolution of an image with a kernel summarizes a part of the image as the sum of the multiplication of that part of the image with the kernel. In this exercise, you will write the code that executes a convolution of an image with a kernel using Numpy. Given a black and white image that is stored in the variable im, write the operations inside the loop that would execute the convolution with the provided kernel.

Questo esercizio fa parte del corso

Image Modeling with Keras

Visualizza il corso

Istruzioni dell'esercizio

  • Select the right window from the image in each iteration and multiply this part of the image with the kernel.
  • Sum the result and allocate the sum to the correct entry in the output array (results).

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

kernel = np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]])
result = np.zeros(im.shape)

# Output array
for ii in range(im.shape[0] - 3):
    for jj in range(im.shape[1] - 3):
        result[ii, jj] = (____[ii:ii+3, jj:____+____] * ____).____

# Print result
print(result)
Modifica ed esegui il codice