My Brain Cells

Easiest (and best) learning materials for anyone with a curiosity for machine learning and artificial intelligence, Deep learning, Programming, and other fun life hacks.

cartooning an image (OpenCV)



     #importing libraries

    import cv2

    images_rgb = cv2.imread(“kanaki.jpg”)  #image path

    numBilateralFilters = 30  

    for _ in range(numBilateralFilters): 

        images_rgb = cv2.bilateralFilter(images_rgb, 9, 9, 7) 

    images_gray = cv2.cvtColor(images_rgb, cv2.COLOR_RGB2GRAY) #converting rgb to gray scale


    images_blur = cv2.medianBlur(images_gray, 3) 


    images_edge = cv2.adaptiveThreshold(images_blur, 255, 


                                             cv2.THRESH_BINARY, 9, 2)  #measuring threshold

    images_edge = cv2.cvtColor(images_edge, cv2.COLOR_GRAY2RGB) #converting brg to gray scale of edge detected images

    cv2.imshow(“images_rgb”, images_rgb) 

    cv2.imshow(“images_edge”, images_edge) 

    res=cv2.bitwise_and(images_rgb, images_edge) #applying bitwise comparator between colored image and sketch


    cv2.imshow(“Cartoon version”, res) 



Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top