竹影536 2022-05-22 21:18
浏览 99
已结题

请教一下程序如何修改,运行报错

问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图

clear ;
clc

%读取图像
% I=imread('huan.jpg');
[filename,pathname]=uigetfile({'.jpg';'.png';'.bmp';'.*'});
if isequal(filename,0)||isequal(pathname,0)
errordlg('没有选中文件','错误');
else
file=strcat(pathname,filename);
end
im=imread(file);
I1=im;

%最大类间方差法二值化
level=graythresh(I1);
I2=double(imbinarize(I1,level));

figure(1),
subplot(131),imshow(im,[]);
title('原图像');
subplot(132),imshow(I1,[]);
title('灰度图像');
subplot(133),imshow(I2,[]);
title('二值图像');

%边缘检测
level1=graythresh(double(I2));
a1=double(edge(I2,'canny',level));
figure(2),
imshow(a1,[]);
title('canny算子边缘检测');

%形态学滤波
se=strel('disk',3);
%腐蚀
s=imdilate(a1,se); %腐蚀的作用是消除物体边界点,使目标缩小,可以消除小于结构元素的噪声点
%膨胀
% w=double(w);
t=double(imerode(s,se));
figure(3),
imshow(t,[]);

[r1,c1]=find(t==1);

% %裁剪
% p =imcrop(t,[1,1,abs(211),abs(388)]);
% [r1,c1]=find(p==1);
% num1=length(r1);
%
% w=imcrop(t,[240,24,abs(218),abs(388)]);
% [r2,c2]=find(w==1);
% num2=length(r2);
%
% z=imcrop(t,[450,17,abs(173),abs(388)]);
% [r3,c3]=find(z==1);
% num3=length(r3);

% %最小二乘法
[R1,A1,B1]=circ(r1,c1);
% [R2,A2,B2]=circ(r2,c2);
% [R3,A3,B3]=circ(r3,c3);

theta=0:pi/100:2pi;
x1=A1+R1
cos(theta);
y1=B1+R1*sin(theta);

% x2=A2+R2cos(theta);
% y2=B2+R2
sin(theta);
%
% x3=A3+R3cos(theta);
% y3=B3+R3
sin(theta);

figure(4);
subplot(121),imshow(t,[]);
subplot(122),imshow(t,[]);

hold on;
plot(y1,x1,'r','linewidth',1.5);
axis equal
hold off;

运行结果及报错内容

错误使用 edge
第 1 个输入, I, 应为 二维。

出错 edge>parse_inputs (第 482 行)
validateattributes(I,{'numeric','logical'},{'real','nonsparse','2d'},mfilename,'I',1);

出错 edge (第 213 行)
[a,method,thresh,sigma,thinning,H,kx,ky] = parse_inputs(args{:});

出错 test (第 31 行)
a1=double(edge(I2,'canny',level1));

我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 5月30日
    • 创建了问题 5月22日

    悬赏问题

    • ¥50 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥200 uniapp长期运行卡死问题解决
    • ¥15 latex怎么处理论文引理引用参考文献
    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
    • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?