
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?
10 次查看(过去 30 天)
显示 更早的评论
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')
0 个评论
采纳的回答
Image Analyst
2018-7-22
编辑:Image Analyst
2018-7-22
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.
0 个评论
更多回答(1 个)
Nayana K M
2022-1-18
I = rgb2gray(imread("dog.jpg"));
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");
5 个评论
Brandon
2024-12-6
how would you normalized the axis? and also move the starting point at the centre of an object (for example a circle)
DGM
2024-12-6
编辑:DGM
2024-12-6
If you just want to visually align a displayed image, then read the documentation for the XData,YData properties of image objects: image() imagesc() imshow()
You want the axes to be "normalized", but you also want the origin to be centered on the object. I see no reason to presume that the object is always centered in the image, so you'll have to figure out what you want to do to fix that. Here are two examples. Depending on what you mean by "normalized", there are plenty of other ways.
% some image (RGB)
inpict = imread('gcircle.png');
% convert it to a logical mask containing the blob to be centered
% (there's only one blob in this image)
mask = im2gray(inpict);
mask = imbinarize(mask);
% find the centroid of the blob
S = regionprops(mask,'centroid'); % [x y]
% assuming that the image fits within the axes without any cropping
sz = fliplr(size(mask,1:2)); % [x y]
rx = [S.Centroid(1) sz(1)-S.Centroid(1)]; % distance from centroid to edges
ry = [S.Centroid(2) sz(2)-S.Centroid(2)];
maxr = max([rx ry]);
rx = [-1 1].*rx./maxr; % normalize
ry = [-1 1].*ry./maxr;
figure(1)
imshow(inpict,'xdata',rx,'ydata',ry)
grid on
axis on
xlim([-1 1]) % enforce axes extents
ylim([-1 1])
% assuming that the image fills the axes, any excess is cropped
sz = fliplr(size(mask,1:2)); % [x y]
rx = [S.Centroid(1) sz(1)-S.Centroid(1)]; % distance from centroid to edges
ry = [S.Centroid(2) sz(2)-S.Centroid(2)];
minr = min([rx ry]);
rx = [-1 1].*rx./minr; % normalize
ry = [-1 1].*ry./minr;
figure(2)
imshow(inpict,'xdata',rx,'ydata',ry)
grid on
axis on
xlim([-1 1]) % enforce axes extents
ylim([-1 1])
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!