function myimstat(filename) %MYIMSTAT Basic image statistics. % %MYIMSTAT(FILENAME) computes basic image statistics (minimum, maximum, %mean, standard deviation) and stores the results in a matfile. % % Thorsten Hansen 2008-04-18 % extract name w/o extension [pathstr name ext versn] = fileparts(filename); matfilename = [name '-mystat.mat']; % load matfile if it exists, else compute statistics and store in matfile if exist(matfilename) disp(['Load data from file ''' matfilename '''.']) load(matfilename) else if exist(filename) I = imread(filename); I = im2double(I); Iv = I(:); % flatten to compute global min, max etc. min_I = min(Iv); max_I = max(Iv); mean_I = mean(Iv); std_I = std(Iv); save(matfilename, 'min_I', 'max_I', 'mean_I', 'std_I') disp(['Data written to ''' matfilename '''.']) else error(['Filename ''' filename ''' does not exist.']) end end % display results disp(['Mean: ' num2str(mean_I) '+/-' num2str(std_I) '; ' ... 'min: ' num2str(min_I) ', max: ' num2str(max_I)])