find corners of an object in image using canny and sobel in matlab

Here's an example code to find corners of an object in an image using Canny and Sobel edge detection in MATLAB:

% Read input image
img = imread('input.jpg');

% Convert input image to grayscale
grayImg = rgb2gray(img);

% Apply Sobel edge detection to the input image
sobelImg = edge(grayImg,'Sobel');

% Apply Canny edge detection to the input image
cannyImg = edge(grayImg,'Canny');

% Find corners using Harris corner detection algorithm on Sobel image
corners = detectHarrisFeatures(sobelImg);

% Display Sobel edges and detected corners on the input image
figure;
imshow(img);
hold on;
plot(corners);

% Find corners using FAST corner detection algorithm on Canny image
corners = detectFASTFeatures(cannyImg);

% Display Canny edges and detected corners on the input image
figure;
imshow(img);
hold on;
plot(corners);
711 chars
30 lines

In the code above, we first read the input image and convert it to grayscale. Then, we apply Sobel and Canny edge detection algorithms to the grayscale image. Next, we use the Harris corner detection method on the Sobel image to find the corners. We display the Sobel edges and detected corners on the input image. We then repeat the same process using the FAST corner detection method on the Canny image. Finally, we display the Canny edges and detected corners on the input image.

Note that the choice of threshold values in the edge detection algorithms can greatly affect the resulting corners. You may need to tune these values for your specific image to get the best results.

gistlibby LogSnag