function Iout = imnormalize(I,minr,maxr)

% normalizes the image so that its range becomes [minr maxr]
minx = min(I(:));
maxx = max(I(:));

% Iout = uint8(255*(I-minx)/(maxx-minx));
Iout = double((maxr-minr)*(I-minx)/(maxx-minx)+minr);