我在MATLAB中裁剪图像时遇到了麻烦。代码如下:
n = 128;
% M0 = rescale(imcrop(x_gray,n));
[xx, xy] = size(x_gray);
M0 = rescale(imcrop(x_gray, 1, 1, n, n));
x_gray的大小是384x512:
>> size(x_gray)
ans =
384 512
imcrop()给出以下错误:
Attempted to access spatial_rect(4); index out
of bounds because numel(spatial_rect)=1.
Error in imcrop (line 128)
pixelHeight = spatial_rect(4) *
pixelsPerVerticalUnit;
为什么索引超出范围? imcrop的语法是:
B = imcrop(A,[xmin ymin width height]);
答案 0 :(得分:2)
我收到与您相同的错误,因为您使用的语法不正确。将矩形的坐标(即1,1,n,n)放在方括号内,它应该起作用:
M0 = rescale(imcrop(x_gray, [1 1 n n]));