微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

我正在尝试使用 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,480]); %reshape output of unique colors

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

this post

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

创建的变量:

img1

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

创建的变量:

img2

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

imgg

注意:如果更好,我也愿意尝试另一种方式

解决方法

解决方法是使用 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);

img

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。