[Python] Pillow (PIL) affine image transform wrong direction

Discussão em 'Python' iniciado por Stack, Agosto 18, 2025.

  1. Stack

    Stack Membro Participativo

    Using Python's Pillow (PIL) module I'm trying to shift an image 85 pixels to the right using an affine transform. The below code should to this, but instead shifts the image seemingly in the wrong direction to the left. Am I misunderstanding something?

    from PIL import Image
    test_image = Image.open('Test image.png')
    affine_params = [1, 0, 85, 0, 1, 0]
    trans_image = test_image.transform(test_image.size, Image.AFFINE, affine_params, Image.BILINEAR, fillcolor = (150,150,150))
    trans_image.save('Transformed image.png')


    Input image: [​IMG]

    Output image: [​IMG]

    The documentation isn't all in one place, but this says given affine_params = [a, b, c, d, e, f] a pixel's new position is x_new, y_new = (a*x_old + b*y_old + c, d*x_old + e*y_old + f) so a positive value for c ?should? give a shift the right?

    Continue reading...

Compartilhe esta Página