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)
image1.load()
image2.load()
alpha=[0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1]
for k in range(len(alpha)):
if myImage.size==myImage2.size:
value=alpha[k]
Image.blend(image1,image2,value)
outImage=image1*(1.0-value)+image2*value
outImage.show()
file=outImage[:-4]
file="morph"+str(k)+".gif"
This post has been edited by atraub: 14 October 2012 - 03:02 PM
Reason for edit:: added code tags

New Topic/Question
Reply



MultiQuote


|