Last active
July 17, 2019 11:45
-
-
Save KhyatiMahendru/2ba8a00af1787f23d871ded3eadf9ba0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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