============================================================== AVERAGE_SMOOTH: Given sequence of 1D data and window size 5, say [1,2,4,2,1] it will do the averaging and assign it to the centre position as it parses the image. Code written by Katherine Smith, 2003 GENERAL new_images = average_smooth(images, window) INPUT/S -images: Input images. -window: Scope of averaging or a type of 1-D mask. OUTPUT/S -new_images: The images with average smooth applied. PENDING WORK -Add a few comments to file. KNOWN BUG/S -None. COMMENT/S -Is a similar function available elsewhere already? RELATED FUNCTION/S GAUSSIAN_SMOOTH ABOUT -Created: November 23rd, 2003 -Last update: Novermber 25th, 2003 -Revision: 0.0.2 -Author: R. S. Schestowitz, University of Manchester ==============================================================
0001 function new_images = average_smooth(images, window) 0002 % ============================================================== 0003 % AVERAGE_SMOOTH: Given sequence of 1D data and window size 5, 0004 % say [1,2,4,2,1] it will do the averaging and 0005 % assign it to the centre position as it parses 0006 % the image. 0007 % 0008 % Code written by Katherine Smith, 2003 0009 % 0010 % GENERAL 0011 % 0012 % new_images = average_smooth(images, window) 0013 % 0014 % INPUT/S 0015 % 0016 % -images: 0017 % Input images. 0018 % 0019 % -window: 0020 % Scope of averaging or a type of 1-D mask. 0021 % 0022 % OUTPUT/S 0023 % 0024 % -new_images: 0025 % The images with average smooth applied. 0026 % 0027 % PENDING WORK 0028 % 0029 % -Add a few comments to file. 0030 % 0031 % KNOWN BUG/S 0032 % 0033 % -None. 0034 % 0035 % COMMENT/S 0036 % 0037 % -Is a similar function available elsewhere already? 0038 % 0039 % RELATED FUNCTION/S 0040 % 0041 % GAUSSIAN_SMOOTH 0042 % 0043 % ABOUT 0044 % 0045 % -Created: November 23rd, 2003 0046 % -Last update: Novermber 25th, 2003 0047 % -Revision: 0.0.2 0048 % -Author: R. S. Schestowitz, University of Manchester 0049 % ============================================================== 0050 0051 0052 if(mod(window,2)~=1) % if even (not odd) sized window 0053 error('Window must be an odd number'); 0054 return; % leave with no smoothing applied 0055 end 0056 images_width = size(images, 1); % extract width of images 0057 border = floor((window-1)/2); % find middle position of window 0058 new_images = zeros(size(images)); % create fully black image, sized as images 0059 for i = 1:images_width % for each pixel along the width (1-D data) 0060 if ((i < border+1) | (i > images_width-border)) % if below middle or beyond middle 0061 new_images(i,:) = images(i,:); % copy pixel 0062 else 0063 new_images(i,:) = mean(images(i-border:i+border,:)); 0064 % if in middle, set average of the whole line 0065 end 0066 end