Blame view

rtsEnviClassify.m 876 Bytes
8be1ab93   David Mayerich   initial commit of...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  function C = rtsEnviClassify(B, envi_filename, mask, nFeatures)
  
  %   B = TreeBagger class
  %   nFeatures = number of features cropped out (0 means use all features)
  
  if nargin < 4
      nFeatures = 0;
  end
  
  
  batchSize = 100000;
  
  
  
  Ns = nnz(mask)    %get the number of samples to be classified
  Nb = ceil(Ns / batchSize);  %get the number of batches
  
  C(Ns, 1) = char(0);
  
  %open the ENVI file
  envi = rtsEnviOpen(envi_filename, [envi_filename '.hdr'], mask);
  
  for b = 1:Nb
      
      %load a batch
      batch = rtsEnviRead(envi, batchSize);
      
      %crop out the number of features specified (if it is specified)
      if nFeatures ~= 0
          batch = batch(1:nFeatures, :);
      end
      
      %classify the batch
      C( (b-1)*batchSize + 1 : (b-1)*batchSize + size(batch, 2) ) = cell2mat(predict(B, batch'));
      
      disp([num2str( round( b / Nb * 100 ) ) '%']);
  end
  
  rtsEnviClose(envi);