To detect edges of an image and make transformation of an image using openCV library in python
.PNG image file.
Edges of PNG image.
Transformation of PNG image.
Import opencv library.
Load the image that you want to transform.
Find the edges using opencv library.
Get image as matrix using opencv.
Plot both the images using matplotlib.pyplot.
#import libraries
import cv2
import numpy as np
from matplotlib import pyplot as plt
#Load the image
img = cv2.imread(‘msd1.jpg’,0)
#Canny edge detection
print(“Canny edge detection\n”)
edges = cv2.Canny(img,100,200)
plt.figure(figsize=(13,13))
plt.subplot(121),plt.imshow(img,cmap = ‘gray’)
plt.title(‘Original Image’), plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(edges,cmap = ‘gray’)
plt.title(‘Edge Image’), plt.xticks([]), plt.yticks([])
plt.show()
#image tranformation
print(“Image transformation”)
rows,cols = img.shape
Matrix = cv2.getRotationMatrix2D((cols/2,rows/2),50,1)
affine = cv2.warpAffine(img,Matrix,(cols,rows))
plt.figure(figsize=(13,13))
plt.subplot(121),plt.imshow(img,cmap = ‘gray’)
plt.title(‘Original Image’), plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(affine,cmap = ‘gray’)
plt.title(‘Transformed Image’), plt.xticks([]), plt.yticks([])
plt.show()