function Inew = resample(I,rate)

[Ny,Nx] = size(I);
Nx_new  = round(Nx/rate);

I    = im2double(I);
Inew = zeros(Ny,Nx_new);

Inew(:,1) = I(:,1);       % first column
Inew(:,Nx_new) = I(:,Nx); % last column
% intermediate columns:
for x_new = 2:(Nx_new-1)
  x  = x_new*rate; 
  xx = floor(x);
  Inew(:,x_new) = I(:,xx)*(1-(x-xx)) + I(:,xx+1)*(x-xx); % linear interpolation
end
