image resampling

This is a simple function that resamples the image at a different pixel size


Updated Mon, 06 Sep 2010 22:24:15 +0000

View License

function nimg = imresample(oldpixsize,img,newpixsize,intmethod)

% This function resamples the images at the new grid points
% defined by the new pixel sizes. It assumes that intensities are
% defined at pixel centers
% img : original image to be resampled
% nimg : newly sampled image
% oldpixsize : a vector of the form [xpixsize, ypixsize]
% for the original image, e.g., [0.5,0.5]
% newpixsize : is a vector of the form [xpixsize, ypixsize]
% for the new image, e.g., [0.2,0.2]
% intmethod: same as interp2
% 'nearest' - nearest neighbor
% 'linear' - bilinear
% 'cubic' - bicubic
% 'spline' - spline

% Example:
% % Create a 2D gaussian function
% H = fspecial('gaussian',[31,31],5);
% % Resample it at a smaller pixel size
% NH = imresample([1,1],H,[0.2,0.2],'spline');
% figure;subplot(211);imshow(H,[]);title('Original');
% subplot(212);imshow(NH,[]);
% title('Resampled using spline interplolation');

Cite As

Omer Demirkaya (2023). image resampling (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R14SP3
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on Images in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

It is modified so it can resample multispectral (e.g., color) images.

It is just reuploading nothing new.

I just added an example image. The image is kindly provided by William Samson and a nice example to show resampling.