[英]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);
I have run this code and get this error " Index exceeds matrix dimensions. 我已运行此代码并得到此错误“索引超出矩阵尺寸。
Error in ==> croptry at 10 I = I(i3_start:i3_stop, i4_start:i4_stop, :);" “ ==>农田在10 I = I时出错(i3_start:i3_stop,i4_start:i4_stop,:);”
Can anybody help me to fix this error? 有人可以帮我解决此错误吗? I want to crop image at the center 我想在中心裁剪图像
The error is probably due to the way you call the functin size
. 该错误可能是由于您调用functin size
的方式引起的。
If the matrix I
in which you load the image is tri-dimensional (N x M x K), you have to call size
this way: 如果I
在其中加载图像的矩阵I
是三维的(N x M x K),则必须以这种方式调用size
:
[p3, p4, p5] = size(I)
that is, by adding an additional parameter (in that case "p5"). 也就是说,通过添加一个附加参数(在这种情况下为“ p5”)。
If you call size
as: 如果您将size
称为:
[p3, p4] = size(I)
p4 will be set to the product of the second and third dimension of your matrix I
p4将设置为矩阵I
的第二维和第三维的乘积
Updated code 更新的代码
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)
Original Image 原始图片
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.