IMAGE WARPING and MOSAICING

CS194-26 Proj 6A (Project Web Page) : Depth Refocusing and Aperture Adjustment with Light Field Data

Project Overview

In this project we implemented image warping and mosaicing. We basically take two or more photographs and create and image mosaic by taking a specific affine transformation of each image so that they are perfectly lined up on top of each other.

Part 1: Shoot and Digitize Pictures

I took a bunch of pictures and digitized them. Check them out.

Pictures Used For Merging

Face and sidewalk - 0
Face and sidewalk - 1
Living Room - 0
Living Room - 1
Living Room - 2
girish_room - 0
girish_room - 1
dennis_room - 0
dennis_room - 1

Pictures Used For Rectification

Homework - (for rectification)
Laptop Screen - (for rectification)

Code Usage

      
  usage: main.py [-h] [-d DATA_DIR] [-f1 FILE_NUM_1] [-f2 FILE_NUM_2] [-n NUM] [-l LANDSCAPE]
        [{clean_iphone_data,multi_annotate,multi_merge,multi_view_corr,rectify,get_correspondence,get_direct_correspondence,view_correspondence,get_homography,test}]

  positional arguments:
    {clean_iphone_data,multi_annotate,multi_merge,multi_view_corr,rectify,get_correspondence,get_direct_correspondence,view_correspondence,get_homography,test}

  optional arguments:
    -h, --help            show this help message and exit
    -d DATA_DIR, --data_dir DATA_DIR
    -f1 FILE_NUM_1, --file_num_1 FILE_NUM_1
    -f2 FILE_NUM_2, --file_num_2 FILE_NUM_2
    -n NUM, --num NUM
    -l LANDSCAPE, --landscape LANDSCAPE
      
      The output is 'output/{file_name}.png'

    Merging Images:
      1. Load images to merge in iphone_data/{data_dir}
      2. python main.py clean_iphone_data -d {data_dir} -l {landscape?}
      3. Annotate each image to the points you want to match
        python main.py multi_annotate -d {data_dir} -n {number of images}
      4. Check if the correspondences were set accurately
        python main.py multi_view_corr -d {data_dir} -n {number of images}
      5. python main.py multi_merge -d {data_dir} -n {number of images}

    Image Rectification:
      1. Load image to rectify in iphone_data/{data_dir}
      2. python main.py clean_iphone_data -d {data_dir} -l {landscape?}
      3. Annotate each image to the points you want to match
        python main.py multi_annotate -d {data_dir} -n 1
      4. Check if the correspondences were set accurately
        python main.py multi_view_corr -d {data_dir} -n 1
      5. python main.py rectify -d {data_dir} -n 1

    

Part 2: Recover Homographies

The point of this section is to recover the use the annotated points on our base image we're using as a reference and the annotated points on the extra images that we're going to transform onto the base image. In my images, I used the first one 0.jpeg in each series as the base image.

Here's the calculation for the homography. This paper below with the calcualations is actually a rectified image! Check it out before but look at the math below

The homography math: - 0

For each point mapping (x1, y1) and (x2, y2) we can get two equations to solve for the 8 variables in the homography transformation.

Part 3: Warp the Images

Once we get the mapping from the base image of annotated points to the corresponding points on image we're trying to transform onto the base image, we can complete the transformation and put the images to transform into the source image.

First thing I had to do is check that the homography works so I wrote a test function that can be run as follows: python -i main.py test -d {data_dir} -f1 0 -f2 1

Homography applied with rotation matrices

I used the homography to transform my face into the sidewalk. Check it out

Annotate the points to map my face to the sidewalk
Homography applied with rotation matrices
Final image

Part 4: Image Rectification

This is the same as the previous homography calculations except we're mapping the area we're trying to rectify to the four corners of the final image.

This is the same image I used to show the homography calculations!
Original Image
Annotated Original
Final image
My laptop screen
Original Image
Annotated Original
Final image

Part 5: Blend the images into a mosaic

I detailed above the code to run so that we can create a mosaic. Here are a few examples.

My roommate Dennis's Room
Original Image 0
Original Image 1
Final merged image
Our living room
Original Image 0
Original Image 1
Original Image 2
Final merged image
My room
Original Image 0
Original Image 1
Final merged image

Part 5: Tell Us What You've Learned

This was an interesting project. The coolest part was being able use homography to rectify images that were in a weird orientation. It was cool to be able to generalize the homography so that we could line up multiple images side by side.