In [1]:
# Code attribution: Yiyin Shen, Tyler Caraza-Harter
# Imports
import matplotlib.pyplot as plt
import skimage
import numpy
In [2]:
# Open the image
image = skimage.io.imread('Spot.png')
img = skimage.color.rgb2gray(image)
skimage.io.imshow(img)
Out[2]:
<matplotlib.image.AxesImage at 0x2919e1adcd0>
In [3]:
# Blur the image
fig, ax = plt.subplots(2, 2)
ax[0, 0].imshow(img, cmap = plt.cm.gray)
ax[0, 1].imshow(skimage.filters.gaussian(img, sigma = 1), cmap = plt.cm.gray)
ax[1, 0].imshow(skimage.filters.gaussian(img, sigma = 10), cmap = plt.cm.gray)
ax[1, 1].imshow(skimage.filters.gaussian(img, sigma = 100), cmap = plt.cm.gray)
Out[3]:
<matplotlib.image.AxesImage at 0x291a3ddf910>
In [4]:
# Get the horizontal edges and vertical edges
dx = skimage.filters.sobel_h(img)
dy = skimage.filters.sobel_v(img)
fig, ax = plt.subplots(1, 2)
ax[0].imshow(dx, cmap = plt.cm.gray, vmin = 0, vmax = 1)
ax[1].imshow(dy, cmap = plt.cm.gray, vmin = 0, vmax = 1)
Out[4]:
<matplotlib.image.AxesImage at 0x291a33ac1d0>
In [5]:
# Get the edges
dxy = skimage.filters.sobel(img)
fig, ax = plt.subplots()
ax.imshow(dxy, cmap = plt.cm.gray)
Out[5]:
<matplotlib.image.AxesImage at 0x291a473a590>
In [6]:
# Highlight the edges in the original image
new_img = image.copy()
new_img[dxy > 0.05] = [0, 255, 0]
fig, ax = plt.subplots()
ax.imshow(new_img)
Out[6]:
<matplotlib.image.AxesImage at 0x291a4fea090>
In [7]:
# Use the Canny Edge detector
edge = skimage.feature.canny(img)
edge_img = image.copy()
edge_img[edge] = [0, 255, 0]
fig, ax = plt.subplots()
ax.imshow(edge_img)
Out[7]:
<matplotlib.image.AxesImage at 0x291a505dd90>