Announcements

• Assignment 2: Due Tuesday 2/18

Generalized , • Midterm: Thursday, February 13 in class, line fitting Well talk about it at the end of class Introduction to CSE 152 Lecture 11a

CSE152, Winter 2014 Intro Computer Vision CSE152, Winter 2014 Intro Computer Vision

Canny Edge Detector So, to detect corners • Filter image with a Gaussian. 1. Smooth image by filtering with a Gaussian 2. Compute gradient at each point in the image. • Compute the gradient everywhere. 3. At each point in the image, compute the direction • Move window over image and construct C of the gradient and the magnitude of the gradient. over the window. 4. Perform non-maximal suppression to identify • Use linear algebra to find λ1 and λ2. candidate edgels. • If they are both big, we have a corner. 5. Trace edge chains using hysteresis tresholding. 1. Let e(x,y) = min(λ1(x,y), λ2(x,y)) 2. (x,y) is a corner if it’s local maximum of e(x,y) and e(x,y) > τ

Parameters: Gaussian std. dev, window size, threshold CSE152, Winter 2014 Intro Computer Vision CSE152, Winter 2014 Intro Computer Vision

Corner Detection # 2 & What to do with edges? ∑Ix ∑IxIy C(x,y) = % ( • Segment linked edge chains into curve features I I I 2 What is region like if: $%∑ x y ∑ y '( (e.g., line segments).

1. λ1 = 0? • Group unlinked or unrelated edges into lines (or 2. λ = 0? curves in general). 2 € 3. λ1 = 0 and λ2 = 0?

4. λ1 > 0 and λ2 > 0?

• Accurately fitting parametric curves (e.g., lines) to grouped edge points.

CSE152, Winter 2014 Intro Computer Vision CSE152, Winter 2014 Intro Computer Vision

1 Finding lines in an image

y b

(m ,b ) Hough Transform 0 0 [ Patented 1962 ] x m image space Hough space

Connection between image (x,y) and Hough (m,b) spaces • A line in the image corresponds to a point in Hough space

CSE152, Winter 2014 Intro Computer Vision

Finding lines in an image Hough Transform Algorithm • Typically use a different parameterization y b

– d is the perpendicular distance from the line to the origin (x0,y0) – θ is the angle this perpendicular makes with the x axis – Why?

x m image space Hough space • Basic Hough transform algorithm 1. Initialize H[d, θ]=0 ; H is called accumulator array Connection between image (x,y) and Hough (m,b) spaces 2. for each edge point I[x,y] in the image for = 0 to 180 • A line in the image corresponds to a point in Hough space θ • What does a point (x , y ) in the image space map to? 0 0 H[d, θ] += 1 The equation of any line passing through (x , y ) has form 0 0 3. Find the value(s) of (d, θ) where H[d, θ] is the global maximum y = mx + b 0 0 4. The detected line in the image is given by This is a line in Hough space: b = -x m + y 0 0 • What’s the running time (measured in # votes)? CSE152, Winter 2014 Intro Computer Vision

Hough Transform: 20 colinear points Hough Transform: Random points Image Accumulator Image Accumulator

y d d y

x θ x θ • R, θ representation of line • R, θ representation of line • Drawn as: d = |xcosθ + ysinθ | • Drawn as: d = |xcosθ + ysinθ

CSE152, •Winter Maximum 2014 Note: accumulator accumulator array range: theta: value 0-360, d: is positive 20 Intro Computer Vision CSE152, •Winter Maximum 2014 accumulator value is 4 Intro Computer Vision

2 Hough Transform: “Noisy line” Hough Transform for Curves Image Accumulator Generalized Hough Transform

The H.T. can be generalized to detect any curve that can be expressed in parametric form: y = f(x, a a ,…a ) d 1, 2 p y or

g(x,y,a1,a2,…ap) = 0

x θ – a1, a2, … ap are the parameters • r, θ representation of line – The parameter space is p-dimensional • Drawn as: d = |xcosθ + ysinθ – The accumulating array is LARGE!

CSE152, •Winter Maximum 2014 accumulator value is 6 Intro Computer Vision CSE152, Winter 2014 Intro Computer Vision

TEM Image of Keyhole Limpet Example: Finding circles Hemocyanin with detected particles Equation for circle is 2 2 2 (x – xc) + (y – yc) = r

where the parameters are the circle’s center (xc, yc) and radius r.

Three dimensional generalized Hough space. Given an edge point (x,y),

1. Loop over all values of (xc, yc), 2. Compute r

3. Increment H(xc, yc, r)

CSE152, Winter 2014 Intro Computer Vision CSE152, Winter 2014 Intro Computer Vision

3D Maps of KLH Processing in Stage 1 for KLH

• Canny . Image • A sequence of ordered Hough transforms (HT’s) is Edge Detection applied in order from the

computationally simplest Circle Detection Circle Coords. one to the most complex one. Remove Circles • Edges covered by the detected shapes are removed Rect. Coords. immediately from edge Rectangle Detection images following the application of the last HT. Candidate Particles Three-dimensional maps of KLH at a resolution of 23.5 Å reconstructed using particles extracted either manually or automatically as described in the text. (a), (b) The side- and top- view of a 3D map reconstructed from a set of 1042 manually selected particle images.

CSE152, Winter 2014 Intro Computer Vision CSE152, Winter 2014 Intro Computer Vision

3 Picking KLH Particles in Stage 1 Line Fitting

Zhu et al., IEEE Transactions on Medical Imaging, 2003 CSE152, Winter 2014 Intro Computer Vision CSE152, Winter 2014 Intro Computer Vision

Line Fitting Line fitting cont. Given n points (xi, yi), estimate parameters of line ax + by - d = 0 i i 2. Substitute d back into E subject to the constraint that

a2 + b2 = 1 where

(xi,yi) Note: ax + by - d is distance i i where n=(a b)T. from (xi, yi) to line. Problem: minimize Cost Function: 2= T T T 3. Minimize E=|Un| n U Un=n Sn with respect to a, b Sum of squared distances T between each point and the line subject to the constraint n n = 1. Note that S is given by

with respect to (a,b,d). S = 1. Minimize E with respect to d: ∂E 1 n Where ( x , y ) is the = 0 ⇒ d = ax + by = ax + by ∑ i i mean of the data points And it’s a real, symmetric, positive definite ∂d n i=1 CSE152, Winter 2014 Intro Computer Vision CSE152, Winter 2014 Intro Computer Vision

Midterm Line Fitting – Finished Thursday, February 13 4. This is a constrained optimization problem in n. Solve • In class with Lagrange multiplier • Full period L(n) = nTSn – λ(nTn – 1) • Coverage – everything up to this point Take partial derivative (gradient) w.r.t. n and set to 0. including readings ∇L = 2Sn – 2λn = 0 • “Cheat sheet” – you can prepare a one sided or sheet of notes. It must be hand written. (After the midterm, save your sheet since Sn = n λ you can use the other side for the final). n=(a,b) is an Eigenvector of the symmetric matrix S (the one corresponding to the smallest Eigenvalue). • No calculators. 5. d is computed from Step 1.

CSE152, Winter 2014 Intro Computer Vision CSE152, Winter 2014 Intro Computer Vision

4 Incomplete list of topics covered… Topics cont.

• Human visual system • Quantization/Resolution • Edges & Edge detection • Binary Vision – Physiology – from eye to • Illumination – Thresholding • Edge sources brain • Reflectance • Canny – Phenomenological – Neighborhoods – BRDF – Gaussian derivatives – Function – Connected component – Lambertian exploration – Magnitude, orientation • Camera models – Specular – Features, moments – Non-maximal suprression • Factors in producing – Phong • Noise – Linking/thresholding images • Color – Additive, Gaussian noise • Hough Transform • Projection models – Light Spectrum • Filtering, linear, • Generalized Hough – Perspective – Reflectance, source with Kernel transform – Orthographic – Sensor response – Averaging/smoothing • Line fitting • Homogenous Coordinates, – Color spaces – Sharpening • Vanishing points – Chromaticity, YUV, RGB – Derivatives • Lenses, Distortion – – Seperability • Sensors

CSE152, Winter 2014 Intro Computer Vision CSE152, Winter 2014 Intro Computer Vision

5