Skip to main content

Use Python to Convert any image to cartoon!

 Welcome back to the blog! In this blog we are going to see how you can convert any picture into a cartoon using python programming language.




Here is the program!

--------------------------------------------------------------------------------------------------------------------------

#we will first import the required libraries

import cv2

import numpy as np

#reading the image

img=cv2.imread("code.jpg") #add the path of the image you want to convert or if the image is in the same folder write the name of the image with the correct extension


#working on edges

gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

gray=cv2.medianBlur(gray,5)

edges=cv2.adaptiveThreshold(gray,255,

      cv2.ADAPTIVE_THRESH_MEAN_C,

      cv2.THRESH_BINARY,9,9)


#Here it is cartoonization

color=cv2.bilateralFilter(img,9,250,250)

cartoon=cv2.bitwise_and(color,color,mask=edges)


cv2.imshow("Image",img)

cv2.imshow("Edges",edges)

cv2.imshow("Cartoon",cartoon)

cv2.waitkey(0)

cv2.destroyAllWindows()

--------------------------------------------------------------------------------------------------------------------------

Try to run the code, in case of queries or suggestions please tell in the comments section below or kindly email.

Thank you.


Comments

Popular posts from this blog

Drawing a star with stamp of turtle in python!

  Here is the code for the same: import   turtle star = turtle . Turtle () star. color ( "pink" ) star. shape ( "turtle" ) wn = turtle . Screen () wn. bgcolor ( "black" ) for  i  in   range ( 100 ):     star. forward ( 200 + 20 * i)     star. stamp ()     star. right ( 144 ) turtle . speed ( 9 ) turtle .done() Output of the above code: 

Introduction to Artificial Intelligence

WHAT  IS  ARTIFICIAL  INTELLIGENCE? Artificial Intelligence                  Concept of AI goes back to the classical ages. Under greek   mythology , the concept of machines and mechanical men were well thought off. In 1950, “ALAS TURING”, published landmark paper “Computing Machinery and Intelligence”, proposes “Imitation Game”, known as the famous “TURING TEST” He speculated about the possibility of creating machines that think. Unfortunately, until this date we haven’t found a machine that has fully cleared the Turin Test. Followed by this was the era of 1951, in which MARVIN MINSKY and DEAN EDMUNDS built the first   artificial neural network using 3000 vacuum tubes stimulating 40 neurons. Next in 1952,   ARTHUR SAMUEL, wrote the first machine learning program(Game AI) for checkers. In 1956, there was the birth of AI. JOHN Mc CARTHY, first coined the term “A...

Know the current Covid status of your country using Python!

 We all are aware about COVID-19, i.e. coronavirus infectious disease 2019.  Isn't it fascinating, using python for numerous purpose! So, here is the python program that can help you know the status of COVID-19 of your country. -------------------------------------------------------------------------------------------------------------------------- For this you need to install one package using the pip command. pip install covid -------------------------------------------------------------------------------------------------------------------------- from covid import Covid covid=Covid() cases=covid.get_status_by_country_name("India") #enter the name of the country you want to know the status for x in cases:     print(x,":",cases[x]) -------------------------------------------------------------------------------------------------------------------------- Output of the above program, giving current status is: id : 80 country : India confirmed : 9857029 active : 35...