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 8960519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:40:34+00:00 2026-06-15T15:40:34+00:00

I am using image.transform in the Python Imaging Library to apply affine transform to

  • 0

I am using image.transform in the Python Imaging Library to apply affine transform to a image of face detection to calibration the face accordding to the position of eyes. The result is right but the color of the image is changed like below. Why?
The code is following. The last two line is the call of tranform function.

def ScaleRotateTranslate(image, angle, center = None, new_center = None, scale = None, resample=Image.NEAREST):
    if (scale is None) and (center is None):
        return image.rotate(angle=angle, resample=resample)
    nx,ny = x,y = center
    sx=sy=1.0
    if new_center:
        (nx,ny) = new_center
    if scale:
        (sx,sy) = (scale, scale)
    cosine = math.cos(angle)
    sine = math.sin(angle)
    a = cosine/sx
    b = sine/sx
    c = x-nx*a-ny*b
    d = -sine/sy
    e = cosine/sy
    f = y-nx*d-ny*e
    return image.transform(image.size, Image.AFFINE, (a,b,c,d,e,f), resample=resample)

def Distance(p1,p2):
    dx = p2[0] - p1[0]
    dy = p2[1] - p1[1]
    return math.sqrt(dx*dx+dy*dy)



image_center = ((eye_left[0]+eye_right[0])/2,(eye_left[1]+eye_right[1])/2)
rotatedImg = ScaleRotateTranslate(pilIm,center=image_center,angle=rotation)

enter image description here

enter image description here

  • 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-15T15:40:36+00:00Added an answer on June 15, 2026 at 3:40 pm

    Tried this:

    import Image
    import math
    
    def ScaleRotateTranslate(image, angle, center = None, new_center = None, scale = None, resample=Image.NEAREST):
        if (scale is None) and (center is None):
            return image.rotate(angle=angle, resample=resample)
        nx,ny = x,y = center
        sx=sy=1.0
        if new_center:
            (nx,ny) = new_center
        if scale:
            (sx,sy) = (scale, scale)
        cosine = math.cos(angle)
        sine = math.sin(angle)
        a = cosine/sx
        b = sine/sx
        c = x-nx*a-ny*b
        d = -sine/sy
        e = cosine/sy
        f = y-nx*d-ny*e
        return image.transform(image.size, Image.AFFINE, (a,b,c,d,e,f), resample=resample)
    
    def Distance(p1,p2):
        dx = p2[0] - p1[0]
        dy = p2[1] - p1[1]
        return math.sqrt(dx*dx+dy*dy)
    
    
    pilIm = Image.open('/Users/carlos/Downloads/image.jpg').convert('RGB');
    eye_left = (10,10)
    eye_right = (40,30)
    rotation = 0.3;
    
    image_center = ((eye_left[0]+eye_right[0])/2,(eye_left[1]+eye_right[1])/2)
    rotatedImg = ScaleRotateTranslate(pilIm,center=image_center,angle=rotation)
    rotatedImg.save('out.jpg')
    

    Got this:

    enter image description here

    So I guess, the answer is it works for me. Try checking your installation of PIL and that you’re using RGB encoding.

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

Sidebar

Related Questions

I have a sample image: I apply the affine transform with the following warp
Using Python Image Library PIL and Google App Engine Blobstore... This: img = images.Image(blob_key=image)
Using Matlab, I have to transform the intensity of an image using this given
I'm using v2.1 with the built-in python interface. I'm trying to load an image
I want to crop an image using images library of google app engine. The
I'm looking to transform an image using a Matrix on the onDraw method of
More specifically, is it possible to scale a tiled background image using CSS3's transform:scale(x,y)
I am using this code to flip image. CGAffineTransform trans = CGAffineTransformScale(imageView.transform, -1, 1);
I am trying to transform an image using Bi-linear interpolation, my input image is
I'm moving a very long image using -webkit-transform: translate(-958px, 0); animation The image gets

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.