Skip to content

Instantly share code, notes, and snippets.

@KhyatiMahendru
Last active July 17, 2019 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KhyatiMahendru/2ba8a00af1787f23d871ded3eadf9ba0 to your computer and use it in GitHub Desktop.
Save KhyatiMahendru/2ba8a00af1787f23d871ded3eadf9ba0 to your computer and use it in GitHub Desktop.
# 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