mp2

.pdf

School

University of Illinois, Urbana Champaign *

*We aren’t endorsed by this school

Course

543

Subject

Electrical Engineering

Date

Jan 9, 2024

Type

pdf

Pages

9

Uploaded by leojiang8

Report
Contour 1. For the warm-up, I added symmetric boundaries for convolve2d function dx = signal.convolve2d(I, np.array([[-1, 0, 1]]), mode='same', boundary='symm') dy = signal.convolve2d(I, np.array([[-1, 0, 1]]).T, mode='same', boundary='symm') For the Smoothing, I added a gaussian filter with a sigma of 2 for the convolve2d function to calculate dx dy dx = signal.convolve2d(gaussian_filter(I , 2 ) , np.array([[- 1 , 0 , 1 ]]) , mode = 'same' , boundary = 'symm' ) dy = signal.convolve2d(gaussian_filter(I , 2 ) , np.array([[- 1 , 0 , 1 ]]).T , mode = 'same' , boundary = 'symm' ) For the NMS, I first calculate the magnitude and angle of dx and dy using arctan distance equation mag = np.sqrt(dx ** 2 + dy ** 2 ) t = np.arctan2(dy , dx) Using the angle, I loop though the entire image, using the angle to find q and r. For each q and r, I find the two points nearest to q and r, and apply linear interpolation to figure out the average of the two points using sin and cos. if ( 0 <= theta[i , j] < pi / 4 ): q = img[i , j + 1 ] * np.sin(theta[i , j]) + ( 1 - np.sin(theta[i , j])) * img[i + 1 , j + 1 ] r = img[i , j - 1 ] * np.sin(theta[i , j]) + ( 1 - np.sin(theta[i , j])) * img[i - 1 , j - 1 ] elif (pi / 4 <= theta[i , j] < pi / 2 ): q = img[i + 1 , j + 1 ] * ( 1 - np.cos(theta[i , j])) + (np.cos(theta[i , j])) * img[i + 1 , j] r = img[i - 1 , j - 1 ] * ( 1 - np.cos(theta[i , j])) + (np.cos(theta[i , j])) * img[i - 1 , j] elif (pi / 2 <= theta[i , j] < 3 * pi / 4 ): q = img[i + 1 , j] * (np.sin(theta[i , j] - pi / 2 )) + img[i + 1 , j - 1 ] * ( 1 - (np.sin(theta[i , j] - pi / 2 ))) r = img[i - 1 , j] * (np.sin(theta[i , j] - pi / 2 )) + img[i - 1 , j + 1 ] * ( 1 - (np.sin(theta[i , j] - pi / 2 ))) elif ( 3 * pi / 4 <= theta[i , j] < pi):
q = img[i + 1 , j - 1 ] * ( 1 - np.cos(theta[i , j] - pi / 2 )) + img[i , j - 1 ] * ( (np.cos(theta[i , j] - pi / 2 ))) r = img[i - 1 , j + 1 ] * ( 1 - np.cos(theta[i , j] - pi / 2 )) + img[i , j + 1 ] * ( (np.cos(theta[i , j] - pi / 2 ))) After that, if the magnitude of an image at one point is greater than q and r of that point, that means the point should be the contour. if (img[i , j] >= q) and (img[i , j] >= r): Z[i , j] = img[i , j] else : Z[i , j] = 0 2. Precision Recall plot Warm up
Smoothing 3. Table Method Overall max F Average max F AP Runtime Initial 0.4 0.46 0.315 0.017 Warm-up 0.423 0.484 0.36 0.03 Smoothing 0.52 0.522 0.333 0.027 NMS 0.5625 0.592 0.537 1.07 Best model 0.5625 0.592 0.537 1.07
4. Visualizations The leftmost image is the original image, the middle one is after applying the gaussian filter, and the last one is after applying the NMS. Gaussian filter got rid of some of the noises from the original implementation, but it also make the image blurry. NMS makes the edges thinner since we suppress the output of a pixel that has less value than its neighbor, and makes the overall contour well-defined. Corner Detection 1. Method The first step is to find the gradient value dx and dy similar to the last problem dx = signal.convolve2d(I , np.array([[- 1 , 0 , 1. ]]) , mode = 'same' , boundary = 'symm' ) dy = signal.convolve2d(I , np.array([[- 1 , 0 , 1. ]]).T , mode = 'same' , boundary = 'symm' ) Then, we can calculate the moment matrix using gaussian filter sigma = 0.6 mx = gaussian_filter(dx** 2 , sigma) my = gaussian_filter(dy** 2 , sigma) mxy = gaussian_filter(dy*dx , sigma) Then we can calculate the response using the above values k = 0.035 response = mx * my - mxy** 2 - k * (mx + my) ** 2 We then set up the 3x3 window and loop through the entire image, and find the points above the response threshold window_size = 3 H , W = I.shape for h in range (H): for w in range (W): for i in range ( max ( 0 , h - window_size) , min (h + window_size + 1 , H)):
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help