<jupyter_start><jupyter_text>Image Cartoonification  Importing required modules--> OpenCV --> Matplotlib for showing the image in notebook itself<jupyter_code>import cv2
import matplotlib.pyplot as plt
# number of bilateral filtering steps
num_bilateral = 7 
# reading image
img_rgb = cv2.imread("harry.jpeg")
img_color = img_rgb
#cv2 works with images in BGR format, so coverting it to RGB format which is used by matplotlib
#showing the input image
plt.imshow(cv2.cvtColor(img_color, cv2.COLOR_BGR2RGB))
plt.show()
# repeatedly apply small bilateral filter instead of
# applying one large filter
for _ in range(num_bilateral):
    img_color = cv2.bilateralFilter(img_color, d=9, sigmaColor=9, sigmaSpace=7)
#Use median filter to reduce noise
# convert to grayscale and apply median blur
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2GRAY)
img_blur = cv2.medianBlur(img_gray, 7)
#Use adaptive thresholding to create an edge mask
# detect and enhance edges
img_edge = cv2.adaptiveThreshold(img_blur, 255,
   cv2.ADAPTIVE_THRESH_MEAN_C,
   cv2.THRESH_BINARY,
   blockSize=9,
   C=2)
# Combine color image with edge mask & display picture
# convert back to color, bit-AND with color image
img_edge = cv2.cvtColor(img_edge, cv2.COLOR_GRAY2RGB)
img_cartoon = cv2.bitwise_and(img_color, img_edge, mask = None)
#cv2 works with images in BGR format, so coverting it to RGB format which is used by matplotlib
plt.imshow(cv2.cvtColor(img_cartoon, cv2.COLOR_BGR2RGB))
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07738492328218813, 'fraction_numerical': 0.02134756504336224, 'mean_word_length': 5.696428571428571, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '131886', 'license': 'MIT', 'n_tokens_mistral': 538, 'n_tokens_neox': 514, 'n_words': 159, 'path': 'Image_Cartoonification/Image_cartoonification.ipynb', 'repo_name': 'Jaideep07/Image-Processing-OpenCV', 'size': '1499'}