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

  • Home
  • SEARCH
  • 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 8890305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:28:16+00:00 2026-06-14T22:28:16+00:00

Say I have an image in PIL from PIL import Image Image.open(path_to_my_image) and two

  • 0

Say I have an image in PIL

from PIL import Image
Image.open(path_to_my_image)

and two lists of x points and y points

x = ['10', '30', '70']
y = ['15', '45', '90']

Is there a way to overlay my polygon with transparency on this image?

Also, is PIL a good library for this? Or should I use a different one? (e.g. scikits.image, or render in an image with pylab).

  • 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-06-14T22:28:17+00:00Added an answer on June 14, 2026 at 10:28 pm

    PIL is a fine tool for this:

    import Image
    import ImageDraw
    img = Image.open(...).convert('RGBA')
    
    x = ['10', '30', '70']
    y = ['15', '45', '90']
    
    # convert values to ints
    x = map(int, x)
    y = map(int, y)
    
    img2 = img.copy()
    draw = ImageDraw.Draw(img2)
    draw.polygon(zip(x,y), fill = "wheat")
    
    img3 = Image.blend(img, img2, 0.5)
    img3.save('/tmp/out.png')
    

    The call signature for draw.polygon is:

    def polygon(self, xy, fill=None, outline=None):
    

    so the only options are fill and outline. I looked at the source code to find this information.

    IPython told me:

    In [38]: draw.polygon?
    ...
    File:       /usr/lib/python2.7/dist-packages/PIL/ImageDraw.py
    

    which showed me where to look.


    To draw a semi-transparent polygon on top of img, make a copy of the image. One the copy, draw the polygon in full color without alpha. Then use Image.blend to combine the original image with the copy with a set level of alpha. For each pixel:

    out = image1 * (1.0 - alpha) + image2 * alpha
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say you have an image that is 200px wide. Is there a way to
Lets say I have an image or two dimensional pattern similar to QRcode and
Lets say I have an image in double that goes from range 0.0 to
Let's say i have this image: The line color is a gradient from yellow
Let's say i have an image uploader script, i want to prevent the upload
I have image and txt file of same size say 200 KB. Now i
Lets say I have a non-square image.. If I increment the width and I
Suppose I have any image(say passport type images where the background will be same
Let's say we have a memory-intensive class like an Image , with chainable methods
I'm planning to try contours on some image. Lets say I have three object

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.