Recent Posts

cartooning an image (OpenCV)

 


CODE:

     #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.ADAPTIVE_THRESH_MEAN_C, 

                                             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) 


output:





No comments

If you have any doubts, Please let me know