part a: image warping and mosaicing
in this project, i used least-squares homography estimation, inverse warping, and image interpolation for two applications: perspective rectification of the amoeba music and sana’a cafe signs, and panorama stitching of memorial glade, doe reading room, and a mountain scene. i walked around berkeley’s campus on a beautiful sunny day, taking photos of memorial glade and doe reading room to combine overlapping views into wider panoramas.
a.1 shooting the pictures · memorial glade
my first pair looks across memorial glade. the photographs share the library facade, the lawn, and the steps in the foreground, while each captures a different side of the scene. this overlap gives me recognizable features to match across the two views.
mosaicing assumes that the camera rotates around a fixed center of projection. under that assumption, a homography can relate the two views even though objects in the scene are at different depths. changing the camera’s position between shots causes objects at different depths to shift by different amounts so a single homography may not align the entire scene. people moving between exposures can also produce ghosting, even when the stationary background is aligned.


a.1 shooting the pictures · doe reading room
the second pair was taken inside the doe reading room. the repeated tables, tall windows, and ceiling details provide many possible correspondences. i used features spread through the overlap so that the fit would account for more than one small region of the image.


a.1 shooting the pictures · mountains
for the third pair, i used externally sourced mountain photographs showing overlapping views of a rocky mountain face and the forest below it. i matched distinctive features along the ridge and across the rock face. the broad stretch of sky has few features to click so the rock formations provide the constraints for the alignment.


a.2 recovering homographies
i selected corresponding points with a matplotlib interface that alternates clicks between the two photographs and saves their original pixel coordinates. i used 11 pairs for the glade, 12 for doe, and 8 for the mountains. each pair contributes two equations so all three fits have more constraints than the eight unknown entries of the homography.
for a source point (x, y) and its match (u, v), i multiply by H in homogeneous coordinates and divide by the third coordinate. setting the bottom-right entry of H to 1 leaves eight unknowns. rearranging the equations gives the two rows below, which i stack for every correspondence. my computeH function solves the resulting overdetermined system with numpy.linalg.lstsq.
[u, v, 1]ᵀ ∝ H [x, y, 1]ᵀ
[x y 1 0 0 0 −ux −uy] h = u [0 0 0 x y 1 −vx −vy] h = v
h = [h₁₁, h₁₂, h₁₃, h₂₁, h₂₂, h₂₃, h₃₁, h₃₂]ᵀ h* = argminₕ ‖Ah − b‖²; h₃₃ = 1
a.2 memorial glade · correspondences and recovered matrix
the numbered green crosses show my clicked correspondences, and the red circles in the second image show where H predicts those source points will land. for memorial glade, the mean reprojection error is 7.79 pixels and the largest error is 16.56 pixels, measured in the original 5712×4284 images.
these residuals measure agreement with the points used to fit H. they help reveal inaccurate clicks or an imperfect geometric fit, but do not measure alignment everywhere else in the image. the matrix below maps image 1 into image 2; the mosaic uses separate transforms into a shared canvas.
H = [ 0.28037 0.0536858 2702.89 -0.312413 0.786987 502.481 -0.000125616 -1.65673e-06 1 ]

a.2 doe reading room · correspondences and recovered matrix
the numbered green crosses show my clicked correspondences, and the red circles in the second image show where H predicts those source points will land. for doe reading room, the mean reprojection error is 7.50 pixels and the largest error is 13.77 pixels, measured in the original 5712×4284 images.
H = [ 3.01199 -0.186078 -8425.99 0.882851 2.41783 -3219.98 0.000355981 -2.0892e-05 1 ]

a.2 mountains · correspondences and recovered matrix
i used eight corresponding points for the mountain pair. the mean reprojection error is 2.19 pixels, with a maximum of 3.99 pixels, measured in the 568×758 source images. the red predictions lie close to the clicked matches along the ridge and rock face. these images have a different resolution from the glade and doe photographs so the raw pixel errors are not directly comparable across the three scenes.
H = [ 0.719696 -0.173759 -185.114 0.122705 0.609756 -20.5315 -0.000231637 -0.000555549 1 ]

a.3 inverse warping and interpolation
to warp an image, i first project its four corners through H and take the floor and ceiling of the transformed bounds. this tells me the output size and its offset in the destination coordinate system. for each output pixel, i apply the inverse homography and divide by the homogeneous coordinate to find the corresponding location in the source image. sampling backward this way avoids the holes that can appear when source pixels are pushed forward.
i implemented both interpolation methods directly. nearest neighbor rounds the source coordinates and copies one pixel. bilinear interpolation finds the four surrounding pixels and combines them according to the horizontal and vertical fractional offsets. a separate validity mask records which output pixels received image data so an actual black pixel is not confused with an empty part of the canvas.
for rectification, i selected the four corners of a sign and mapped them to the corners of a rectangle. i chose the output dimensions to set the rectangle’s aspect ratio, since the homography alone does not describe the sign’s actual width and height.
[x, y, w]ᵀ = H⁻¹ [u, v, 1]ᵀ; (xₛ, yₛ) = (x/w, y/w)
a = xₛ − floor(xₛ); b = yₛ − floor(yₛ) I(xₛ, yₛ) = (1−a)(1−b)I₀₀ + a(1−b)I₁₀ + (1−a)bI₀₁ + abI₁₁
a.3 rectification · amoeba music
i mapped the four selected corners of the amoeba music mural to a 400×600 rectangle. the original photograph compresses the sign toward the right, while the rectified versions spread the lettering across a front-facing rectangle.
the two results look quite similar at this scale, with bilinear interpolation producing a slightly smoother appearance. the saved run took 0.62 seconds for nearest neighbor and 1.32 seconds for bilinear so the smoother result took about twice as long in this implementation.

a.3 rectification · sana’a cafe
for the sana’a cafe sign, i used a wider 600×250 destination rectangle. the sign’s sloping border becomes horizontal, and the lettering is easier to compare across the two sampling methods.
nearest neighbor took 0.34 seconds and bilinear took 0.81 seconds in the saved comparison. the nearest-neighbor and bilinear results look almost identical at this scale, with both recovering the same geometry. these timings include the pixel-by-pixel inverse-warping loops and describe these particular runs, rather than a general benchmark for the two methods.

a.4 building and blending the mosaics
i compared using either photograph as the reference with warping both into a shared intermediate view. using image 1’s plane keeps image 1 unchanged and warps image 2 into it, while using image 2’s plane reverses those roles. in the glade and doe comparisons below, either fixed reference leaves the opposite side more stretched, while the third, intermediate plane spreads the perspective change across both images and gives a more balanced overall view. in the current pipeline, i average the two sets of correspondence coordinates and fit H₁ from image 1 to those midpoints. if H maps image 1 to image 2, i set H₂ = H₁H⁻¹ so that both source images are mapped consistently into the same coordinate system.
before sampling, i resize each source to a maximum width of 1200 pixels and adjust the transforms for the change of coordinates. i then project the corners of both images, find their combined bounds, and inverse-warp both onto that canvas with bilinear interpolation.
for blending, i compute each warped image’s distance to its mask boundary and choose a seam that favors the image farther from its edge. i split the images into a coarse gaussian level and a high-frequency residual. a broadly smoothed seam blends the coarse levels, while a narrower transition blends the detail levels. after reconstructing the image, i keep the original warped values wherever only one image is valid. this two-level laplacian blend softens the transition without averaging fine detail across the entire overlap.
mᵢ = (pᵢ + qᵢ)/2; H₁: pᵢ → mᵢ; H₂ = H₁H⁻¹
Lᵢ = Iᵢ − expand(Gᵢ) M = expand(wG G₁ + (1−wG)G₂) + wL L₁ + (1−wL)L₂
a.4 mosaic 1 · memorial glade
the glade mosaic brings the lawn, library, and foreground steps into one wider view. the intermediate projection distributes the perspective change across both photographs instead of leaving one view fixed. people who moved between the exposures can still create local inconsistencies, because blending cannot make two different moments agree.


a.4 mosaic 2 · doe reading room
the doe mosaic combines the two sides of the reading room and extends the view across the tables and ceiling. the repeated architecture makes small alignment errors noticeable: a mismatch along a window frame or table edge can remain visible even when the color transition is smooth. comparing the reference choices also shows how strongly the final perspective depends on the coordinate system used for the mosaic.


a.4 mosaic 3 · mountains
the mountain mosaic joins the two views into one continuous ridge and rock face, with the forest extending across the foreground. the main rock features line up without an obvious doubled outline. i kept the uncropped canvas so the boundaries of the warped photographs remain visible.
a faint brightness transition remains in the sky near the upper center. the alignment of the mountain is much less noticeable than this change in sky color, which makes the example useful for separating geometric alignment from blending quality. the mosaic uses the same shared intermediate view, bilinear sampling, and two-level laplacian blend as the other scenes.

part b · feature matching for autostitching
for part b, i used the same glade, doe, and mountain pairs and found correspondences automatically. the pipeline detects harris corners, selects a spatially distributed set with adaptive non-maximal suppression, describes each point with a normalized image patch, and matches the descriptors across the two images. four-point RANSAC then selects a consistent set of matches for the homography.
i reused the inverse warping and blending code from part a to construct the final mosaics. the figures below follow the feature selection and matching steps, then compare each automatic mosaic with its manually matched counterpart. the mountain photographs are from the same external source credited in part a.
b.1 harris corners and adaptive non-maximal suppression
i applied harris corner detection to grayscale images at their original resolution, using a single detection scale and a 20-pixel boundary exclusion. i selected local maxima of the harris response as candidate corners. the left panels show these candidates, including many points clustered around textured surfaces and repeated architectural details.
the glade and doe inputs each contain about 24.5 million pixels. with local maxima only one pixel apart and no explicit response-strength cutoff, fine texture and small intensity variations produce hundreds of thousands of candidates. weak maxima can appear even in the sky, and ANMS can retain some of them because it favors points far from stronger neighbors. the mountain images contain about 10,800 candidates each. the ratio test and RANSAC later filter the matches produced from these points.
for each candidate, i compute the distance to the nearest corner whose response is sufficiently stronger. specifically, a candidate j can suppress candidate i when fᵢ < 0.9 fⱼ. a point with no sufficiently stronger neighbor gets an infinite radius. i keep the 500 points with the largest suppression radii. using squared distances preserves the same ordering and avoids taking square roots. the right panels show the selected points.
rᵢ² = minⱼ ‖pᵢ − pⱼ‖², over j satisfying fᵢ < 0.9 fⱼ






b.2 feature descriptors
around each selected corner, i extract a 40×40 grayscale window, apply a gaussian blur with a 5×5 kernel and σ = 1, and sample every fifth pixel to produce an axis-aligned 8×8 patch. each descriptor therefore summarizes a larger neighborhood around the corner. flattening the patch gives a vector of 64 values.
i subtract the descriptor mean and divide by its standard deviation, with a small epsilon to handle constant patches. this bias/gain normalization reduces sensitivity to additive brightness changes and positive contrast scaling. the top rows below show source windows, and the bottom rows show the normalized descriptors. the descriptor orientation follows the image axes.
d = vec(blur(P)[::5, ::5])
d̂ = (d − mean(d)) / (std(d) + 10⁻⁸)






b.3 matching feature descriptors
for each descriptor in image 1, i compute its sum of squared differences from every descriptor in image 2 and sort the distances. i accept the closest candidate when its squared distance divided by the second-closest squared distance is below 0.7. this tests whether the best match is clearly better than its nearest competitor. on ordinary euclidean distances, this threshold is equivalent to approximately 0.837. as professor efros said in class, “If you’re deciding between two hard choices and can’t decide because it’s too close, you probably should choose neither.”
the ratio test leaves 33 matches for glade, 69 for doe, and 90 for the mountains. some incorrect pairs remain, especially among repeated windows, tables, and vegetation. RANSAC filters these using agreement with a common geometric transformation.
SSD(a, b) = Σₖ (aₖ − bₖ)²
accept when SSD₁ / SSD₂ < 0.7



b.4 robust homography estimation with RANSAC
i implemented four-point RANSAC. each iteration samples four matches without replacement and rejects a sample if any three source or destination points are collinear. the remaining sample defines a homography, which i use to project all matched image 1 points into image 2.
a match counts as an inlier when its euclidean reprojection error is below five pixels in the original destination image. i run 10,000 iterations with a fixed random seed, keep the hypothesis with the most inliers, and refit the homography using all matches in that consensus set. the consensus sets contain 10 of 33 matches for glade, 19 of 69 for doe, and 63 of 90 for the mountains.
eᵢ = ‖π(H [xᵢ, yᵢ, 1]ᵀ) − [uᵢ, vᵢ]ᵀ‖₂
inlier when eᵢ < 5 pixels; π([X, Y, W]ᵀ) = [X/W, Y/W]ᵀ



b.4 automatic mosaics · memorial glade
i pass the RANSAC consensus matches into the shared-plane stitching code from part a. it fits the inter-image homography, defines an intermediate view from the correspondence midpoints, and composes the second image’s transform through the first. both images are inverse-warped with bilinear interpolation and combined with the two-level gaussian/residual blend.
the automatic glade mosaic aligns the library facade and the foreground steps using ten consensus matches. the lawn and architecture form a continuous wider view, while a visible brightness transition remains in the sky.


b.4 automatic mosaics · doe reading room
the doe pair contains many repeated structures that produce ambiguous descriptor matches. RANSAC retains 19 geometrically consistent pairs, and the resulting mosaic joins the ceiling, window wall, and rows of tables. the manual and automatic versions have similar overall geometry, with small differences in alignment and the resulting intermediate projection.
the side-by-side figures use previews fitted to their panels. the original output resolutions differ between parts a and b, so these comparisons show the overall stitching and projection. fine-detail sharpness also depends on the sampling resolution.


b.4 automatic mosaics · mountains
the mountain pair has the largest consensus set, with 63 of the 90 ratio-test matches agreeing with the selected homography. the automatic result joins the ridge and rock face across the two views. its outline and intermediate perspective differ from the manually matched version because the fit uses a different set of correspondences.
a brightness transition remains visible across the sky, where there is little texture to constrain matching and the two source colors differ. the rock face gives a clearer view of the geometric alignment. this is the image with the clearest improvement between manual and automated correspondences!

