Scikit Image
scikit-image is an easy and most powerful image processing Python package that works with NumPy arrays. The package is imported as skimage.
# importing required libraries
import numpy as np
import skimage.io
import matplotlib.pyplot as plt
%matplotlib inline
## reading the image
img = skimage.io.imread('images/Taj_mahal.jpg')
## displaying the image as an array
img
array([[[43, 50, 60], [43, 50, 60], [43, 50, 60], ..., [63, 46, 36], [63, 46, 36], [63, 46, 36]], [[43, 50, 60], [43, 50, 60], [44, 51, 61], ..., [63, 46, 36], [63, 46, 36], [63, 46, 36]], [[43, 50, 60], [44, 51, 61], [44, 51, 61], ..., [63, 46, 36], [63, 46, 36], [63, 46, 36]], ..., [[32, 30, 31], [32, 30, 31], [33, 31, 32], ..., [24, 16, 14], [24, 16, 14], [24, 16, 14]], [[31, 29, 30], [31, 29, 30], [31, 29, 30], ..., [26, 18, 16], [26, 18, 16], [25, 17, 15]], [[30, 28, 29], [30, 28, 29], [30, 28, 29], ..., [27, 19, 17], [27, 19, 17], [27, 19, 17]]], dtype=uint8)
# reading the image
plt.imshow(img)
# # displaying the shape of the image
print(img.shape)
(500, 870, 3)

img1 = skimage.io.imread('images/pattern.jpg')
plt.imshow(img1)

img1.shape
(1300, 1950, 3)
r = img1[:,:,0] # red matrix
g = img1[:,:,1] # green
b = img1[:,:,2] # blue
r.shape
(950, 634)
plt.figure(figsize=(10,6))
plt.subplot(1,3,1)
plt.imshow(r,cmap='gray')
plt.subplot(1,3,2)
plt.imshow(g,cmap='gray')
plt.subplot(1,3,3)
plt.imshow(b,cmap='gray')
plt.show()
plt.imshow(img1)

plt.figure(figsize=(10,6))
plt.subplot(1,3,1)
plt.imshow(r,cmap='Reds')
plt.subplot(1,3,2)
plt.imshow(g,cmap='Greens')
plt.subplot(1,3,3)
plt.imshow(b,cmap='Blues')
plt.show()
plt.imshow(img1)

Convert Image into Gray Scale
import skimage.color
img2 = skimage.io.imread('images/sky.jpg')
plt.imshow(img2)

# reading the image
gray = skimage.color.rgb2gray(img2)
# displaying the shape of the image(img2)
print(img2.shape)
# displaying the shape of the gray image
print(gray.shape)
# displaying the gray image
print(plt.imshow(gray,cmap='gray'))

skimage.io.imsave('images/Taj_mahal_gray.jpg',gray)
Comments
Post a Comment