[英]I'm having trouble shuffling a deck of cards in Matlab. Need help to see where I went wrong
[英]im newbie in matlab. so i need help. im try do this coding but have this error
I = imread('data1.jpg')
[p3, p4] = size(I);
q1 = 50; % size of the crop box
i3_start = floor((p3-q1)/2); % or round instead of floor; using neither gives warning
i3_stop = i3_start + q1;
i4_start = floor((p4-q1)/2);
i4_stop = i4_start + q1;
I = I(i3_start:i3_stop, i4_start:i4_stop, :);
figure ,imshow(I);
我已运行此代码并得到此错误“索引超出矩阵尺寸。
“ ==>农田在10 I = I时出错(i3_start:i3_stop,i4_start:i4_stop,:);”
有人可以帮我解决此错误吗? 我想在中心裁剪图像
该错误可能是由于您调用functin size
的方式引起的。
如果I
在其中加载图像的矩阵I
是三维的(N x M x K),则必须以这种方式调用size
:
[p3, p4, p5] = size(I)
也就是说,通过添加一个附加参数(在这种情况下为“ p5”)。
如果您将size
称为:
[p3, p4] = size(I)
p4将设置为矩阵I
的第二维和第三维的乘积
更新的代码
I = imread('pdb_img_1.jpg');
% Modified call to "size"
% [p3, p4] = size(I)
[p3, p4, p5] = size(I)
% Increased the size of the "crop box"
q1 = 150; % size of the crop box
i3_start = floor((p3-q1)/2) % or round instead of floor; using neither gives warning
i3_stop = i3_start + q1
i4_start = floor((p4-q1)/2)
i4_stop = i4_start + q1
I = I(i3_start:i3_stop, i4_start:i4_stop, :);
figure
imshow(I)
原始图片
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.