Image Processing with SciPy – scipy.ndimage

12

scipy.ndimage is a submodule of SciPy which is mostly used for performing an image related operation
It is now deprecated we can not use the misc package on the latest version scipy.
If we want to show image and perform an operation on images then we can use 
imageio package to write and read images with the following code.
import imageio
f=imageio.imread('img.jpg')
import matplotlib.pyplot as plt
plt.imshow(f)
plt.show()
#note you can upload your own images to show the image(img.jpg).
If we want to flip the images of the actual image using this then we can use flipud() of numpy
import numpy as np
flip_ud_face = np.flipud(f)
plt.imshow(flip_ud_face)
plt.show()
Rotate the image at particular angle in scipy.
import numpy as np
from scipy import ndimage, misc

s=ndimage.rotate(f, 45)
plt.imshow(s)
plt.show()

Code to blur image

import numpy as np from scipy import ndimage, misc #s=ndimage.rotate(f, 45) s=ndimage.gaussian_filter(f, sigma=3) plt.imshow(s) plt.show()


http://scipy-lectures.org/advanced/image_processing/

Post a Comment

12Comments

POST Answer of Questions and ASK to Doubt

  1. # DATA Science ( 7 to 8 PM)

    # Matching two Images using Nd-Image(SciPy)

    import imageio
    import numpy as np
    f = input("Name of First Image :-\t")
    g = input("Name of Second Image you want to Match :-\t")

    f1 = imageio.imread(f)
    g1 =imageio.imread(g)

    import matplotlib.pyplot as plt

    plt.imshow(f1)
    plt.show()

    plt.imshow(g1)
    plt.show()

    if np.all(f == g):
    print("Image is Matched")
    else:
    print("Image Un-Matched")

    ReplyDelete
  2. #read image
    import cv2
    img=cv2.imread("C:\\Users\DELL\\Pictures\\cdgi\\FB_IMG_1475301504207.jpg")
    cv2.imshow("output",img)
    cv2.waitKey(0)

    ReplyDelete
  3. #read and write image
    import cv2
    img=cv2.imread("C:\\Users\DELL\\Pictures\\cdgi\\FB_IMG_1475301504207.jpg")
    cv2.imshow("output",img)
    cv2.imwrite("open.jpg",img)
    cv2.imwrite("open.png",img)
    cv2.waitKey(0)

    ReplyDelete
  4. #show height and width pixel value
    import cv2
    img=cv2.imread("C:\\Users\DELL\\Pictures\\cdgi\\FB_IMG_1475301504207.jpg")
    cv2.imshow("output",img)
    print(img.shape)
    print("height pixel value:-",img.shape[0])
    print("width pixel value:-",img.shape[1])
    cv2.waitKey(0)

    ReplyDelete
  5. #first method
    #convert colorfull image to grey image
    import cv2
    img=cv2.imread("C:\\Users\DELL\\Pictures\\cdgi\\FB_IMG_1475301504207.jpg")
    cv2.imshow("show",img)
    cv2.waitKey(0)
    grey_col=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    cv2.imshow("showing",grey_col)
    cv2.waitKey(0)

    ReplyDelete
  6. #second method
    #convert colorfull image to grey image
    import cv2
    img=cv2.imread("C:\\Users\\DELL\\Pictures\\cdgi\\FB_IMG_1475301504207.jpg",0)
    cv2.imshow("show",img)
    cv2.waitKey(0)

    ReplyDelete
  7. #pure binary image(black and white)
    import cv2
    img=cv2.imread("C:\\Users\\DELL\\Pictures\\cdgi\\FB_IMG_1475301504207.jpg",0)
    cv2.imshow("s",img)
    cv2.waitKey(0)
    ret,bw=cv2.threshold(img,127,255,cv2.THRESH_BINARY)
    cv2.imshow("binary",bw)
    cv2.waitKey(0)
    print(ret)

    ReplyDelete
  8. #extract RGB color
    import cv2
    import numpy as np
    img=cv2.imread("c")
    cv2.imshow("output",img)
    cv2.waitKey(0)
    B,G,R=cv2.split(img)
    zeros=np.zeros(img.shape[:2],dtype="uint8")
    cv2.imshow("Red",cv2.merge([zeros,zeros,R]))
    cv2.imshow("Green",cv2.merge([zeros,G,zeros]))
    cv2.imshow("Blue",cv2.merge([B,zeros,zeros]))
    cv2.waitKey(0)

    ReplyDelete
  9. #campare image
    import cv2
    import numpy as np
    img=cv2.imread('C:\\Users\DELL\\Pictures\\cdgi\\FB_IMG_1475301504207.jpg')
    numpydata =np.array(img)
    img1=cv2.imread('C:\\Users\\DELL\\Pictures\\cdgi\\FB_IMG_1475301504207.jpg') #7997
    numpydata1=np.array(img1)
    if np.all(numpydata==numpydata1):
    print("same image")
    else:
    print("not same")
    cv2.imshow("open",img)
    cv2.waitKey(0)
    cv2.imshow("open1",img1)
    cv2.waitKey(0)

    ReplyDelete
  10. import PIL
    import numpy as np
    img=Image.open('C:\\Users\DELL\\Pictures\\cdgi\\FB_IMG_1475301504207.jpg')
    numpydata =np.array(img)
    img1=Image.open('C:\\Users\DELL\\Pictures\\cdgi\\FB_IMG_1475301507997.jpg')
    numpydata1=np.array(img1)
    if np.all(numpydata==numpydata1):
    print("same image")
    else:
    print("not same")

    ReplyDelete
  11. #image translation
    import cv2
    import numpy as np
    img=cv2.imread("C:\\Users\\DELL\\Pictures\\cdgi\\FB_IMG_1475301504207.jpg")
    height,width=img.shape[:2]
    print(height)
    print(width)
    quarter_height,quarter_width=height/4,width/4
    print(quarter_height)
    print(quarter_width)
    T=np.float64([[1,0,quarter_width],
    [0,1,quarter_height]])
    print(T)
    img_tra=cv2.warpAffine(img,T,(width,height))
    cv2.imshow("original image",img)
    cv2.imshow("translation",img_tra)
    cv2.waitKey(0)

    ReplyDelete
  12. #hue:0-180,saturation:0-255,value:0-255
    import cv2
    img=cv2.imread("C:\\Users\DELL\\Pictures\\cdgi\\FB_IMG_1475301504207.jpg")
    img_hsv=cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
    cv2.imshow("hsv",img_hsv)
    cv2.imshow("hue:-",img_hsv[:,:,0])
    cv2.imshow("saturation:-",img_hsv[:,:,1])
    cv2.imshow("value:-",img_hsv[:,:,2])
    cv2.waitKey(0)

    ReplyDelete
Post a Comment