normalizeImage - linearly normalize an array. res = normalizeImage(data); Linearly normalize data between 0 and 1. res = normalizeImage(img,range); Lineary normalize data between range(1) and range(2) instead of [0,1]. The special value range = [0 0] means that no normalization is performed, i.e., res = img.
0001 % normalizeImage - linearly normalize an array. 0002 % 0003 % res = normalizeImage(data); 0004 % Linearly normalize data between 0 and 1. 0005 % 0006 % res = normalizeImage(img,range); 0007 % Lineary normalize data between range(1) and range(2) 0008 % instead of [0,1]. The special value range = [0 0] 0009 % means that no normalization is performed, i.e., res = img. 0010 0011 % This file is part of the SaliencyToolbox - Copyright (C) 2006-2008 0012 % by Dirk B. Walther and the California Institute of Technology. 0013 % See the enclosed LICENSE.TXT document for the license agreement. 0014 % More information about this project is available at: 0015 % http://www.saliencytoolbox.net 0016 0017 function res = normalizeImage(img,varargin) 0018 0019 if (length(varargin) >= 1) range = varargin{1}; 0020 else range = [0,1]; end 0021 0022 if ((range(1) == 0) & (range(2) == 0)) 0023 res = img; 0024 return; 0025 end 0026 0027 mx = max(img(:)); 0028 mn = min(img(:)); 0029 0030 if (mx == mn) 0031 res = img - mx + 0.5*sum(range); 0032 else 0033 res = (img - mn) / (mx - mn) * abs(range(2)-range(1)) + min(range); 0034 end