【问题标题】:Cropping an image with imcrop() in matlab在 matlab 中使用 imcrop() 裁剪图像
【发布时间】:2014-10-20 05:54:57
【问题描述】:

我在 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]);

【问题讨论】:

    标签: image matlab image-processing crop


    【解决方案1】:

    我得到和你一样的错误,因为你使用的语法不正确。将矩形的坐标(即 1,1,n,n)放在方括号内,它应该可以工作:

    M0 = rescale(imcrop(x_gray, [1 1 n n]));
    

    【讨论】:

    • 我还注意到重新缩放不起作用。正确的语法是 M0 = imresize(imcrop(x_gray, [1, 1, n, n]), [xx xy]); . +1 顺便说一句
    • 效果很好!我承认我只是尝试裁剪而不是“重新缩放”我的测试图像;我不确定该功能是否存在。如果它解决了您的问题,您可以将答案标记为“已接受”以便关闭线程吗?谢谢!
    猜你喜欢
    • 2016-12-05
    • 1970-01-01
    • 2013-04-20
    • 2012-02-12
    • 2013-12-26
    • 2013-03-08
    • 2014-03-27
    • 2016-06-12
    相关资源
    最近更新 更多