└── pencilsketch.py /pencilsketch.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[1]: 5 | 6 | 7 | import cv2 8 | import numpy as np 9 | import plotly.express as px 10 | 11 | 12 | # In[54]: 13 | 14 | 15 | import sys 16 | 17 | # Install required packages 18 | get_ipython().system('{sys.executable} -m pip install opencv-python numpy plotly') 19 | 20 | import cv2 21 | import numpy as np 22 | import plotly.express as px 23 | 24 | # Loading Image 25 | img = cv2.imread("dq.jpg") 26 | img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) 27 | 28 | # Displaying Image 29 | imgs = px.imshow(img) 30 | imgs.update_xaxes(showticklabels=False).update_yaxes(showticklabels=False) 31 | imgs.show() 32 | 33 | 34 | # In[55]: 35 | 36 | 37 | #Resizing image shape 38 | scale_percent = 0.60 39 | width = int(img.shape[1]*scale_percent) 40 | height = int(img.shape[0]*scale_percent) 41 | dim = (width,height) 42 | resized = cv2.resize(img,dim,interpolation = cv2.INTER_AREA) 43 | res=px.imshow(resized) 44 | res.update_xaxes(showticklabels=False).update_yaxes(showticklabels=False) 45 | res.show() 46 | 47 | 48 | # In[56]: 49 | 50 | 51 | #Sharpening Image 52 | kernel_sharpening = np.array([[-1,-1,-1], 53 | [-1, 9,-1], 54 | [-1,-1,-1]]) 55 | sharpened = cv2.filter2D(resized,-1,kernel_sharpening) 56 | sharp=px.imshow(sharpened) 57 | sharp.update_xaxes(showticklabels=False).update_yaxes(showticklabels=False) 58 | sharp.show() 59 | 60 | 61 | # In[57]: 62 | 63 | 64 | #Converting an image into gray_scale image 65 | grayscale = cv2.cvtColor(sharpened , cv2.COLOR_BGR2GRAY) 66 | gray = px.imshow(grayscale, color_continuous_scale='gray') 67 | gray.update_xaxes(showticklabels=False).update_yaxes(showticklabels=False) 68 | gray.show() 69 | 70 | 71 | # In[58]: 72 | 73 | 74 | #Inverting the image 75 | invs = 255-grayscale 76 | inv=px.imshow(invs,color_continuous_scale='gray') 77 | inv.update_xaxes(showticklabels=False).update_yaxes(showticklabels=False) 78 | inv.show() 79 | 80 | 81 | # In[59]: 82 | 83 | 84 | #Inverting the image 85 | invs = 255-grayscale 86 | inv=px.imshow(invs,color_continuous_scale='gray') 87 | inv.update_xaxes(showticklabels=False).update_yaxes(showticklabels=False) 88 | inv.show() 89 | 90 | 91 | # In[60]: 92 | 93 | 94 | #Inverting the image 95 | invs = 255-grayscale 96 | inv=px.imshow(invs,color_continuous_scale='gray') 97 | inv.update_xaxes(showticklabels=False).update_yaxes(showticklabels=False) 98 | inv.show() 99 | 100 | 101 | # In[ ]: 102 | 103 | 104 | 105 | 106 | --------------------------------------------------------------------------------