繁体   English   中英

我在Matlab中是新手。 所以我需要帮助。 我尝试执行此编码,但有此错误

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM