Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in Data Science by (17.6k 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)


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


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


Here's the output:

enter image description here

1 Answer

0 votes
by (41.4k 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)

If you want to Learn Python visit this Online Python Course.

Related questions

Browse Categories