Skip to content
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

Regression from 9.0.1 to 9.1.0 in polygon rasterization #6290

Closed
rockandsalt opened this issue May 13, 2022 · 7 comments · Fixed by #6303
Closed

Regression from 9.0.1 to 9.1.0 in polygon rasterization #6290

rockandsalt opened this issue May 13, 2022 · 7 comments · Fixed by #6303

Comments

@rockandsalt
Copy link

What did you do?

@mikedh and I noticed that the polygon rasterization wasn't clean in certain case. The regression seems to have occured in 9.1.0 since version before that one works fine. @mikedh made a comment here

image

What are your OS, Python and Pillow versions?

  • OS: Windows
  • Python: 3.8
  • Pillow: 9.1.0

Here's the minimum code to reproduce it.

from PIL import Image, ImageDraw

if __name__ == '__main__':
    curve = [270, 114, 269, 114, 269, 114, 268, 115, 268, 115, 267, 116, 267, 116, 266, 117, 266, 117, 265, 117, 265, 117, 264, 118, 264, 118, 263, 119, 263, 119, 262, 119, 262, 119, 261, 120, 261, 120, 260, 121, 260, 121, 259, 121, 259, 121, 258, 122, 258, 122, 257, 123, 257, 123, 256, 123, 256, 123, 255, 124, 255, 124, 254, 125, 254, 125, 253, 125, 253, 125, 252, 126, 252, 126, 251, 126, 251, 126, 250, 127, 250, 127, 249, 128, 249, 128, 248, 128, 247, 128, 246, 129, 246, 129, 245, 129, 245, 129, 244, 130, 244, 130, 243, 130, 243, 130, 242, 131, 242, 131, 241, 131, 241, 131, 240, 132, 240, 132, 239, 132, 239, 132, 238, 133, 238, 133, 237, 133, 237, 133, 235, 134, 235, 134, 234, 134, 234, 134, 233, 135, 233, 135, 232, 135, 232, 135, 231, 136, 231, 136, 230, 136, 230, 136, 229, 136, 229, 136, 228, 137, 228, 137, 226, 137, 226, 137, 225, 137, 225, 137, 224, 138, 224, 138, 223, 138, 223, 138, 222, 139, 222, 139, 221, 139, 221, 139, 219, 139, 219, 139, 218, 139, 218, 139, 217, 140, 217, 140, 216, 140, 216, 140, 215, 140, 215, 140, 214, 141, 213, 141, 212, 141, 212, 141, 211, 141, 211, 141, 210, 141, 210, 141, 209, 142, 209, 142, 208, 142, 207, 142, 206, 142, 206, 142, 205, 142, 205, 142, 204, 142, 204, 142, 203, 143, 203, 143, 201, 143, 201, 143, 200, 143, 200, 143, 199, 143, 199, 143, 198, 143, 198, 143, 197, 143, 197, 143, 195, 143, 195, 143, 194, 143, 194, 143, 193, 144, 193, 144, 192, 144, 192, 144, 190, 144, 190, 144, 189, 144, 189, 144, 188, 144, 188, 144, 187, 144, 187, 144, 186, 144, 186, 144, 184, 144, 184, 144, 183, 144, 183, 144, 182, 144, 182, 144, 181, 144, 181, 144, 179, 144, 179, 144, 178, 144, 178, 144, 177, 144, 177, 144, 176, 144, 176, 144, 174, 143, 174, 143, 174, 143, 174, 143, 173, 143, 173, 143, 171, 143, 171, 143, 168, 143, 168, 143, 163, 143, 163, 142, 153, 142, 144, 141, 143, 141, 134, 140, 133, 140, 132, 140, 113, 138, 111, 138, 92, 136, 89, 136, 71, 134, 68, 134, 50, 133, 50, 133, 40, 132, 39, 132, 29, 131, 29, 131, 19, 130, 11, 129, 11, 129, 11, 129, 11, 129, 10, 129, 10, 129, 9, 129, 9, 129, 8, 129, 8, 129, 8, 129, 7, 128, 7, 128, 6, 128, 6, 128, 6, 128, 5, 127, 5, 127, 5, 127, 4, 127, 4, 127, 4, 126, 4, 126, 3, 126, 3, 125, 3, 125, 2, 125, 2, 124, 2, 124, 2, 124, 2, 123, 1, 123, 1, 123, 1, 123, 1, 122, 1, 122, 1, 121, 1, 121, 0, 120, 0, 120, 0, 120, 0, 120, 0, 120, 0, 119, 0, 119, 0, 118, 0, 118, 0, 117, 0, 117, 0, 114, 0, 72, 0, 70, 0, 27, 0, 27, 0, 26, 0, 26, 0, 25, 0, 25, 0, 24, 0, 24, 0, 24, 0, 23, 0, 23, 1, 23, 1, 22, 1, 22, 1, 22, 1, 21, 1, 21, 2, 20, 2, 20, 2, 20, 2, 19, 2, 19, 3, 19, 3, 18, 3, 18, 4, 18, 4, 17, 4, 17, 5, 17, 5, 17, 5, 17, 5, 16, 6, 16, 6, 16, 7, 16, 7, 16, 7, 15, 8, 15, 8, 15, 8, 15, 9, 15, 9, 15, 9, 15, 10, 15, 10, 15, 11, 15, 11, 15, 11, 15, 11, 15, 19, 14, 20, 14, 29, 13, 30, 13, 40, 12, 41, 12, 50, 11, 53, 11, 71, 9, 89, 8, 92, 8, 93, 7, 112, 6, 114, 6, 133, 4, 142, 3, 143, 3, 153, 2, 153, 2, 154, 2, 163, 1, 168, 1, 168, 1, 171, 1, 171, 1, 173, 0, 173, 0, 174, 0, 174, 0, 176, 0, 176, 0, 177, 0, 177, 0, 178, 0, 178, 0, 179, 0, 179, 0, 180, 0, 181, 0, 182, 0, 182, 0, 183, 0, 183, 0, 184, 0, 184, 0, 185, 0, 185, 0, 187, 0, 187, 0, 188, 0, 188, 0, 189, 0, 189, 0, 190, 0, 190, 0, 192, 0, 192, 0, 193, 0, 193, 0, 194, 0, 194, 0, 195, 0, 195, 0, 196, 1, 196, 1, 198, 1, 198, 1, 199, 1, 199, 1, 200, 1, 200, 1, 201, 1, 201, 1, 203, 1, 203, 1, 204, 1, 204, 1, 205, 2, 205, 2, 206, 2, 206, 2, 207, 2, 207, 2, 209, 2, 209, 2, 210, 2, 210, 2, 211, 3, 211, 3, 212, 3, 212, 3, 213, 3, 213, 3, 214, 3, 215, 3, 216, 4, 216, 4, 217, 4, 217, 4, 218, 4, 218, 4, 219, 5, 219, 5, 220, 5, 220, 5, 222, 5, 222, 5, 223, 6, 223, 6, 224, 6, 224, 6, 225, 6, 225, 6, 226, 7, 226, 7, 227, 7, 227, 7, 228, 7, 229, 7, 230, 8, 230, 8, 231, 8, 231, 8, 232, 9, 232, 9, 233, 9, 233, 9, 234, 10, 234, 10, 235, 10, 235, 10, 236, 10, 236, 10, 238, 11, 238, 11, 239, 11, 239, 11, 240, 12, 240, 12, 241, 12, 241, 12, 242, 13, 242, 13, 243, 13, 243, 13, 244, 14, 244, 14, 245, 14, 245, 15, 246, 15, 246, 15, 247, 16, 247, 16, 248, 16, 248, 16, 249, 17, 249, 17, 251, 17, 251, 17, 252, 18, 252, 18, 253, 19, 253, 19, 254, 19, 254, 19, 255, 20, 255, 20, 256, 20, 256, 20, 257, 21, 257, 21, 258, 22, 258, 22, 259, 22, 259, 22, 260, 23, 260, 23, 261, 24, 261, 24, 262, 24, 262, 24, 263, 25, 263, 25, 264, 26, 264, 26, 265, 26, 265, 26, 266, 27, 266, 27, 267, 28, 267, 28, 268, 29, 268, 29, 268, 29, 269, 29, 269, 30, 269, 30, 270, 31, 270, 31, 271, 32, 271, 32, 272, 32, 272, 32, 273, 33, 273, 33, 274, 34, 274, 34, 275, 35, 275, 35, 276, 36, 276, 36, 277, 36, 277, 37, 278, 37, 278, 37, 278, 38, 278, 38, 279, 39, 279, 39, 280, 40, 280, 40, 281, 41, 281, 41, 282, 42, 282, 42, 283, 42, 283, 42, 283, 43, 284, 43, 284, 44, 284, 44, 285, 45, 285, 45, 286, 46, 286, 46, 287, 47, 287, 47, 287, 48, 288, 48, 288, 49, 288, 49, 289, 50, 289, 50, 290, 51, 290, 51, 291, 52, 291, 52, 291, 53, 291, 53, 292, 53, 292, 54, 293, 54, 293, 54, 293, 55, 293, 55, 294, 56, 294, 56, 295, 57, 295, 57, 296, 58, 296, 58, 296, 59, 296, 59, 297, 60, 297, 60, 298, 61, 298, 61, 298, 62, 298, 62, 299, 63, 299, 63, 299, 64, 300, 65, 300, 66, 300, 66, 301, 67, 301, 67, 301, 67, 301, 67, 301, 67, 301, 67, 301, 67, 301, 68, 301, 68, 301, 68, 302, 68, 302, 68, 302, 69, 302, 69, 302, 69, 302, 70, 302, 70, 302, 70, 302, 70, 302, 71, 302, 71, 302, 71, 302, 71, 302, 72, 302, 72, 302, 72, 302, 72, 302, 73, 302, 73, 302, 73, 302, 73, 302, 74, 302, 74, 302, 74, 302, 74, 302, 75, 302, 75, 302, 75, 302, 75, 302, 75, 302, 76, 302, 76, 301, 76, 301, 77, 301, 77, 301, 77, 301, 77, 301, 77, 300, 78, 300, 78, 300, 79, 300, 79, 299, 80, 299, 80, 298, 81, 298, 81, 298, 82, 298, 82, 297, 83, 297, 83, 296, 84, 296, 84, 296, 85, 296, 85, 295, 86, 295, 86, 294, 87, 294, 87, 294, 88, 294, 88, 293, 89, 293, 89, 292, 90, 292, 90, 291, 91, 291, 91, 291, 92, 291, 92, 290, 93, 290, 93, 289, 94, 289, 94, 288, 95, 288, 95, 288, 96, 288, 96, 287, 97, 287, 97, 286, 98, 286, 98, 285, 99, 285, 99, 284, 99, 284, 99, 284, 100, 284, 100, 283, 101, 283, 101, 282, 102, 282, 102, 281, 103, 281, 103, 280, 104, 280, 104, 279, 105, 279, 105, 279, 106, 279, 106, 278, 106, 278, 106, 277, 107, 277, 107, 276, 108, 276, 108, 275, 109, 275, 109, 274, 110, 274, 110, 273, 110, 273, 110, 272, 111, 272, 111, 271, 112, 271, 112, 271, 113, 271, 113, 270, 114, 270, 114]

    result = Image.new(mode='1', size=[400,400])
    draw = ImageDraw.Draw(result)
    draw.polygon(curve, fill=1)
    result.save('scanline_defect.png')
@radarhere
Copy link
Member

Is it possible to get an example with a smaller number of co-ordinates?

@rockandsalt
Copy link
Author

Sure, I can try

@radarhere
Copy link
Member

I've managed to reduce curve down to this - [(67, 66), (66, 67), (18, 67), (18, 40), (93, 40)]. That is sufficient to demonstrate a dent in the polygon.

@radarhere
Copy link
Member

I've created PR #6303 to resolve this.

@mikedh
Copy link

mikedh commented May 27, 2022

Awesome thanks! Fixes mikedh/trimesh#1569

@opeide
Copy link

opeide commented Dec 1, 2022

In which version is this fix included?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants