function [cim,nfiles]=generatecalimage(basefilename) % [CIM,NFILES] = GENERATECALIMAGE(BASEFILENAME, N) % This function loads a sequence of .bmp files starting with basefilename % (i.e. basefilename='file', seq=['file0.bmp','file1.bmp', ...]), % extracts the red plane only (:,:,1), converts each to a double, and % adds them all together to produce aggregate calibration image CIM. % Note all images must be three planes deep (red,green,blue) and all % must be the same size. The total number of files used is returned % as NFILES. cim=0; num=0; while 1, fname = strcat(basefilename,sprintf('%d',num),'.bmp'); clear im; if exist(fname,'file'), fprintf(1,'Reading %s...\n', fname); im = imread(fname,'bmp'); im=double(im(:,:,1)); cim = cim + im; num = num + 1; else nfiles = num; return; end end