I'm trying to make a function to highlight edges in an image using convolution from scipy.signal. Here is my code:

def highlight_edges(self):
    window = np.array([[-1, -1, -1],
                       [-1, 9, -1],
                       [-1, -1, -1]])

    if self.image_data.ndim == 2:
        # gray image
        self.image_data = convolve2d(self.image_data, window, mode='same', boundary='symm')
    elif self.image_data.shape[2] == 3:
        # rgb image
        # for each channel:
        for i in range(3):
            self.image_data[:, :, i] = convolve2d(self.image_data[:, :, i], window, mode='same', boundary='symm')

It works just fine for a gray image, but for and RGB Image it returns a mess. I suspect, that there might be some overflowing going on, but I'm not really sure. Here are the images:

Original image:

enter image description here

After performing highligh_edges function:

enter image description here

0 Answers