简体   繁体   English

使用 imresize 调整图像大小会导致八度误差

[英]Resize image using imresize gives an error in octave

I'm trying to resize a very small image using Octave 5.2.0 but I'm not sure why it's giving an error when trying to resize it我正在尝试使用 Octave 5.2.0 调整非常小的图像大小,但我不确定为什么在尝试调整大小时会出错

The error happens with the line below:错误发生在下面的行中:

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)

Code Below:代码如下:

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

Using imshow(f2) creates the image below使用imshow(f2)创建下面的图像

图像1

The Line img_unique_only = imresize(f2, [640, 480]); %reshape output of unique colors该行img_unique_only = imresize(f2, [640, 480]); %reshape output of unique colors img_unique_only = imresize(f2, [640, 480]); %reshape output of unique colors won't resize it img_unique_only = imresize(f2, [640, 480]); %reshape output of unique colors不会调整它的大小

Variables created:创建的变量:

图像2

When using the line img_unique_only = imresize(f2, [640, 480], "nearest"); %reshape output of unique colors当使用img_unique_only = imresize(f2, [640, 480], "nearest"); %reshape output of unique colors img_unique_only = imresize(f2, [640, 480], "nearest"); %reshape output of unique colors

Variables created:创建的变量:

imgg

I get a gray scale image instead of a 640x480 color image我得到的是灰度图像而不是640x480 彩色图像

img3

Note: I'm also willing to try another way if better注意:如果更好,我也愿意尝试另一种方式

A work around is to use cat Note: it creates a gradient of colors that aren't correct.解决方法是使用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);

图片

Update: July 19 2021 It's a bug in imresize for more info and workaround Matrix array to multidimensional RGB image array and using imresize to reshape image更新:2021 年 7 月 19 日这是 imresize 中的一个错误,以获取更多信息和解决方法矩阵数组到多维 RGB 图像数组并使用 imresize 来重塑图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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