Home > bioelectromagnetism > LoadAVWObjectMap.m

LoadAVWObjectMap

PURPOSE ^

objectmap = LoadAVWObjectMap ( Filename )

SYNOPSIS ^

function objectmap = LoadAVWObjectMap ( Filename )

DESCRIPTION ^

 objectmap = LoadAVWObjectMap ( Filename )
 Load the objectmap given by Filename.  Returns a structure
 containing the map (as field Image), and a list of objects (as
 field Objects)

 NOTE: Matlab versions have an offset of 1, i.e. the 1-based
 indexing of Matlab applies to the objectmap.Image as well as the
 objectmap.Objects.  That is objectmap.Objects(1) is defined as
 all the voxels in objectmap.Image == 1

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function objectmap = LoadAVWObjectMap ( Filename )
0002 % objectmap = LoadAVWObjectMap ( Filename )
0003 % Load the objectmap given by Filename.  Returns a structure
0004 % containing the map (as field Image), and a list of objects (as
0005 % field Objects)
0006 %
0007 % NOTE: Matlab versions have an offset of 1, i.e. the 1-based
0008 % indexing of Matlab applies to the objectmap.Image as well as the
0009 % objectmap.Objects.  That is objectmap.Objects(1) is defined as
0010 % all the voxels in objectmap.Image == 1
0011 
0012   % Filename = 'BWLabelsHippocampus.obj';
0013 
0014 objectmap = struct ( 'Version', -1 );  
0015   
0016 fid = fopen ( Filename, 'r', 'b');
0017 if fid < 0,
0018   error ( ['Can not open ' Filename ' for reading'] );
0019 end
0020 
0021 objectmap.Version = fread ( fid, 1, 'int' );
0022 if objectmap.Version ~= 910926
0023   error ( ['Unknown ObjectMap version: ' int2str(objectmap.Version) ' expected 910926'] );
0024 end
0025 
0026 objectmap.Width = fread ( fid, 1, 'int' );
0027 objectmap.Height = fread ( fid, 1, 'int' );
0028 objectmap.Depth = fread ( fid, 1, 'int' );
0029 objectmap.NumberOfObjects = fread ( fid, 1, 'int' );
0030 
0031 for o = 1:objectmap.NumberOfObjects
0032   Object = struct ( 'Name', 'Foo' );
0033   Object.Name = char(fread ( fid, 32, 'uchar' ));
0034   Object.Name = sscanf ( Object.Name, '%s' );
0035   Object.Display = fread ( fid, 1, 'int' );
0036   Object.Copy = fread ( fid, 1, 'uchar' );
0037   Object.Mirror = fread ( fid, 1, 'uchar' );
0038   Object.Status = fread ( fid, 1, 'uchar' );
0039   Object.NUsed = fread ( fid, 1, 'uchar' );
0040   Object.Shades = fread ( fid, 1, 'int' );
0041   Object.StartRed = fread ( fid, 1, 'int' );
0042   Object.StartGreen = fread ( fid, 1, 'int' );
0043   Object.StartBlue = fread ( fid, 1, 'int' );
0044   Object.EndRed = fread ( fid, 1, 'int' );
0045   Object.EndGreen = fread ( fid, 1, 'int' );
0046   Object.EndBlue = fread ( fid, 1, 'int' );
0047   Object.XRotation = fread ( fid, 1, 'int' );
0048   Object.YRotation = fread ( fid, 1, 'int' );
0049   Object.ZRotation = fread ( fid, 1, 'int' );
0050   Object.XShift = fread ( fid, 1, 'int' );
0051   Object.YShift = fread ( fid, 1, 'int' );
0052   Object.ZShift = fread ( fid, 1, 'int' );
0053   Object.XCenter = fread ( fid, 1, 'int' );
0054   Object.YCenter = fread ( fid, 1, 'int' );
0055   Object.ZCenter = fread ( fid, 1, 'int' );
0056   Object.XRotationIncrement = fread ( fid, 1, 'int' );
0057   Object.YRotationIncrement = fread ( fid, 1, 'int' );
0058   Object.ZRotationIncrement = fread ( fid, 1, 'int' );
0059   Object.XShiftIncrement = fread ( fid, 1, 'int' );
0060   Object.YShiftIncrement = fread ( fid, 1, 'int' );
0061   Object.ZShiftIncrement = fread ( fid, 1, 'int' );
0062   Object.XMinimum = fread ( fid, 1, 'short' );
0063   Object.YMinimum = fread ( fid, 1, 'short' );
0064   Object.ZMinimum = fread ( fid, 1, 'short' );
0065   Object.XMaximum = fread ( fid, 1, 'short' );
0066   Object.YMaximum = fread ( fid, 1, 'short' );
0067   Object.ZMaximum = fread ( fid, 1, 'short' );
0068   Object.Opacity = fread ( fid, 1, 'float' );
0069   Object.OpacityThickness = fread ( fid, 1, 'int' );
0070   Dummy = fread ( fid, 1, 'int' );
0071   objectmap.Objects(o) = Object;
0072 end
0073 
0074 % Read the rest of the file
0075 Map = fread ( fid, inf, 'uchar' );
0076 % objectmap.RLE = Map;
0077 % Undo RLE
0078 T = zeros ( objectmap.Width, objectmap.Height, objectmap.Depth );
0079 
0080 ImageIndex = 1;
0081 Counts = Map(1:2:end);
0082 Values = Map(2:2:end);
0083 
0084 for idx = 1:length(Counts)
0085   T(ImageIndex:ImageIndex+Counts(idx)-1) = Values(idx) + 1;
0086   ImageIndex = ImageIndex + Counts(idx);
0087 end
0088 
0089 objectmap.Image = zeros ( objectmap.Height, objectmap.Width, objectmap.Depth );
0090 yy = objectmap.Height:-1:1;
0091 for dd = 1:objectmap.Depth
0092   t = T(:,:,dd)';
0093   objectmap.Image(:,:,dd) = t(yy,:);
0094 end
0095 
0096 fclose ( fid );
0097

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003