How to Detect Edges of an Image using Canny Edge Detection technique. I have already detected edges of Images, but I'm not sure if it is correct or not. Also, I want to add legend command and axis information in this, how would I do this thing?

250 views (last 30 days)
if true
% code
end
clc;
clear all;
close all;
img = imread('Table.jpg');
image(img)
title('Original Image')
figure,
I = rgb2gray(img);
imshow(uint8(I))
image(I)
title('Grey Scaled Image')
figure,
Canny_img = edge(I,'Canny');
imshow(Canny_img)
image(Canny_img*255)
title('Edge Detected Image')

Accepted Answer

Image Analyst
Image Analyst on 22 Jul 2018
Edited: Image Analyst on 22 Jul 2018
Use axis('on', 'image'). I fixed other problems too. Fixed code is below:
clc;
clear all;
close all;
workspace; % Make sure the workspace panel is showing.
% Read in original RGB image.
rgbImage = imread('Table.jpg');
subplot(2, 2, 1);
imshow(rgbImage)
axis('on', 'image');
title('Original Image')
% Convert to gray scale.
grayImage = rgb2gray(rgbImage);
subplot(2, 2, 2);
imshow(grayImage)
axis('on', 'image');
title('Grey Scale Image')
% Get edges
Canny_img = edge(grayImage, 'Canny');
subplot(2, 2, 3);
imshow(Canny_img, [])
axis('on', 'image');
title('Edge Detected Image')
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0.05, 1, 0.95]);
By the way, you don't need to do edge detection to "find" the table if that's all that you want to do. You can simply threshold.

More Answers (1)

Nayana  K M
Nayana K M on 18 Jan 2022
I = rgb2gray(imread("dog.jpg"));
Error using imread>get_full_filename (line 569)
File "dog.jpg" does not exist.

Error in imread (line 371)
fullname = get_full_filename(filename);
subplot(2, 4, 1),
imshow(I);
title("Gray Scale Image");
% Sobel Edge Detection
J = edge(I, 'Sobel');
subplot(2, 4, 2),
imshow(J);
title("Sobel");
% Prewitt Edge detection
K = edge(I, 'Prewitt');
subplot(2, 4, 3),
imshow(K);
title("Prewitt");
% Robert Edge Detection
L = edge(I, 'Roberts');
subplot(2, 4, 4),
imshow(L);
title("Robert");
% Log Edge Detection
M = edge(I, 'log');
subplot(2, 4, 5),
imshow(M);
title("Log");
% Zerocross Edge Detection
M = edge(I, 'zerocross');
subplot(2, 4, 6),
imshow(M);
title("Zerocross");
% Canny Edge Detection
N = edge(I, 'Canny');
subplot(2, 4, 7),
imshow(N);
title("Canny");
  1 Comment
Image Analyst
Image Analyst on 18 Jan 2022
rgbImage = imread('kobi.png');
% rgbImage = imread('table.jpg');
if ndims(rgbImage) == 3
grayImage = rgb2gray(rgbImage);
else
grayImage = rgbImage;
end
subplot(3, 3, 1),
imshow(grayImage);
axis('on', 'image')
title("Gray Scale Image");
%--------------------------------------------
% Sobel Edge Detection
J = edge(grayImage, 'Sobel');
subplot(3, 3, 2),
imshow(J);
title("Sobel");
%--------------------------------------------
% Prewitt Edge detection
K = edge(grayImage, 'Prewitt');
subplot(3, 3, 3),
imshow(K);
title("Prewitt");
%--------------------------------------------
% Robert Edge Detection
L = edge(grayImage, 'Roberts');
subplot(3, 3, 4),
imshow(L);
title("Robert");
%--------------------------------------------
% Log Edge Detection
M = edge(grayImage, 'log');
subplot(3, 3, 5),
imshow(M);
title("Log");
%--------------------------------------------
% Zerocross Edge Detection
M = edge(grayImage, 'zerocross');
subplot(3, 3, 6),
imshow(M);
title("Zerocross");
%--------------------------------------------
% Canny Edge Detection
N = edge(grayImage, 'Canny');
subplot(3, 3, 7),
imshow(N);

Sign in to comment.

Products


Release

R2014a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!