0 Replies - 2851 Views - Last Post: 14 October 2012 - 10:31 AM Rate Topic: -----

#1 croger   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-October 12

Morphing Images

Posted 14 October 2012 - 10:31 AM

PIL Library contains a function called blend:

Image.blend(image1, image2, alpha)
Returns: Imagethat creates a new image by morphing image1 and image2, using a constant alpha.

outImage = image1 * (1.0 - alpha) + image2 * alpha
If alpha is 0.0, a copy of the first image is returned. If alpha is 1.0, a copy of the second image is returned. There are no restrictions on the alpha value. If necessary, the result is clipped to fit into the allowed output range.

Note: Both images must have the same size.

In this task, you will create a function called morphPicture that has two arguments representing the file names of image1 and image2. Your function will use a for loop to call Image.blend with the following alpha values: 0, 1/10, 2/10, … 1. Your function then saves and displays the result image for each alpha.

The name of the files created by your function must have the following format: “morph”+str(k)+”.gif”. Note that (k) means the value of the variable that controls the for loop.

Here is my code so far. I keep getting an erro message that says, 'str' object has no attribute 'load'. Can someone please lead me in the righ direction.
def morphPicture(image1,image2):
    myImage=Image. open(image1)
    myImage2=Image. open(image2)


    for k in range(len(alpha)):
        if myImage.size==myImage2.size:


This post has been edited by atraub: 14 October 2012 - 03:02 PM
Reason for edit:: added code tags

Is This A Good Question/Topic? 0
  • +

Page 1 of 1