-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong width when creating arbitrary polygon #7104
Comments
So, this is the shape that your code draws. If I insert print([tuple(v) for v in path.vertices]) I get
You are drawing a polygon with If I change draw.polygon([tuple(v) for v in path.vertices], outline=color)
image = Image.new('RGB', (height + 4, width + 4), color=(0, 0, 0))
image.paste(canvas, (2, 2))
for (x, y) in [tuple(v) for v in path.vertices]:
image.putpixel((int(x+2), int(y+2)), (0, 255, 0)) Pillow is drawing a polygon connecting all of those pixels, and joining them to make a shape. Thus, it is including the vertices, and instead drawing a shape that is 37 pixels across. For a simpler example, drawing a filled polygon from |
Ah I see. I in order to get the desired result I must subtract one unit length from vertices that define the right/bottom sides (or top/left), right? |
One pixel, yes. |
Great, thanks for the help! I am closing this now. |
What did you do?
I am trying to create a dataset containing Pentomino shapes for some experiment.
To define the shapes, I specify the vertices in the path. Since the shapes are composed of 5 squares in different configurations, distance between the corners must be uniform. In this case I have made each side be 2 units.
I plot them using Pillow, optinally performing some transformation of the input using Matplotlib's Affine2D functionality.
What did you expect to happen?
I expected the sides to be all of equal length.
What actually happened?
Pillow (or matplotlib) seems to add a couple of pixels to some sides and this creates a misalignment in the shape. This misalignment is magnified when performing transformations such as scaling (see example).
As an example, notice the right 'arm' in the 'R' shape used in the example or the dip in the 'U' (currently commented out in the example code).
I have tried manipulating the points ever so slightly but they never land in the right location. At first I thought I was going crazy because of how subtle it is, but for what I need to do, this slight variation is not ideal.
I have seen similar issues (367 and 3747), but they seemed to be solved...
What are your OS, Python and Pillow versions?
The text was updated successfully, but these errors were encountered: