Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Added Cartoonify Image Code #220

Merged
merged 8 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Image-Processing/Cartoonify Image/Cartoonify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Importing Libraries
import cv2
import numpy as np
from skimage import io


# Class Defination
class Cartoon:
def __init__(self):
img = io.imread("images/sunset.jpg")
# 1) Edges Image
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = cv2.medianBlur(gray, 5)
edges = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 9, 7)

# 2) Color Image
color = cv2.bilateralFilter(img, 10, 300, 300)
RGB_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

# 3) Cartoon Image
cartoon = cv2.bitwise_and(color, color, mask=edges)
cartoon_img = cv2.cvtColor(cartoon, cv2.COLOR_BGR2RGB)

# Re-sizeing Image
resize = cv2.resize(RGB_img, (600, 450))
resize2 = cv2.resize(cartoon_img, (600, 450))
self.resize = resize
self.resize2 = resize2


# Displaying Image
# Creating an object of class Cartoon
c1 = Cartoon()
c1.resize
c1.resize2
cv2.imshow("Original_Image", c1.resize)
cv2.imshow("Cartoonified_Image", c1.resize2)
cv2.waitKey(0)
cv2.destroyAllWindows()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.