CS 4501: Computer Vision
Homework Assignment #1

Tom Crossland (tcc4dr)

Canny Edge Detector

My Canny Edge Detecter is written as the program edge.m. edge takes in four arguments:

My gradient filter size is based off of the sigma value inputted. After researching online and consulting some members of the class, I made the filter size be the rounded sigma value multiplied by 6. If this number was even, I added one to it to make it odd. This allowed me to centralize the Gaussian filter so the values x=0,y=0 passed into the derivative of the Gaussian filter to be at its center. Convolution was then performed to get the gradients in the x and y directions. conv2 was used due to its ease of implementation and to ensure that the resulting gradients would be the same size as the original image.

For finding the edge orientation at each pixel, I used arctan, offsetting the value by 90 degrees due to the range arctan returns on Matlab. When performing nonmaximum surpression, I created a new matrix, the same size as the original image. Surpressed pixels had a value of 0 in its corresponding pixel in the new matrix while nonsurpressed pixels had the same value as their edge strength in the new matrix. When doing hysteresis, if the given pixel has an edge strength higher than T_h, I added it to a list to be chained. While going along the "chains," I could easily add a pixel to the list to be chained and mark the node as "visited" in a new matrix. This "visited" matrix would be analogous to the final edge detected image; any pixel visited would be an edge and white while any pixel not "visited" in this sense would be black and not an edge. The following are example images used as input and created as output.

mandrill.jpg

Input Values: sigma = 2, T_h = .005, T_l = .001

Smoothed Horizontal Gradient
Smoothed Vertical Gradient
Gradient Magnitude
Gradient Magnitude after Nonmaximal Suppression
Image after Hysteresis

Input Values: sigma = 5, T_h = .005, T_l = .001

Smoothed Horizontal Gradient
Smoothed Vertical Gradient
Gradient Magnitude
Gradient Magnitude after Nonmaximal Suppression
Image after Hysteresis

Input Values: sigma = 5, T_h = .01, T_l = .001

Smoothed Horizontal Gradient
Smoothed Vertical Gradient
Gradient Magnitude
Gradient Magnitude after Nonmaximal Suppression
Image after Hysteresis

Input Values: sigma = 5, T_h = .01, T_l = .005

Smoothed Horizontal Gradient
Smoothed Vertical Gradient
Gradient Magnitude
Gradient Magnitude after Nonmaximal Suppression
Image after Hysteresis

Changing the sigma value had a noticeable effect on edge detection as seen in the Mandrill example. When sigma was low, there was less blurring of the image. When sigma was high, the inverse was true. A low sigma value such as 2 on the mandrill did not blur away the hair lines around the animal's face. Therefore, the program detected lots of edges in the mandrill's fur. A sigma value of 5 blurred the hair lines, causing the program to not detect as many edges in the animal's fur. In addition, the thresholds had a noticeable impact on the final image. Maintaining a constant blur of sigma value 5, a smaller low threshold (like .001) allowed weaker edges to be detected while a larger high threshold (like .01) allowed weaker edges to not be as easily detected, as seen above.

building.jpg

Input Values: sigma = 2, T_h = .005, T_l = .001

Smoothed Horizontal Gradient
Smoothed Vertical Gradient
Gradient Magnitude
Gradient Magnitude after Nonmaximal Suppression
Image after Hysteresis

Input Values: sigma = 3, T_h = .005, T_l = .001

Smoothed Horizontal Gradient
Smoothed Vertical Gradient
Gradient Magnitude
Gradient Magnitude after Nonmaximal Suppression
Image after Hysteresis

Input Values: sigma = 6, T_h = .005, T_l = .001

Smoothed Horizontal Gradient
Smoothed Vertical Gradient
Gradient Magnitude
Gradient Magnitude after Nonmaximal Suppression
Image after Hysteresis

Changing the sigma value altered the amount of edges detected in the building picture. The higher the sigma value was, the more the picture was blurred. This smoothed over pixels that might otherwise be deemed an edge. For example, a sigma value of 2 caused many of the edges of the bricks in the building to be detected. A sigma value of 3 showed a decrease in this detection. A sigma value of 6 caused an image so blurred that little to no brick edges were detected.

Starry.jpg

Input Values: sigma = 2, T_h = .005, T_l = .001

Smoothed Horizontal Gradient
Smoothed Vertical Gradient
Gradient Magnitude
Gradient Magnitude after Nonmaximal Suppression
Image after Hysteresis

Input Values: sigma = 5, T_h = .005, T_l = .001

Smoothed Horizontal Gradient
Smoothed Vertical Gradient
Gradient Magnitude
Gradient Magnitude after Nonmaximal Suppression
Image after Hysteresis

The effects of sigma can again be seen here. A higher sigma value blurs the brushstrokes of the painting. This causes fewer edges to be detected. A lower sigma does not blur the brushstrokes, causing more edges to be detected.


Corner Detector

My Corner Detecter is written as the program corner.m. It takes in four arguments: file, sigma, nsize, T.

My gradient filter size is based off of the sigma value inputted. After researching online and consulting some members of the class, I made the filter size be the rounded sigma value multiplied by 6. If this number was even, I added one to it to make it odd. This allowed me to centralize the Gaussian filter so the values x=0,y=0 passed into the derivative of the Gaussian filter to be at its center. Convolution was then performed to get the gradients in the x and y directions. conv2 was used due to its ease of implementation and to ensure that the resulting gradients would be the same size as the original image.

When storing the minimum eigenvalues for a pixel's neighborhood's covariance matrix, I made a three dimensional matrix. The first two dimensions stored the cartesian point location of the pixel. The third dimension had two elements: the minimum eigenvalue and whether or not that pixel was a possible corner pixel. On a copy of the original image, I changed every possible corner pixel to be red. Originally, I had the possible corners in a list. While this saved space, it took a vast amount of time to detect corners. Finding corners with the building picture would take about 13 minutes. With a matrix using greater memory, that time was reduced to under 45 seconds. Instead of sorting a list and comparing the positions of the eigenvalues of the pixel in question and a pixel in its neighborhood in said list, I did comparison by lookup in my three-dimensional matrix. If a corner pixel was to be suppressed, I updated that in constant time updating the matrix values. I then could find all corner values after this suppression process based on their values in position 2 of the third dimension of the matrix. I drew a box the size of the neighborhood around every nonsuppressed corner pixel in the image. The following are example images used as input and created as output.

building.jpg

Input Values: sigma = 1, nsize = 10, T = .1

Smoothed Horizontal Gradient
Smoothed Vertical Gradient
Gradient Magnitude
Finding Corners
Nonmaximal Surpression

Input Values: sigma = 2, nsize = 10, T = .1

Smoothed Horizontal Gradient
Smoothed Vertical Gradient
Gradient Magnitude
Finding Corners
Nonmaximal Surpression

Input Values: sigma = 2, nsize = 10, T = .05

Smoothed Horizontal Gradient
Smoothed Vertical Gradient
Gradient Magnitude
Finding Corners
Nonmaximal Surpression

Using the building picture as an example, I saw how sigma values can affect corner detection. The higher the sigma value is, the blurrier the image becomes. This will smooth over some pixels, making them less detectable as a corner. With a sigma value of 1, many of the corners of the bricks can be detected. However, a sigma value of 2 will lead to a decrease in the amount of brick corners detected due to them being smoothed over. In addition, the smaller the threshold is, the more possible corner pixels there are. One can observe the difference in amount of pixel corners found when using a threshold of 0.1 compared to 0.05.

checker.jpg

Input Values: sigma = 1, nsize = 10, T = 0.3

Smoothed Horizontal Gradient
Smoothed Vertical Gradient
Gradient Magnitude
Finding Corners
Nonmaximal Surpression

Input Values: sigma = 1, nsize = 12, T = 0.4

Smoothed Horizontal Gradient
Smoothed Vertical Gradient
Gradient Magnitude
Finding Corners
Nonmaximal Surpression

Input Values: sigma = 1, nsize = 14, T = 0.6

Smoothed Horizontal Gradient
Smoothed Vertical Gradient
Gradient Magnitude
Finding Corners
Nonmaximal Surpression

Using the checkerboard image as an example, I observed how neighborhood size affects corner detection. The smaller the neighborhood size is, the more likely multiple corner pixels representing the same corner will be not suppressed. The larger the neighborhood size is, the less likely this will happen. This is because a larger neighborhood will cause a wider spread of potential corners to possibly be suppressed. One can see how the number of these errors decreases with increased neighborhood size. When increasing the neighborhood size, one should increase the threshold amount since when computing the convariance matrix, one will be summing over more pixels.