# 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
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)

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")

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")

import cv2
cv2.imshow("output",img)
cv2.waitKey(0)

3. #read and write image
import cv2
cv2.imshow("output",img)
cv2.imwrite("open.jpg",img)
cv2.imwrite("open.png",img)
cv2.waitKey(0)

4. #show height and width pixel value
import cv2
cv2.imshow("output",img)
print(img.shape)
print("height pixel value:-",img.shape[0])
print("width pixel value:-",img.shape[1])
cv2.waitKey(0)

5. #first method
#convert colorfull image to grey image
import cv2
cv2.imshow("show",img)
cv2.waitKey(0)
grey_col=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cv2.imshow("showing",grey_col)
cv2.waitKey(0)

6. #second method
#convert colorfull image to grey image
import cv2
cv2.imshow("show",img)
cv2.waitKey(0)

7. #pure binary image(black and white)
import cv2
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)

8. #extract RGB color
import cv2
import numpy as np
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)

9. #campare image
import cv2
import numpy as np
numpydata =np.array(img)
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)

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")

11. #image translation
import cv2
import numpy as np
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)

12. #hue:0-180,saturation:0-255,value:0-255
import cv2