Cartooning an Image using OpenCV - Python Last Updated : 11 Aug, 2025 Comments Improve Suggest changes Like Article Like Report Cartooning an image turns a normal photo into a fun, animated-style picture. With OpenCV, we do this by smoothing the image to simplify colors and detecting edges to create outlines. Combining these steps makes the photo look like a cartoon.Prerequisites: Opencv moduleApproachRead the input image.Convert the image to grayscale for edge detection.Apply median blur to remove noise.Use adaptive thresholding to detect edges.Apply a bilateral filter to smooth the image while preserving edges.Combine the smoothed image with edges to produce the cartoon effect.Python Implementation Python import cv2 img = cv2.imread("Screenshot.png") if img is None: print("Image not found") exit() # Prep grayscale & blur g = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) g = cv2.medianBlur(g, 5) # Edges e = cv2.adaptiveThreshold(g, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 9, 9) # Smooth color c = cv2.bilateralFilter(img, 9, 250, 250) # Combine cartoon = cv2.bitwise_and(c, c, mask=e) cv2.imshow("Cartoon", cartoon) cv2.imwrite("cartoon_output.jpg", cartoon) cv2.waitKey(0) cv2.destroyAllWindows() Output:Original ImageCartoon Output ImageExplanation:cv2.cvtColor() converts the image to grayscale for edge detection.cv2.medianBlur() removes noise for cleaner edges.cv2.adaptiveThreshold() detects edges, giving a sketch-like effect.cv2.bilateralFilter() smooths colors while keeping edges sharp.cv2.bitwise_and() combines smoothed colors and edges for the cartoon effect. Cartooning an Image using OpenCV – Python Comment K kartik Follow Improve K kartik Follow Improve Article Tags : GBlog Project AI-ML-DS Explore GBlog - Explore Techâs Hottest Topics & Career Growth Hacks! 2 min read How To BecomeHow to become a Java Developer? 6 min read How to Become a GenAI Developer 8 min read How to become a Cloud Network Engineer? 11 min read How to Become a DevSecOps Engineer 9 min read How to become an Automation Tester? 11 min read RoadmapFull Stack Developer Roadmap [2025 Updated] 15 min read Complete DevOps Roadmap - Beginner to Advanced 8 min read Machine Learning Roadmap 11 min read Data Analyst Roadmap 2025 - A Complete Guide 7 min read Interview PreparationInterview Preparation Roadmap 5 min read Top Interview Problems Asked in 2024 (Topic Wise) 2 min read Top HR Interview Questions and Answers (2025) 15+ min read Database Administrator Interview Questions 14 min read Aptitude Questions and Answers 3 min read Project Ideas10 Best Computer Science Projects Ideas for Final Year Students 8 min read Top 10 Mini Project Ideas For Computer Science Students 7 min read 30+ Web Development Projects with Source Code [2025] 4 min read Top 10 Data Science Project Ideas for Beginners 13 min read Java Project Ideas For Beginners and Advanced 15+ min read 10 Best Linux Project Ideas For Beginners 7 min read Top 7 Python Project Ideas for Beginners in 2025 6 min read CertificationTop Machine Learning Certifications in 2025 9 min read DevOps Certification - A Way to Enhance Growth Opportunities 4 min read Top 10 Highest Paying Certifications 11 min read Tech Certifications: Worth the Effort in 2025? 9 min read Like