File Exchange

image thumbnail

Image Resize

version 1.0 (1.39 KB) by

Another function to resize an image.

7 Downloads

Updated

View License

IMAGERESIZE able to resize an image. You can downsize and also upsize an image using scaling factor.

This is a simple implementation of matlab IMRESIZE code.

Nothing new about this code.

Comments and Ratings (5)

DGM

DGM (view profile)

Yes, using a loop without preallocation means this is terribly slow for what should be the most simple interpolation method (nearest-neighbor).

While simplicity has its place, people looking for a image-resizing tool outside of the Image Processing Toolbox shouldn't think that this reflects the approach used by IMRESIZE.

A faster and more flexible IMRESIZE alternative would be to use INTERP2().

%%%%%%%%%%%%%%
%% set axis scaling
xscale=3
yscale=3

sz=size(img_in);
numchans=size(img_in,3);
yy=linspace(1,sz(1),ceil(sz(1)*yscale));
xx=linspace(1,sz(2),ceil(sz(2)*xscale));

img_out=zeros([ceil(sz(1:2).*[yscale xscale]) 3]);
for c=1:numchans
img_out(:,:,c)=interp2(img_in(:,:,c),xx',yy,'bilinear');
end
%%%%%%%%%%%%%%

This will work on images with any number of channels, and can use different interpolation methods. It also doesn't require any IPT functions.

That's not to imply that my suggested code replicates IMRESZE behavior either.

for loop is not a good idea in matlab, please try vectorizing it.

Wetch

Wetch (view profile)

Dung Luong

Grzegorz Knor

Please pre-allocate the img_out variable to speed up your code.

MATLAB Release
MATLAB 6.5 (R13)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today