Blending Two Images using Affine Combinations

This section explores implementing the gradual change of one image to another using affine combinations. Part of the implementation also explored the difference between adding lists in standard Python versus adding lists in Numpy. This essentially resulted in the matrix like structure of the resulting image. (ADD OVERLEAF THEORY PIC on affine combinations )

Process

    1. Read in both images with PIL, then convert to a numpy array
    2. Find the dimensions of both images
    3. Convert both image matrices into square matrices, where n is the minimum dimension found
    - note: the minimum,n,out of m1,m2,n1,n2 is used as the images need to be the same size for the following processs to work properly. Using the minumum dimension implies removing unneeded rows and columns from larger images rather than adding blank ones to smaller ones.
    4. Assign an increment variable which will determine how many visible, gradual transitions there will be from one image to the next.
    5. Create an array of affine touples (a1,a2)...(a1_inc+1,a2_inc+1) where inc is the number of increments specified
    - note: if the number of increments chosen is 3, then our array will be [(1,0),(2/3,1/3),(1/3,2/3),(0,1)]
    6. Iterate through the array of affine touples, multiplying the first image by a1 and the second image by a2. Then create an array of the results achieved ( the array will have (increments + 1) images inside all of the type np.ndarray )
    7. Next convert each image inside step 6 into a list and concatinate in order to create the column like effect in the result
    8. Append the result to itself (inc) times to get more columns in our result
    9. Scale the image in order to read it into plt.imsave properly
    10. The process is now complete!

3 and 5 Increments

10 Increments

Tools Used

  • Python
  • Numpy
  • PIL.Image