Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# import required libraries
import numpy as np
import matplotlib.pyplot as plt
import cv2
from skimage.color import rgb2gray
from scipy import ndimage
# read the image
img = cv2.imread('1.jpeg')
# imread returns image in BRG format by default, convert it to RGB
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# convert to grayscale for 2D convolution
gray = rgb2gray(img)
kernel = # define your kernel as a 2d numpy array
output = ndimage.convolve(gray, kernel, mode='reflect')
# The mode parameter determines how the input array is extended when the filter overlaps a border
# plot the output image
plt.imshow(output, cmap = 'gray')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.