These are the instructions that I am to go by:
PIL Library contains a function called blend:
Image.blend(image1, image2, alpha)
Returns: Image
that 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.
So far this is what I think it is asking for but not sure if I am going in the right direction:
def morphPicture(filename,filename1):
myImage = Image.open(filename)
myImage1 = Image.open(filename1)
myImage.show()
myImage1.show()
for k in range(alpha)
Image.blend(filename, filename1, alpha)
outImage = filename * (1.0 - alpha) + filename1 * alpha
newfilename = filename[:-4]
newfilename = "morph"+str(k)+".gif"
myImage.save(newfilename)
newImage = Image.open(newfilename)
newImage.show()

New Topic/Question
Reply



MultiQuote




|