fastDepthSegmentationDSKCF_noiseModel

PURPOSE ^

FASTDEPTHSEGMENTATIONDSKCF_NOISEMODEL.m segments depth data

SYNOPSIS ^

function [L,Cnew,LUT,H,I,LUTCC]=fastDepthSegmentationDSKCF_noiseModel(im,c,nanMatrix,minimumError,Cinit, findPeak,targetDepth,targetSTD,noiseModelVector)

DESCRIPTION ^

 FASTDEPTHSEGMENTATIONDSKCF_NOISEMODEL.m segments depth data
 
   FASTDEPTHSEGMENTATIONDSKCF_NOISEMODEL function applies the fast depth
   segmentation algorithm described in [1]. The segmentation is composed
   by two different stage a fast version of the Kmeans applied to the
   depth data, plus a connected component analysis to refine clusters in
   the image plane. This function was implemented by starting from the
   "Fast segmentation of N-dimensional grayscale images" presented by
   Anton Semechko and shared in the Matlab Central at this link under BSD
   licence
   http://www.mathworks.com/matlabcentral/fileexchange/41967-fast-segmentation-of-n-dimensional-grayscale-images

   INPUT: 
   - im   depth image coded in 16bits, each pixel contains mm data. 
   - c    positive interger greater than 1 specifying the number of
           clusters. c=2 is the default setting. Alternatively, c
           initialized by considering peaks in the depth distribution.
   -nanMatrix  binary mask containing flags for missing depth pixels 
   -minimumError convergence criteria for the Kmeans algorithm
   -histStep histogram bin used to compose depth histogram
   -Cinit initial Kmeans seeds. Set this values to -1 to not initialize
   externally the starting seeds
   -findPeak boolean flag to initialize the Kmeans seed with the peaks in
   the depth distribution 
   -targetDepth,targetSTD  depth mean value and standard deviation of the
   object in the previous frame. THey are used to calculate the noise
   component

   OUTPUT
   - L    label image of the same size as the input image. For example,
           L==i represents the region associated with prototype C(i),
           where i=[1,k] (k = number of clusters).
   - Cnew    1-by-k array of cluster centroids.
   - LUT  L-by-1 array that specifies the intensity-class relations,
           where L is the dynamic intensity range of the input image. 
           Specifically, LUT(1) corresponds to class assigned to 
           min(im(:)) and LUT(L) corresponds to the class assigned to
           max(im(:)). 
   -H histogram's bin height
   -I histogram's bin centers
   -LUTCC the same as LUT but considering also the connected component
   anaylsis

  See also LUT2LABELNANSUPPORT, LUT2LABELNANSUPPORTCC, CALCULATENOISEVAR,
  CHECKOCCLUSIONSDSKCF_NOISEMODEL, SINGLEFRAMEDSKCF,
  CHECKOCCLUSIONSDSKCF_SECONDPLANE

 [1] S. Hannuna, M. Camplani, J. Hall, M. Mirmehdi, D. Damen, T.
 Burghardt, A.Paiement, L. Tao, DS-KCF: A ~real-time tracker for RGB-D
 data, Journal of Real-Time Image Processing


  University of Bristol
  Massimo Camplani and Sion Hannuna

  massimo.camplani@bristol.ac.uk
  hannuna@compsci.bristol.ac.uk

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [L,Cnew,LUT,H,I,LUTCC]=fastDepthSegmentationDSKCF_noiseModel(im,c,nanMatrix,minimumError,Cinit, findPeak,targetDepth,targetSTD,noiseModelVector)
0002 % FASTDEPTHSEGMENTATIONDSKCF_NOISEMODEL.m segments depth data
0003 %
0004 %   FASTDEPTHSEGMENTATIONDSKCF_NOISEMODEL function applies the fast depth
0005 %   segmentation algorithm described in [1]. The segmentation is composed
0006 %   by two different stage a fast version of the Kmeans applied to the
0007 %   depth data, plus a connected component analysis to refine clusters in
0008 %   the image plane. This function was implemented by starting from the
0009 %   "Fast segmentation of N-dimensional grayscale images" presented by
0010 %   Anton Semechko and shared in the Matlab Central at this link under BSD
0011 %   licence
0012 %   http://www.mathworks.com/matlabcentral/fileexchange/41967-fast-segmentation-of-n-dimensional-grayscale-images
0013 %
0014 %   INPUT:
0015 %   - im   depth image coded in 16bits, each pixel contains mm data.
0016 %   - c    positive interger greater than 1 specifying the number of
0017 %           clusters. c=2 is the default setting. Alternatively, c
0018 %           initialized by considering peaks in the depth distribution.
0019 %   -nanMatrix  binary mask containing flags for missing depth pixels
0020 %   -minimumError convergence criteria for the Kmeans algorithm
0021 %   -histStep histogram bin used to compose depth histogram
0022 %   -Cinit initial Kmeans seeds. Set this values to -1 to not initialize
0023 %   externally the starting seeds
0024 %   -findPeak boolean flag to initialize the Kmeans seed with the peaks in
0025 %   the depth distribution
0026 %   -targetDepth,targetSTD  depth mean value and standard deviation of the
0027 %   object in the previous frame. THey are used to calculate the noise
0028 %   component
0029 %
0030 %   OUTPUT
0031 %   - L    label image of the same size as the input image. For example,
0032 %           L==i represents the region associated with prototype C(i),
0033 %           where i=[1,k] (k = number of clusters).
0034 %   - Cnew    1-by-k array of cluster centroids.
0035 %   - LUT  L-by-1 array that specifies the intensity-class relations,
0036 %           where L is the dynamic intensity range of the input image.
0037 %           Specifically, LUT(1) corresponds to class assigned to
0038 %           min(im(:)) and LUT(L) corresponds to the class assigned to
0039 %           max(im(:)).
0040 %   -H histogram's bin height
0041 %   -I histogram's bin centers
0042 %   -LUTCC the same as LUT but considering also the connected component
0043 %   anaylsis
0044 %
0045 %  See also LUT2LABELNANSUPPORT, LUT2LABELNANSUPPORTCC, CALCULATENOISEVAR,
0046 %  CHECKOCCLUSIONSDSKCF_NOISEMODEL, SINGLEFRAMEDSKCF,
0047 %  CHECKOCCLUSIONSDSKCF_SECONDPLANE
0048 %
0049 % [1] S. Hannuna, M. Camplani, J. Hall, M. Mirmehdi, D. Damen, T.
0050 % Burghardt, A.Paiement, L. Tao, DS-KCF: A ~real-time tracker for RGB-D
0051 % data, Journal of Real-Time Image Processing
0052 %
0053 %
0054 %  University of Bristol
0055 %  Massimo Camplani and Sion Hannuna
0056 %
0057 %  massimo.camplani@bristol.ac.uk
0058 %  hannuna@compsci.bristol.ac.uk
0059 
0060 % Default input arguments
0061 if nargin<2 || isempty(c), c=2; end
0062 
0063 % Basic error checking
0064 if nargin<1 || isempty(im)
0065     error('Insufficient number of input arguments')
0066 end
0067 msg='Revise variable used to specify class centroids. See function documentaion for more info.';
0068 if ~isnumeric(c) || ~isvector(c)
0069     error(msg)
0070 end
0071 if numel(c)==1 && (~isnumeric(c) || round(c)~=c || c<2)
0072     error(msg)
0073 end
0074 
0075 % Check image format
0076 if isempty(strfind(class(im),'int'))
0077     error('Input image must be specified in integer format (e.g. uint8, int16)')
0078 end
0079 if sum(isnan(im(:)))~=0 || sum(isinf(im(:)))~=0
0080     error('Input image contains NaNs or Inf values. Remove them and try again.')
0081 end
0082 
0083 
0084 histStep=max(2.5*calculateNoiseVar(targetDepth,noiseModelVector(1),noiseModelVector(2),noiseModelVector(3)),targetSTD);
0085 
0086 newPointSet=im(~nanMatrix);
0087 Imin=double(min(newPointSet));
0088 Imax=double(max(newPointSet));
0089 I=(Imin:histStep:Imax)';
0090 if(isempty(I))
0091     L=[];
0092     Cnew=[];
0093     LUT=[];
0094     H=[];
0095     I=[];
0096     LUTCC=[];
0097     return
0098 end
0099 
0100 if(I(end)~=Imax || length(I)==1)
0101     I(end+1)=Imax+histStep;
0102 end
0103 I=I(:);
0104 % Compute intensity histogram
0105 H=hist(double(newPointSet),I);
0106 H=H(:);
0107 maxValue=max(H);
0108 
0109 minPeakDistParam=3;
0110 if(length(I)<50)
0111    minPeakDistParam=2;
0112 end
0113 
0114 [peakDepth,posPeak]=findpeaks([0; H ;0],'MINPEAKDISTANCE',minPeakDistParam,'MINPEAKHEIGHT',0.005*maxValue);
0115 
0116 % Initialize cluster centroids
0117 if numel(c)>1
0118     C=c;
0119     c=numel(c);
0120 else
0121     dI=(Imax-Imin)/c;
0122     if(isempty(Cinit))
0123         C=Imin+dI/2:dI:Imax;
0124     else
0125         C=Cinit;
0126     end
0127 end
0128 
0129 if(findPeak)
0130     if(length(C)==length(posPeak) && C(1)==-1);
0131         C=I(posPeak-1);
0132     elseif (length(C)~=length(posPeak))
0133         c=length(posPeak);
0134         C=I(posPeak-1);
0135     end
0136     C=C';
0137 end
0138 
0139 
0140 
0141 % Update cluster centroids
0142 IH=I.*H; dC=Inf;
0143 
0144 C0=C;
0145 Citer=C;
0146 while dC>minimumError
0147     
0148     Citer=C;
0149     
0150     % Distance to the centroids
0151     D=abs(bsxfun(@minus,I,C));
0152     
0153     % Classify by proximity
0154     [Dmin,LUT]=min(D,[],2); %#ok<*ASGLU>
0155     for j=1:c
0156         C(j)=sum(IH(LUT==j))/sum(H(LUT==j));
0157         if(isnan(C(j)))
0158             C(j)=Citer(j);
0159         end
0160     end
0161       
0162     % Change in centroids
0163     dC=max(abs(C-Citer));
0164     
0165 end
0166 
0167 %%correct singleton peaks
0168 if(length(C)==1)
0169     C=I(posPeak-1);
0170 end
0171 
0172 [L,Cnew,LUTCC]=LUT2labelNanSupportCC(im,LUT,nanMatrix,histStep,C);
0173

Generated on Thu 24-Nov-2016 18:03:21 by m2html © 2005