Info

This question is closed. Reopen it to edit or answer.

i don't know what is wrong with my code for finding edges

1 view (last 30 days)
i'm new to this, i got this Question where i have to find edge for 2 images and their common edge but it keeps showing me error :/ for if and end statement
% i = imread('file:///C:/Users/Rana/Desktop/firstCV.png');
j = imread('file:///C:/Users/Rana/Desktop/secondCV.png');
if (size(i,3)==3)
I= rgb2gray(i);
elseif I==i
end
e1 = edge(I, 'canny');
%-------------------------
if (size(j,3)==3)
I2 = rgb2gray(j);
elseif I2==j
end
e2 = edge(I2, 'canny');
edge = e1+e2;
imshow(edg);
secretcode = e1+e2-1;
imshow(secretcode);
  3 Comments
per isakson
per isakson on 23 Mar 2018
Edited: per isakson on 24 Mar 2018
You increase your chances to get a useful answer by

Answers (1)

Image Analyst
Image Analyst on 23 Mar 2018
You can't have this:
elseif I==i
like the error message says. And you also switched to the badly-named j from the even worse-named i but then still checked for i. Plus you're using "edge", which is the name of a built-in function, as your variable name. Plus several more problems. I made it more robust by checking that the image sizes match. Try it like this:
grayImage1 = imread('eight.tif'); % Whatever.
subplot(2, 3, 1);
imshow(grayImage1, []);
axis on;
title('Gray Image 1', 'FontSize', 15);
grayImage2 = imread('coins.png'); % Whatever.
subplot(2, 3, 2);
imshow(grayImage2, []);
axis on;
title('Gray Image 2', 'FontSize', 15);
if ndims(grayImage1) == 3
grayImage1 = rgb2gray(grayImage1);
end
edgeImage1 = edge(grayImage1, 'canny');
subplot(2, 3, 4);
imshow(edgeImage1, []);
title('Edge Image 1', 'FontSize', 15);
%-------------------------
if ndims(grayImage2) == 3
grayImage2 = rgb2gray(grayImage2);
end
edgeImage2 = edge(grayImage2, 'canny');
subplot(2, 3, 5);
imshow(edgeImage2, []);
title('Edge Image 2', 'FontSize', 15);
% Make sure images are the same size before we try to add them.
if ~isequal(size(edgeImage1), size(edgeImage2))
errorMessage = 'Images are not the same size';
uiwait(errordlg(errorMessage));
return;
end
edgeImage = edgeImage1 + edgeImage2;
subplot(2, 3, 3);
imshow(edgeImage, []);
title('Sum of Edge Images', 'FontSize', 15);
secretcode = edgeImage1+edgeImage2-1;
subplot(2, 3, 6);
imshow(secretcode, []);
title('Secret Code', 'FontSize', 15);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!