In [30]:
import numpy as np
import matplotlib.pyplot as plt
import skimage.io as io
import skimage as sk
import matplotlib.image as mpimg
In [31]:
from IPython.core.display import HTML
HTML("""
<style>

div.cell { /* Tunes the space between cells */
margin-top:1em;
margin-bottom:1em;
}

div.text_cell_render h1 { /* Main titles bigger, centered */
font-size: 2.2em;
line-height:0.9em;
}

div.text_cell_render h2 { /*  Parts names nearer from text */
margin-bottom: -0.4em;
}


div.text_cell_render { /* Customize text cells */
font-family: 'Georgia';
font-size:1.2em;
line-height:1.4em;
padding-left:3em;
padding-right:3em;
}

.output_png {
    display: table-cell;
    text-align: center;
    vertical-align: middle;
}

</style>

<script>
code_show=true; 
function code_toggle() {
 if (code_show){
 $('div.input').hide();
 } else {
 $('div.input').show();
 }
 code_show = !code_show
} 
$( document ).ready(code_toggle);
</script>
The raw code for this IPython notebook is by default hidden for easier reading.
To toggle on/off the raw code, click <a href="javascript:code_toggle()">here</a>.

""")

#Trebuchet MS
Out[31]:
The raw code for this IPython notebook is by default hidden for easier reading. To toggle on/off the raw code, click here.

Project 5A

The goal of this part is to get image mosaicing. I take SOME photographs and create an image mosaic by registering, projective warping, resampling, and compositing them. Along the way, i learn how to compute homographies, and how to use them to warp images.

1. Shoot the Pictures

I took three pictures of my kitchen from the same point of view but with different view directions

In [6]:
im1=io.imread("im1.jpg")
im2=io.imread("im2.jpg")
im3=io.imread("im3.jpg")

f = plt.figure(figsize=(20,20))
ax1 = f.add_subplot(1,3,1)
ax1.imshow(im1)
plt.axis("off")
ax2 = f.add_subplot(1,3,2)
ax2.imshow(im2)
plt.axis("off")
ax3 = f.add_subplot(1,3,3)
ax3.imshow(im3)
plt.axis("off")

plt.show()

2. Recover Homographies

In this part, we write a function of the form H = computeH(im1_pts,im2_pts) to compute the transformation function H. H is a 3*3 matrix with 8 freedom. The computation is based on:

In [9]:
im=io.imread("diagram.png")
plt.imshow(im)
plt.axis("off")
plt.show()

Weset i to be 1 to get rid of an arbitrary scaling. We strech the matrix H into a vector with 8 component and re-write the function into a linear function. By doing so, we turn this problem into a least square problem.

3. Warp the images and Rectification

In this part, we are able to rectify an image. We first select four points on the image. We assume these points are mapped to the vertex of a rectangle/square, e.g. (0,0), (0,100), (100,100), (100,9). Then we compute the matric H with the four point pairs. We write a function in the form of imwarped = warpImage(im,H) to warp an image based on the transformation H computed from the last step. We do this by inverse warping.

We show some examples here:

In [21]:
im1 = io.imread("blding.jpg")
im2 = io.imread("rec_blding.png")
f = plt.figure(figsize=(20,20))
ax1 = f.add_subplot(1,2,1)
ax1.imshow(im1)
plt.axis("off")

ax2 = f.add_subplot(1,2,2)
ax2.imshow(im2)
plt.axis("off")
Out[21]:
(-0.5, 1354.5, 1269.5, -0.5)
In [22]:
im1 = io.imread("tile.jpg")
im2 = io.imread("rec_tile.png")
f = plt.figure(figsize=(20,20))
ax1 = f.add_subplot(1,2,1)
ax1.imshow(im1)
plt.axis("off")

ax2 = f.add_subplot(1,2,2)
ax2.imshow(im2)
plt.axis("off")
plt.show
Out[22]:
<function matplotlib.pyplot.show(*args, **kw)>

Part 4: Blend images into a mosaic

In this part, we warp the images so they're registered and create an image mosaic. We blend images by Laplacian pyramid using the function we wrote in project 2. We show some examples here:

The original images are:

In [23]:
im1=io.imread("im1.jpg")
im2=io.imread("im2.jpg")
im3=io.imread("im3.jpg")

f = plt.figure(figsize=(20,20))
ax1 = f.add_subplot(1,3,1)
ax1.imshow(im1)
plt.axis("off")
ax2 = f.add_subplot(1,3,2)
ax2.imshow(im2)
plt.axis("off")
ax3 = f.add_subplot(1,3,3)
ax3.imshow(im3)
plt.axis("off")

plt.show()

Blend images into a mosaic

In [29]:
im1=io.imread("blend_f.png")
f = plt.figure(figsize=(10,10))
ax1 = f.add_subplot(1,1,1)
ax1.imshow(im1)
plt.axis("off")

plt.show()

What I learn:

In this project, I learn a lot on image rectification and mosaic. It helps me recall how to blend two images which is learned in project 2. It also helps me recall what we learned about image warping in project3. Really fun with this project!

In [ ]: