Home > SaliencyToolbox > gaussianSubsample.m

gaussianSubsample

PURPOSE ^

gaussianSubsample - smooths and subsamples image.

SYNOPSIS ^

function result = gaussianSubsample(img)

DESCRIPTION ^

 gaussianSubsample - smooths and subsamples image.

 result = gaussianSubsample(image)
    Convolves image with a 6x6 separable Gaussian kernel
    and subsamples by a factor of two. 

 See also makeDyadicPyramid, makeSqrt2Pyramid, makeGaussianPyramid, sepConv2PreserveEnergy.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % gaussianSubsample - smooths and subsamples image.
0002 %
0003 % result = gaussianSubsample(image)
0004 %    Convolves image with a 6x6 separable Gaussian kernel
0005 %    and subsamples by a factor of two.
0006 %
0007 % See also makeDyadicPyramid, makeSqrt2Pyramid, makeGaussianPyramid, sepConv2PreserveEnergy.
0008 
0009 % This file is part of the SaliencyToolbox - Copyright (C) 2006-2013
0010 % by Dirk B. Walther and the California Institute of Technology.
0011 % See the enclosed LICENSE.TXT document for the license agreement.
0012 % More information about this project is available at:
0013 % http://www.saliencytoolbox.net
0014 
0015 function result = gaussianSubsample(img)
0016 % need the extra trailing 1 for backward compatibility with the old mex version
0017 % the particular values are also for backward compatibility
0018 filter = [1,5,10,10,5,1,1]; 
0019 filter = filter/sum(filter);
0020 
0021 [h,w] = size(img);
0022 
0023 if min(h,w) > 3
0024   % big image - use straight-forward method
0025   convResult = sepConv2PreserveEnergy(filter,filter,img);
0026   horResult = convResult(:,[2:2:end]-1);
0027   result = horResult([2:2:end]-1,:);
0028 else
0029   % Image is small along at least one dimension.
0030   % Need to treat dimensions separately.
0031 
0032   % Horizontal pass
0033   if w <= 1
0034     % nothing to do
0035     horResult = img;
0036   elseif w == 2
0037     % kernel: [1,1]
0038     horResult = mean(img,2);
0039   elseif w == 3
0040     % kernel: [1,2,1]
0041     horResult = mean(img(:,[1,2,2,3]),2);
0042   else
0043     % horizontal convolution
0044     horResult = sepConv2PreserveEnergy(1,filter,img);
0045 
0046     % horizontal subsampling
0047     horResult = horResult(:,1:2:end-1);
0048   end
0049 
0050   % Vetical pass
0051   if h <= 1
0052     % nothing to do
0053     result = horResult;
0054   elseif h == 2
0055     % kernel: [1,1]
0056     result = mean(horResult,1);
0057   elseif h == 3
0058     % kernel: [1,2,1]
0059     result = mean(horResult([1,2,2,3],:),1);
0060   else
0061     % vertical convolution
0062     verResult = sepConv2PreserveEnergy(filter,1,horResult);
0063 
0064     % vertical subsampling
0065     result = verResult(1:2:end-1,:);
0066   end
0067 end
0068

Generated on Thu 18-Jul-2013 06:10:46 by m2html © 2005