function [Croc, Cauc] = rtsEnviRandomForest2C_validate(RF, EnviFileName, EnviHeaderName, RoiImages, reference) %Validates a 2-class random forest classifier, creating ROC curves. %parameters maxPixels = 200000; %determine the number of classes nClasses = length(RoiImages); %make sure that there are only two classes if nClasses > 2 disp('This classifier only supports 2 classes.'); return; end %for each class, load the validation data T = []; F = []; for c = 1:nClasses %load the class mask maskImage = imread(RoiImages{c}); maskBinary = (maskImage(:, :, 1) > 0)'; disp('------------------------------------------------------'); %load epithelium spectra disp(['Loading Validation Class ' num2str(c) ' pixels: ' EnviFileName]); tLoadTime = tic; fid = rtsEnviOpen(EnviFileName, EnviHeaderName, maskBinary); Fc = rtsEnviRead(fid, maxPixels); rtsEnviClose(fid); if c == 1 Tc = ones(size(Fc, 2), 1); else Tc = zeros(size(Fc, 2), 1); end disp(['Time: ' num2str(toc(tLoadTime)) 's']); %add features and targets to the final vectors T = [T; Tc]; F = [F; Fc']; end %apply the reference if nargin == 5 Fnorm = repmat(F(:, reference), 1, size(F, 2)); F = F./Fnorm; F(:, reference) = []; end %classify the data (get the estimated posterior probability) disp('Validating...'); tClassTime = tic; Tpost = predict(RF, F); disp(['Time: ' num2str(toc(tClassTime)) 's']); %calculate and display the ROC curve disp('Calculating ROC...'); tRocTime = tic; [Croc, Cauc, threshList] = rtsROC(Tpost, T); disp(['Time: ' num2str(toc(tRocTime)) 's']); disp(['AUC = ' num2str(Cauc)]); plot(Croc(:, 1), Croc(:, 2));