【问题标题】:im newbie in matlab. so i need help. im try do this coding but have this error我是matlab的新手。所以我需要帮助。我尝试做这个编码,但有这个错误
【发布时间】:2015-10-10 17:45:17
【问题描述】:
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, :);"

谁能帮我解决这个错误?我想在中心裁剪图像

【问题讨论】:

    标签: matlab image-processing handwriting-recognition


    【解决方案1】:

    这个错误可能是由于你调用函数size的方式造成的。

    如果您加载图像的矩阵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)
    

    原图

    裁剪图像 希望这会有所帮助。

    【讨论】:

    • 非常感谢您帮助我解决此错误。有用。谢谢你
    • 不客气!很高兴我对你有用。也许您可能想接受关闭问题的答案:-)
    • @user5405704 考虑接受答案为有效 ;) meta.stackexchange.com/questions/5234/…
    • @il_raffa 已经使用去噪器来平滑图像,但我不知道编码。你能帮帮我吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-06
    • 2021-12-05
    • 2014-10-14
    • 2022-08-16
    相关资源
    最近更新 更多