Homework 4 Notes Connelly Barnes COS 323. MATLAB Semicolon at endline suppresses output. >> [1 2]...

17
Homework 4 Notes Connelly Barnes COS 323
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    217
  • download

    1

Transcript of Homework 4 Notes Connelly Barnes COS 323. MATLAB Semicolon at endline suppresses output. >> [1 2]...

Homework 4 Notes

Connelly Barnes

COS 323

MATLAB

• Semicolon at endline suppresses output.

>> [1 2]

ans =

1 2

>> [1 2];

Images

• imread(filename) reads image as:– h x w (greyscale) or– h x w x 3 (color)– uint8, values in [0, 255].

• Do alignment in greyscale, doubles.A=double(imread(filename));

if size(A,3)==3 A = rgb2gray(A); end• imshow(A) with double A assumes colors are in

[0, 1]. So divide by 255 before imshow() at some point.

Image Transform

• imtransformSimple(A, [x y θ]) =>

Transformed image with same size as A.

Image Transform

>> imshow(A);

Image Transform

>>imshow(imtransformSimple(A,[100 0 pi/4]));

Parts of Assignment

• Paradigm: Write an error function, then minimize that function.

• Part 1: Image difference– F(x, y, theta) => Error– Want to minimize error.

• Part 2: Minimization– Minimizing a function of n variables is a well-studied

problem, general solutions are known.

Image Difference

• Find sum squared difference on region where images overlap.

Image Difference

• Overlap region image 1's region.• So in image 1's coordinates, can represent

overlap region with a mask,

1 = overlap, 0 = no overlap.

Mask

Mask

• If A, B are pair of images, then

imtransformSimple(B, [x y θ]) transforms

image B.

• To find mask, transform array of all ones with same parameters.

Image Difference

• Now follow directions of assignment: use mask to find sum squared difference.

• Use .* (element-wise product) operator, not * (matrix product) when multiplying mask against an image.

Minimization

• Given F(x, y, θ) (F: R3 → R).• Find vector [x y θ] minimizing F.• If smooth, can find local minimum by general

algorithm.• So treat F as a black box and solve minimization

independently of the previous part.• Golden Section search finds local minimum of

1D function.• Do Golden Section search for dimensions i=1, 2,

3, then repeat => taxicab minimization.

Minimization

• For convenience, loop over the dimension i that you're minimizing via Golden Section search (write F as a vector function).

• Extra credit: plot [x, y, θ] points that the algorithm searches over in 3D (use plot3()), observe zig-zagging of taxicab minimization.

Merge Results

• Use mergeImages(A, B, [x y θ]) to get merged image. Use color.

Caveats

• Minimization finds a local minimum.

• Not necessarily the global minimum.

x

FLocal

Global

Solution

• Start with a good guess (gets full credit on this assignment).

• If F is quadratic, can solve exactly via a linear system. Not so in our case.

• General solution is to start with many random guesses (extra credit).