function convolve(image, kernel):

   output = new_grid(size = image.size - kernel.size + 1)
   for row, col in output.positions:
      patch = image[row : row + kernel.height, col : col + kernel.width]
      output[row][col] = sum(patch[i][j] * kernel[i][j] for i, j in patch.positio
 ns)
   return output  # the same small kernel slides across the whole image
