to make a sketch from image

Pencil Sketcing

Open CV

import cv2

import sys


#read image

image = cv2.imread("1200px-Dubai_skyline_2015_(crop).jpg")


#check if image exists

if image is None:

    print("can not find image")

    sys.exit()#to terminate


#convert to gray scale

grayImage = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)


#invert the gray image

grayImageInv = 255 - grayImage


#Apply gaussian blur

grayImageInv = cv2.GaussianBlur(grayImageInv, (21, 21), 0)


#blend using color dodge

output = cv2.divide(grayImage, 255-grayImageInv, scale=256.0)



cv2.namedWindow("pencilsketch", cv2.WINDOW_AUTOSIZE)

frame=cv2.resize(output,None,fx=0.5,fy=0.5,interpolation=cv2.INTER_AREA)#to draw the frame

#display images

#cv2.imshow("image", image)

cv2.imshow("pencilsketch", output)


#press esc to exit the program

cv2.waitKey(0)


#close all the opened windows

cv2.destroyAllWindows()


'''

read image->grayscale->blur->color dodge->display image

'''