function ROC ( X, GoodToBad, xAxis, lineattr ) % % function ROC ( X, GoodToBad, xAxis ) - plots a ROC curve. % % % % Input data: % % X N x 2 This is the main input variable. The first column % contains the score of each image, the second column contains the % labels. Noise (images that don't contain the % object) is labeled with 0, signal (images that % contain the object) is labeled with k > 0. Noise % is supposed to have a low score, signal is % supposed to have a high score. N is the number of % samples. % %%%%%% % % GoodToBad scalar Allows to rescale the ratio of signal and noise samples. Just % put 1 here if you're not sure. % % xAxis 2 x 1 The range for the x-axis. This allows to close in or zoom out. % Put [0 1] if you are not sure. % % lineattr string These are the attributes that will be used for the ROC curve. Use % this if you want to plot several curves in the same plot. % % % (c) 1997 by California Institute of Technology % % Markus Weber % % edited P.Moreels, 2004. if nargin < 4, lineattr = 'r-'; end if nargin == 1 GoodToBad = 1; xAxis = [0 1]; end N_SAMPLES = size(X, 1); N_SIGNAL = length(find(X(:, 2))); N_NOISE = N_SAMPLES - N_SIGNAL; [D, I] = sort(rand(N_SAMPLES, 1)); X = X(I, :); [D, I] = sort(X(:, 1)); X = flipud(X(I, :)); P = cumsum([ (X(:, 2) > 0) / N_SIGNAL, (X(:, 2) == 0) / N_NOISE ]); P = [0 0;P]; plot(P(:, 2) * 1/GoodToBad, P(:, 1), lineattr); grid; set(gca, 'xtick', xAxis(1):(xAxis(2) - xAxis(1)) / 5:xAxis(2), 'ytick', 0:0.1:1); axis ([xAxis(:)', 0 1 ]); xlabel('false alarm rate'); ylabel('detection rate'); title('ROC curve');