Index out of bounds
3 次查看(过去 30 天)
显示 更早的评论
hello, i want to use canny edge detection from this image

here is the code :
handles.m = edge(handles.m,'canny');
[h, w] = size(handles.m);
filter = [0.0174 0.348 0.04348 0.0348 0.0174; 0.0348 0.0782 0.1043 0.0782 0.0348; 0.0435 0.1043 0.1304 0.1043 0.0435;0.0348 0.0782 0.1043 0.0782 0.0348; 0.0174 0.348 0.04348 0.0348 0.0174];
Mx = [-1 0 1; -2 0 2; -1 0 1];
My = [-1 -2 -1; 0 0 0; 1 2 1];
for v = 2 : 511
for u = 2 : 511
sum = 0;
for i = -2 : 2
for j = -2 : 2
sum = sum + (handles.m(u, v) * filter(i+3, j+3));
end
end
handles.mx(u,v) = sum;
end
end
guidata(hObject,handles);
axes(handles.axes3);
imshow(handles.m);
msgbox('Detection SUCCESSFUL !');
when i execute the program, an error occured like this :
??? Attempted to access handles.m(139,2); index out of bounds because
size(handles.m)=[138,1130].
Error in ==> processing>pushbutton12_Callback at 247
sum = sum + (handles.m(u, v) * filter(i+3, j+3));
anyone knows why? Thanks
0 个评论
采纳的回答
Image Analyst
2016-10-31
Because your m matrix does not have 139 rows in it. It has only 138 rows. The error message plainly says this. We do not know why it has only 138 rows, nor do we know why you are trying to access rows beyond that.
Possible fix:
[rows, columns] = size(handles.m);
for v = 2 : columns - 1
for u = 2 : rows - 1
Also, do not use sum as a variable name because it's a built-in function.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!