【问题标题】:Resize image using imresize gives an error in octave使用 imresize 调整图像大小会导致 octave 错误
【发布时间】:2021-09-19 11:14:24
【问题描述】:

我正在尝试使用 Octave 5.2.0 调整非常小的图像,但我不确定为什么在尝试调整大小时会出错

错误发生在以下行:

img_unique_only = imresize(f2, [640, 480]); %reshape output of unique colors
error: interp2: cubic requires at least 2 points in each dimension
error: called from
    interp2 at line 244 column 9
    imremap at line 65 column 19
    imresize at line 135 column 8
    test_small_resize_question at line 30 column 17 (the last line which is the imresize line)

代码如下:

pkg load image

f(:,:,1)=[0;0;0;0;127;128;128;128];

f(:,:,2)=[0;0;127;128;0;0;0;0];

f(:,:,3)=[127;128;0;0;0;0;127;128];
%%%%%%%%%%%%%%%%-------------------------------------------------------------------------

[im_r im_c]=size(f);
size_min=min(im_r,im_c); %get minum size from row and col
f2=uint8(f)
imshow(f2)

img_unique_only = imresize(f2, [640, 480]); %reshape output of unique colors

使用imshow(f2) 创建下面的图像

img_unique_only = imresize(f2, [640, 480]); %reshape output of unique colors 行不会调整大小

创建的变量:

当使用img_unique_only = imresize(f2, [640, 480], "nearest"); %reshape output of unique colors这一行时

创建的变量:

我得到的是 灰度 图像,而不是 640x480 彩色图像

注意:如果更好,我也愿意尝试其他方式

【问题讨论】:

  • 您有一个只有 1 行的图像。三次插值在每个方向上至少需要 2 个值。你没有它们。你确定它是一个图像?人们不称数组为“图像”。您可以尝试使用不同的插值方法,查看imresize docs。
  • 我添加了一个 uint8 以确保它是一个图像并做了一个 imshow(f2) 我用图像更新了问题
  • uint8 的东西不会使它成为图像呵呵。使它成为图像的唯一原因是您说矩阵是图像。错误很明显,我告诉你如何解决它:使用与默认三次不同的插值技术
  • 我想我错过了一些东西,因为我尝试了nearest, cubic, bilinear, bicubic, linear 示例:img_unique_only = imresize(f2, [640, 480], "nearest"); 最近会生成图像,但它是灰度而不是颜色
  • 最近的size(img_unique_only) 和size(f2) 是什么?其余的很明显,您至少需要 2 个值来插值,并且您没有将它们放在其中一个方向

标签: arrays image image-processing multidimensional-array octave


【解决方案1】:

解决方法是使用cat 注意:它会创建不正确的颜色渐变。

f(:,:,1)=[0;0;0;0;127;128;128;128];
f(:,:,2)=[0;0;127;128;0;0;0;0];
f(:,:,3)=[127;128;0;0;0;0;127;128];

height_wanted=640;
width_wanted=480;

repmat_rgb=cat(2,f,f); %add another column to array to get imresize to work
reshaped_output = imresize(repmat_rgb, [height_wanted, width_wanted],'cubic'); %reshape swatch to large output

imshow(reshaped_output);

更新:2021 年 7 月 19 日 这是 imresize 中的一个错误,以获取更多信息和解决方法 Matrix array to multidimensional RGB image array and using imresize to reshape image

【讨论】:

    猜你喜欢
    • 2018-11-10
    • 1970-01-01
    • 1970-01-01
    • 2014-10-08
    • 1970-01-01
    • 2014-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多