canny filter manually in matlab

To apply the Canny filter manually in matlab, you can follow these steps:

  1. Read the image using imread() function.
main.m
img = imread('image.jpg');
27 chars
2 lines
  1. Convert the image to grayscale.
main.m
gray_img = rgb2gray(img);
26 chars
2 lines
  1. Apply Gaussian filter to the image using imfilter() function.
main.m
gaussian_img = imfilter(gray_img,fspecial('gaussian'));
56 chars
2 lines
  1. Calculate gradient magnitude and direction of the smoothed image using edge() function.
main.m
[grad_mag, grad_dir] = edge(gaussian_img,'Canny');
51 chars
2 lines
  1. Finally, display the gradient magnitude image using imshow() function.
main.m
imshow(grad_mag);
18 chars
2 lines

You can adjust the parameters of imfilter() and edge() functions to get different results based on your requirements.

gistlibby LogSnag