Skip to content

Commit 7ca80a9

Browse files
authored
Merge pull request HarshCasper#314 from sharur7/sharur7
Sharur7
2 parents 4d2d1ea + ab58833 commit 7ca80a9

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

Python/Image_Sketch/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Image to Sketch
2+
The original image is converted into black and white sketched image.
3+
4+
### Results:
5+
6+
#### Original Image
7+
<img src ="https://github.com/sharur7/Rotten-Scripts/blob/sharur7/Python/Image_Sketch/obama.jpg?raw=true" alt="Original_image" width="280" height="300">
8+
9+
#### Sketched Image
10+
<img src ="https://github.com/sharur7/Rotten-Scripts/blob/sharur7/Python/Image_Sketch/sketch.jpg?raw=true" alt="Original_image" width="280" height="300">

Python/Image_Sketch/Sketch.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Importing Libraries
2+
import cv2
3+
import numpy as np
4+
from skimage import io
5+
6+
# Making a sketch generating function
7+
8+
def sketch(img):
9+
# Converting image into grayscale
10+
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
11+
RGB_img = cv2.cvtColor(img_gray, cv2.COLOR_BGR2RGB)
12+
13+
# Clean up image using Gausian Blur
14+
img_gray_blur = cv2.GaussianBlur(RGB_img, (5, 5), 0)
15+
16+
# Extracting edges
17+
canny_edges = cv2.Canny(img_gray_blur, 10, 70)
18+
19+
# Do an invert binarize the image
20+
ret, mask = cv2.threshold(canny_edges, 70, 255, cv2.THRESH_BINARY_INV)
21+
return mask
22+
23+
# Reading our image
24+
img = io.imread("obama.jpg")
25+
cv2.imshow('Our Sketch', sketch(img))
26+
# cv2.imwrite('sketch.jpg', sketch(img))
27+
cv2.waitKey(0)
28+
cv2.destroyAllWindows()
29+

Python/Image_Sketch/obama.jpg

190 KB
Loading

Python/Image_Sketch/sketch.jpg

250 KB
Loading

0 commit comments

Comments
 (0)