Python Pillow – Embossing Effect on Image

Pillow – Embossing effect on image

To apply embossing effect on an image using Pillow library, you can use Image.filter() function with ImageFilter.EMBOSS kernel.

Python Pillow - Embossing Effect on Image

Steps to emboss an image

Follow these steps to apply embossing effect on a given image.

  1. Import Image, and ImageFilter modules from Pillow library.
  2. Read input image using Image.open() function.
  3. Call filter() function on the read Image object and pass ImageFilter.EMBOSS as argument to the function. The function returns the embossed image as PIL.Image.Image object.
  4. Save the returned image to required location using Image.save() function.

Syntax of filter() function

The syntax of filter() function from PIL.Image module is

PIL.Image.filter(filter_kernel)
ParameterDescription
filter_kernelA filter kernel that applies to the given image. To apply embossing effect on this image, you can use ImageFilter.EMBOSS filter kernel.

Returns

The function returns a PIL.Image.Image object.

Examples

1. Emboss given image

In the following example, we read an image test_image.jpg, apply embossing effect on this image using Image.filter() function, and save the embossed image as embossed_image.jpg.

Python Program

from PIL import Image, ImageFilter

# Open the image
image = Image.open("test_image.jpg")

# Emboss effect on the image
embossed_image = image.filter(ImageFilter.EMBOSS)

# Save the resulting image
embossed_image.save("embossed_image.jpg")
Copy

Original Image [test_image.jpg]

Embossing Effect on Image example - input image

Resulting Image with EMBOSS filter [embossed_image.jpg]

Embossing Effect on Image example - output image

Summary

In this Python Pillow Tutorial, we learned how to apply embossing effect on a given image using PIL.Image.filter() function, with the help of examples.

Related Tutorials

Code copied to clipboard successfully 👍