Attachment 'load_gca.m'

Download

   1 function [gca] = load_gca(fname)
   2 %
   3 % [gca] = load_gca(fname)
   4 % reads an array of gaussian classifiers
   5 %
   6 
   7 
   8 %
   9 % load_gca.m
  10 %
  11 % Original Author: Bruce Fischl
  12 % CVS Revision Info:
  13 %    $Author: nicks $
  14 %    $Date: 2007/01/10 22:55:09 $
  15 %    $Revision: 1.2 $
  16 %
  17 % Copyright (C) 2002-2007,
  18 % The General Hospital Corporation (Boston, MA). 
  19 % All rights reserved.
  20 %
  21 % Distribution, usage and copying of this software is covered under the
  22 % terms found in the License Agreement file named 'COPYING' found in the
  23 % FreeSurfer source code root directory, and duplicated here:
  24 % https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferOpenSourceLicense
  25 %
  26 % General inquiries: freesurfer@nmr.mgh.harvard.edu
  27 % Bug reports: analysis-bugs@nmr.mgh.harvard.edu
  28 %
  29 
  30 GCA_VERSION=4.0;
  31 GCA_NO_MRF=1;
  32 GIBBS_NEIGHBORHOOD=6 ;
  33 GIBBS_NEIGHBORS=GIBBS_NEIGHBORHOOD;
  34 MAX_LABELS=4;
  35 
  36 % open it as a big-endian file
  37 fid = fopen(fname, 'rb', 'b') ;
  38 if (fid < 0)
  39 	 str = sprintf('could not open gca file %s.', fname) ;
  40 	 error(str) ;
  41 end
  42 version = fread(fid, 1, 'float32') ;
  43 if (version < 1 | version > GCA_VERSION)
  44 	 fclose(fid) ;
  45 	 error(sprintf('version %d in file %s incorrect - not a known gca file',version,fname));
  46 end
  47 
  48 prior_spacing = fread(fid, 1, 'float32') ;
  49 node_spacing = fread(fid, 1, 'float32') ;
  50 
  51 prior_width = fread(fid, 1, 'int32') ;
  52 prior_height = fread(fid, 1, 'int32') ;
  53 prior_depth = fread(fid, 1, 'int32') ;
  54 
  55 node_width = fread(fid, 1, 'int32') ;
  56 node_height = fread(fid, 1, 'int32') ;
  57 node_depth = fread(fid, 1, 'int32') ;
  58 
  59 ninputs = fread(fid, 1, 'int32') ;
  60 flags = fread(fid, 1, 'int32') ;
  61 
  62 disp(sprintf('reading gca file %s (%dx%dx%d), spacing=%d, version %.1f', fname, prior_width,prior_height,prior_depth,prior_spacing,version)) ;
  63 
  64 gca = zeros(prior_width*prior_height*prior_depth, 2*MAX_LABELS+1) ;
  65 
  66 index = 1 ;
  67 for x=1:node_width
  68 %		disp(sprintf('reading slice %d of %d', x, node_width)) ;
  69 		for y=1:node_height
  70 				for z=1:node_depth
  71 						nlabels = fread(fid, 1, 'int32') ;
  72 						total_training = fread(fid, 1, 'int32') ;
  73 %						gca(index,1) = nlabels ;
  74 
  75 						for n=1:nlabels
  76 								label = fread(fid, 1, 'uchar') ;
  77 								mean = fread(fid, 1, 'float32') ;
  78 								var = fread(fid, 1, 'float32') ;
  79 								if (bitand(flags, GCA_NO_MRF))
  80 									continue ;
  81 							  end
  82 								for i=1:GIBBS_NEIGHBORS
  83 										gibbs_nlabels = fread(fid, 1, 'uint32') ;
  84 										for j=1:gibbs_nlabels
  85 												gibbs_label = fread(fid, 1, 'uint32') ;
  86 												gibbs_prior = fread(fid, 1, 'float32') ;
  87 										end
  88 								end
  89 						end
  90 						index = index+1 ;
  91 				end
  92 		end
  93 end
  94 
  95 
  96 index = 1 ;
  97 for x=1:prior_width
  98 		disp(sprintf('reading slice %d of %d', x, prior_width)) ;
  99 		for y=1:prior_height
 100 				for z=1:prior_depth
 101 						nlabels = fread(fid, 1, 'int32') ;
 102 						total_training = fread(fid, 1, 'int32') ;
 103 						gca(index,1) = nlabels ;
 104 
 105 						if (x == prior_width/2 & y==prior_height/2 & z==prior_depth/2)
 106 %							 keyboard ;
 107 						end
 108 						for n=1:nlabels
 109 								label = fread(fid, 1, 'uchar') ;
 110 								prior = fread(fid, 1, 'float32') ;
 111 								if (n <= MAX_LABELS)
 112 									gca(index,2*n) = label ;
 113 									gca(index,2*n+1) = prior ;
 114 								end
 115 						end
 116 						index = index+1 ;
 117 				end
 118 		end
 119 end
 120 
 121 fclose(fid) ;

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2009-01-26 22:35:31, 625.2 KB) [[attachment:gca.c]]
  • [get | view] (2009-01-26 22:35:31, 19.3 KB) [[attachment:gca.h]]
  • [get | view] (2009-01-26 22:35:31, 3.1 KB) [[attachment:load_gca.m]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.