I am using IMRESIZE with either the 'bilinear' or 'bicubic' interpolation method. If I input an image that is in the range [0,1], the output image sometimes falls outside of this range. Here is an example that reproduces the situation:
% Create an arbitrary matrix, and normalize it
img=magic(250);imgi=img/max(img(:));% Resize the image
imgo=imresize(imgi,[180,180],'bilinear');% Show the results
disp(sprintf('Input min = %g. Input max = %g.',min(imgi(:)),max(imgi(:))))disp(sprintf('Ouput min = %g. Output max = %g.',min(imgo(:)),max(imgo(:)))) Input min = 1.6e-005. Input max = 1. Ouput min = -0.0563929. Output max = 1.0631.
This could potentially cause problems with TrueColor (mxnx3) images, because if I then use IMSHOW (as in the code below), I get the following error:
% Create an arbitrary TrueColor image matrix, and normalize it
img=repmat(magic(250),[1 1 3]);imgi=img/max(img(:));% Resize the imageimgo=imresize(imgi,[180,180],'bilinear');% Show the resultsdisp(sprintf('Input min = %g. Input max = %g.',min(imgi(:)),max(imgi(:))))disp(sprintf('Ouput min = %g. Output max = %g.',min(imgo(:)),max(imgo(:))))% Display the resized image
imshow(imgo)
??? Error using ==> image TrueColor CData contains element out of range 0.0 <= value <= 1.0. Error in ==> D:\Applications\MATLAB6p5\toolbox\images\images\imshow.m On line 104 ==> hh = image(xdata, ydata, cdata, 'BusyAction', 'cancel', ...
Best Answer