#5, First Floor, 4th Street , Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to detect edges and transformation of an image using openCV in python?
Description

To detect edges of an image and make transformation of an image using openCV library in python

Input

.PNG image file.

Output

  Edges of PNG image.

  Transformation of PNG image.

Process

  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.

Sapmle Code

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

Screenshots