def blendimages(file1,file2): img1 = makePicture(file1) img2 = makePicture(file2) compw = getWidth(img1) + getWidth(img2) - 100 # composite width comph = max(getHeight(img1),getHeight(img2)) # composite height composite = makeEmptyPicture(compw,comph) # composite picture for x in range(0,getWidth(img1) - 100): # copy most of left image for y in range(0, getHeight(img1)): color = getColor(getPixel(img1,x,y)) setColor(getPixel(composite,x,y),color) for x in range(100,getWidth(img2)): # copy most of right image for y in range(0, getHeight(img2)): color = getColor(getPixel(img2,x,y)) setColor(getPixel(composite,x + getWidth(img1) - 100,y),color) for x in range(0, 100): # handle overlapping region for y in range(0, min(getHeight(img1),getHeight(img2))): # min() ensures that the blend extends only to the smaller image pixel1 = getPixel(img1,x + getWidth(img1) - 100,y) pixel2 = getPixel(img2,x,y) newred = 0.50 * getRed(pixel1) + 0.50 * getRed(pixel2) newgreen = 0.50 * getGreen(pixel1) + 0.50 * getGreen(pixel2) newblue = 0.50 * getBlue(pixel1) + 0.50 * getBlue(pixel2) color = makeColor(newred,newgreen,newblue) setColor(getPixel(composite,x + getWidth(img1) - 100,y),color) return compositeThis results in the following image:
To improve this, you are asked to blend the two source images with varying weights, i.e. weights that vary over the region of overlap. In particular, at the left boundary of the overlap region, the left image should have 100% weight, whereas the right image should have 0%. Conversely, at the right boundary of the overlap region, the left image should have 0% weight, whereas the right image should have 100%. In between the weights should vary linearly.
One simple way to generate these varying weights is to compute a gradient, see e.g. the greyscale gradient example in section 5.5. Your task for this lab is to modify this function so that it arranges the two images side by side, where the size of the overlap is specified as an argument to the function. The overlapping area must be blended, as in the second image. The function must be named blendimages(file1,file2,overlap). The arguments are the name of the first and second image file, respectively, and the overlap area in pixels. The function must return a composite image that contains the blended result.
>>> print 3 / 2 1 >>> print float(3) / 2 1.5
submit 1710 lab05 lab05.py
Note: You must do all the above steps correctly for receiving full credit for this lab.