The effect of blending two images is like projecting two transparent slide images onto a projector screen from two separate projectors where the amount of light from each projector is controlled by proportion setting. The command is of the form Image.blend(image_1, image_2, proportion-of-image_1)
.
Use the two images 100_canary.png
and 100_cockcrow.png
from the folder /constr/pics1
. The 100_
in the titles is a reminder that the images are 100 x 100 pixels in size and we will see the format, size, and type of each image printed onto the console.
With the two identical size and mode images in place, execute the following code.
# image_blend_1.py # >>>>>>>>>>>>>>>> import Image im_1 = Image.open("/constr/pics1/100_canary.png") # mode is RGBA im_2 = Image.open("/constr/pics1/100_cockcrow.png") # mode is RGB # Check on mode, size and format first for compatibility. print "im_1 format:", im_1.format, ";size:", im_1.size, "; mode:",im_1.mode print "im_2 format:", im_2.format, ";size:", im_2.size, "; mode:",im_2.mode im_2 = im_2.convert("RGBA") # Make both modes the same im_4 = Image.blend(im_1, im_2, 0.5) im_4.show()
From format information, we will see that the mode of the first image is RGBA
while the second is RGB
. Therefore, it is necessary to first convert the second image to RGBA
.
In this particular example, the proportion control was set to 0.5
. That is, the two images were blended together by equal amounts. If the proportion setting had been 0.2
, then 20%
of im_1
would have been combined with 80%
of im_2
.
3.133.157.142