0 votes
1 view
in Data Science by (11.2k points)

Here's my code:

from matplotlib.pyplot import imread

import matplotlib.pyplot as plt

from scipy.ndimage.filters import convolve

k3 = np.array([ [-1, -1, -1], [-1, 8, -1], [-1, -1, -1] ])

img = imread("lena.jpg")

channels = []

for channel in range(3):

    res = convolve(img[:,:,channel], k3)

    channels.append(res)

img = np.dstack((channels[0], channels[1], channels[2]))

plt.imshow(img)

plt.show()

k3 filter suppose to be an edge detection filter. Instead, I'm getting a weird image looks like white noise.

Why?

Here's the output:

enter image description here

1 Answer

0 votes
by (16.1k points)

Here, in this filter,you should convert the image to a signed type, like a 16-bit signed integer or a floating-point type.

img = img.astype(np.int16)

...