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);