Wednesday, July 3, 2024
HomeLanguagesPythonWand – sketch() function in Python

Wand – sketch() function in Python

Sketch is another artistic special effect present in Wand library in python. sketch() function generates a pencil sketched image in output.For best results, radius value should be larger than sigma.
 

Syntax :

Python3




wand.image.sketch( radius, sigma, angle)
# radius should always be greater than sigma(standard deviation)


Parameter : 
 

Parameter Input Type Description
radius numbers.Real Size of Gaussian aperture.
sigma numbers.Real standard deviation of the Gaussian operator.
angle numbers.Real direction of blur.

 

Source Image: 
 

Example #1: 
 

Python3




# import display() to show final image
from wand.display import display
 
# import Image from wand.image module
from wand.image import Image
 
# read file using Image function
with Image(filename ="koala.jpeg") as img:
 
    # generate pencil sketch image using sketch() function
    img.sketch(0.5, 0.0, 98.0)
 
    # save final image
    img.save(filename ="rb_koala.jpeg")
 
    # display final image
    display(img)


Output : 
 

 
Example #2: To get the best result transform image to grayscale image 
 

Python3




# import display() to show final image
from wand.display import display
 
# import Image from wand.image module
from wand.image import Image
 
# read file using Image function
with Image(filename ="koala.jpeg") as img:
 
    # transform to grayscale image
    img.transform_colorspace("gray")
 
    # generate pencil sketch image using sketch() function
    img.sketch(0.5, 0.0, 98.0)
 
    # save final image
    img.save(filename ="rb_koala.jpeg")
 
    # display final image
    display(img)


Output : 
 

 

Ted Musemwa
As a software developer I’m interested in the intersection of computational thinking and design thinking when solving human problems. As a professional I am guided by the principles of experiential learning; experience, reflect, conceptualise and experiment.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments