function annot2dpv(annotfile,dpvfile)
% Convert an annotation file to a DPV file.
%
% Usage:
% annot2dpv(annotfile,dpvfile)
%
% Inputs:
% annotfile : Annotation file.
% dpvfile   : Output DPV file.
%
% Before running, be sure that ${FREESURFER_HOME}/matlab is in your
% OCTAVE/MATLAB path.
%
% _____________________________________
% Anderson M. Winkler
% Yale University / Institute of Living
% Aug/2011

% Read the annotation file
[vtx,lab,ctab] = read_annotation(annotfile);

% For each structure, replace its coded colour by its index
for s = 1:ctab.numEntries,
    lab(lab==ctab.table(s,5)) = s;
end

% Save the result
dpxwrite(dpvfile,lab)
