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
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
The Line img_unique_only = imresize(f2, [640, 480]); %reshape output of unique colors
won't resize it
Variables created:
When using the line img_unique_only = imresize(f2, [640, 480], "nearest"); %reshape output of unique colors
Variables created:
I get a gray scale image instead of a 640x480 color image
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.
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