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
Python3
## 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)
Python3
# reading the image
plt.imshow(img)

# # displaying the shape of the image
print(img.shape)
(500, 870, 3)
Python3
img1 = skimage.io.imread('images/pattern.jpg')
plt.imshow(img1)
Python3
img1.shape
(1300, 1950, 3)
Python3
r = img1[:,:,0] # red matrix
g = img1[:,:,1] # green
b = img1[:,:,2] # blue
Python3
r.shape
(950, 634)
Python3
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)
Python3
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

Python3
import skimage.color
img2 =  skimage.io.imread('images/sky.jpg')
plt.imshow(img2)
Python3
# 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'))
To save the  gray image of Taj_mahal as Taj_mahal_gray
Python3
skimage.io.imsave('images/Taj_mahal_gray.jpg',gray)




Comments

Popular posts from this blog

Covid-19 Analysis and Visualization using Plotly Express

Artificial Intelligence (Problem Solving)

Linear Regression