InĀ [1]:
# Code attribution: Yiyin Shen, Tyler Caraza-Harter
# Imports
import skimage
import numpy
InĀ [2]:
# Open the image
img = skimage.io.imread('Spot.png')
skimage.io.imshow(img)
Out[2]:
<matplotlib.image.AxesImage at 0x1cf5babf490>
InĀ [3]:
# Get the 3D color array
print(img.shape)
img[0:3, 0:3]
(450, 600, 3)
Out[3]:
array([[[212, 214, 226], [212, 214, 226], [212, 214, 226]], [[212, 214, 226], [214, 216, 228], [214, 214, 227]], [[210, 214, 226], [212, 214, 225], [212, 214, 228]]], dtype=uint8)
InĀ [4]:
# Convert to grayscale
gray = skimage.color.rgb2gray(img)
print(gray.shape)
gray[0:3, 0:3]
(450, 600)
Out[4]:
array([[0.84094196, 0.84094196, 0.84094196], [0.84094196, 0.8487851 , 0.84289137], [0.83927529, 0.84065922, 0.84150745]])
InĀ [5]:
# Plot the grayscale image
skimage.io.imshow(gray)
Out[5]:
<matplotlib.image.AxesImage at 0x1cf5babdf10>
InĀ [6]:
# Compute the pixel intensity features
x = numpy.ndarray.flatten(gray)
print(x.shape)
x[0:9]
(270000,)
Out[6]:
array([0.84094196, 0.84094196, 0.84094196, 0.84094196, 0.84150745, 0.83366431, 0.84094196, 0.84094196, 0.84094196])