MulaiMulai sekarang secara 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.

Latihan ini adalah bagian dari kursus

Image Modeling with Keras

Lihat Kursus

Petunjuk latihan

  • 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).

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

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)
Edit dan Jalankan Kode