Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 539755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:10:10+00:00 2026-05-13T10:10:10+00:00

I am trying to emboss an image using PIL . PIL provides a basic

  • 0

I am trying to emboss an image using PIL.

PIL provides a basic way to emboss an image ( using ImageFilter.EMBOSS).

In image editing packages like GIMP, you can vary parameters like Azimuth, depth and elevation in this embossed image.

How to do this with PIL? At the very least I want to adjust the “depth” of the embossed image.

Update: I tried things suggested by Paul (modifying the filterargssuch as scale, offset and the matrix), but I couldn’t change the “depth” effect. So still looking for an answer.

Here is the comparison of embossing effect using PIL (left) and GIMP (right). The original picture is located here, http://www.linuxtopia.org/online_books/graphics_tools/gimp_advanced_guide/gimp_guide_node74.html.

alt text

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:10:10+00:00Added an answer on May 13, 2026 at 10:10 am

    If you cannot achieve your goal by using or combination of operations (like rotating, then applying the EMBOSS filter, the re-rotating), (or enhancing the contrast then embossing) then you may resort to changing (or creating your own) filter matrix.

    Within ImageFilter.py you will find this class:

    ##
    # Embossing filter.
    
    class EMBOSS(BuiltinFilter):
        name = "Emboss"
        filterargs = (3, 3), 1, 128, (
            -1,  0,  0,
            0,  1,  0,
            0,  0,  0
            )
    

    Placing a -1 in a different corner of the matrix will change the azimuth and making it a -2 may have the effect you are looking for.

    The matrix is applied pixel-by-pixel. Each element in the matrix corresponds to the current pixel and surrounding pixels; the center value representing the current pixel. The new, transformed current pixel will be created as a combination of all 9 pixels, weighted by the values in the matrix. For example, a matrix with all zeros and a 1 in the center will not change the image.

    Additional parameters are scale and offset. For the built-in EMBOSS, the values are 1 (scale) and 128 (offset). Changing these will change the overall strength of the result.

    From ImageFilter.py:

    # @keyparam scale Scale factor.  If given, the result for each
    #    pixel is divided by this value.  The default is the sum
    #    of the kernel weights.
    # @keyparam offset Offset.  If given, this value is added to the
    #    result, after it has been divided by the scale factor.
    

    As I am unfamiliar with the effects of GIMP’s “depth” parameter, I cannot say which is most likely to do what you want.

    You can also make the matrix a different size. Replace the (3,3) with (5,5), and then create 25-element matrix.

    To make temporary changes to the filter without re-saving source code, just do this:

    ImageFilter.EMBOSS.filterargs=((3, 3), 1, 128, (-1, 0, 0, 0, 1, 0, 0, 0, 0))
    

    Edit: (taking the NumPy approach)

    from PIL import Image
    import numpy
    
    # defining azimuth, elevation, and depth
    ele = numpy.pi/2.2 # radians
    azi = numpy.pi/4.  # radians
    dep = 10.          # (0-100)
    
    # get a B&W version of the image
    img = Image.open('daisy.jpg').convert('L') 
    # get an array
    a = numpy.asarray(img).astype('float')
    # find the gradient
    grad = numpy.gradient(a)
    # (it is two arrays: grad_x and grad_y)
    grad_x, grad_y = grad
    # getting the unit incident ray
    gd = numpy.cos(ele) # length of projection of ray on ground plane
    dx = gd*numpy.cos(azi)
    dy = gd*numpy.sin(azi)
    dz = numpy.sin(ele)
    # adjusting the gradient by the "depth" factor
    # (I think this is how GIMP defines it)
    grad_x = grad_x*dep/100.
    grad_y = grad_y*dep/100.
    # finding the unit normal vectors for the image
    leng = numpy.sqrt(grad_x**2 + grad_y**2 + 1.)
    uni_x = grad_x/leng
    uni_y = grad_y/leng
    uni_z = 1./leng
    # take the dot product
    a2 = 255*(dx*uni_x + dy*uni_y + dz*uni_z)
    # avoid overflow
    a2 = a2.clip(0,255)
    # you must convert back to uint8 /before/ converting to an image
    img2 = Image.fromarray(a2.astype('uint8')) 
    img2.save('daisy2.png')
    

    I hope this helps. I can see now why you were disappointed with PIL’s results. Wolfram Mathworld is a good resource for a vector algebra refresher.

    Before

    alt text

    After

    alt text

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 269k
  • Answers 269k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Another way to ask this question would be to ask,… May 13, 2026 at 1:19 pm
  • Editorial Team
    Editorial Team added an answer objectForKey returns a reference, not an integer. I believe that… May 13, 2026 at 1:19 pm
  • Editorial Team
    Editorial Team added an answer Where is environment variable PYTHONPATH defined in your working environment?… May 13, 2026 at 1:19 pm

Related Questions

I am trying to set a javascript date so that it can be submitted
I am trying to grab the capital letters of a couple of words and
I am trying to set a flag to show or hide a page element,
I am trying to generate a report by querying 2 databases (Sybase) in classic
I am trying to do some string concatenation/formatting, but it's putting all the parameters

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.