⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hdr.bff

📁 toolbox of BVQX, This is the access between BV and matlab. It will help you to analysis data from BV
💻 BFF
📖 第 1 页 / 共 2 页
字号:
# BinaryFileFormat (leave this tag as its own magic token!)

# Analyze img/hdr Header format
#
# Version:  v0.7b
# Build:    7090708
# Date:     Sep-07 2007, 8:04 AM CEST
# Author:   Jochen Weber, Brain Innovation, B.V., Maastricht, NL
# URL/Info: http://wiki.brainvoyager.com/BVQXtools

# FILE FORMAT
Description:Analyze header files,NIftI header files
EncodingSyntax:ieee-le
Extensions:hdr,nii
Magic:|
name             |range       |type    |magic
HDR_AnalyzeBE    |  1,   7    |hex     |00, 00, 01, 5c, 64, 73, 72
HDR_AnalyzeLE    |  1,   7    |hex     |5c, 01, 00, 00, 64, 73, 72
HDR_NiFTiMagic   |345, 348    |hex     |6e, 69, 69, 00
HDR_NiFTiMagic_1 |345, 348    |hex     |6e, 69, 31, 00
HDR_NiFTiMagic_pp|345, 348    |hex     |6e, 2b, 31, 00
EndMagic

# FIELDS
ListOfFields:!
type  !cond                   !disktype!datatype!dim                      !default !varname

# correctly handle fixed length strings
BLOOP !$BFFWRITE              ! ! !1 ! !WriteCheckLoop
EXPRE !!!!!!@HdrKey.DataType = zerodstring(@HdrKey.DataType, 10);
EXPRE !!!!!!@HdrKey.DBName = zerodstring(@HdrKey.DBName, 18);
EXPRE !!!!!!try, @HdrKey.Regular = @HdrKey.Regular(1); catch, @HdrKey.Regular = 'r'; end
EXPRE !!!!!!@ImgDim.Dim = [4, 1, 1, 1, 1, 0, 0, 0]; $ndi = ndims(@VoxelData); if $ndi > 4, @ImgDim.Dim(1) = $ndi; end, @ImgDim.Dim(2:1+ndims(@VoxelData)) = size(@VoxelData);
EXPRE !!!!!!@DataHist.Description = zerodstring(@DataHist.Description, 80);
EXPRE !!!!!!@DataHist.AuxFilename = zerodstring(@DataHist.AuxFilename, 24);
EXPRE !!!!!!try, @DataHist.Orientation = @DataHist.Orientation(1); catch, @DataHist.Orientation = int8(0); end
EXPRE !!!!!!if numel(@DataHist.OriginString) > 5, @DataHist.Originator = uint8(@DataHist.OriginString), elseif numel(@DataHist.OriginSPM) == 5 && ~all(@DataHist.OriginSPM == 0), dh = min(65535, max(0, round(@DataHist.OriginSPM(:)'))); @DataHist.Originator = reshape([uint8(dh / 256); uint8(mod(dh, 256))], [1, 10]); if strcmpi(@Endian, 'ieee-le'), @DataHist.Originator = @DataHist.Originator([2:2:10, 1:2:10]); end, end
EXPRE !!!!!!@DataHist.Generated = zerodstring(@DataHist.Generated, 10);
EXPRE !!!!!!@DataHist.ScanNumber = zerodstring(@DataHist.ScanNumber, 10);
EXPRE !!!!!!@DataHist.PatientID = zerodstring(@DataHist.PatientID, 10);
EXPRE !!!!!!@DataHist.ExpiryDate = zerodstring(@DataHist.ExpiryDate, 10);
EXPRE !!!!!!@DataHist.ExpiryTime = zerodstring(@DataHist.ExpiryTime, 10);
EXPRE !!!!!!@DataHist.Hist_UN0 = zerodstring(@DataHist.Hist_UN0, 3);
EXPRE !!!!!!@DataHist.NIftI1.IntentName = zerodstring(@DataHist.NIftI1.IntentName, 16);
EXPRE !!!!!!@DataHist.NIftI1.NIftIMagic = zerodstring(@FileMagic, 4);
EXPRE !!!!!!@IntermedData = @IntermedData(:)'; $IntermediateData = numel(@IntermedData);
ELOOP !                       ! ! !  ! !WriteCheckLoop
EXPRE !$BFFREAD           !!!!!@@ = BVQXfile(0, 'newcont', 'hdr');

# Header fields in HdrKey

# assume le for reading, and re-open file for writing if endian is not ieee-le
EXPRE !!!!!!if $BFFREAD, @Endian = 'ieee-le'; else, if isempty(strfind(lower(@Endian), 'ieee-le')), fclose(fid); fid = fopen([$FILENAME '.tmp'], 'w', 'ieee-be'); end, end

# detect filetype
EXPRE !$BFFREAD           !!!!!fseek(fid, 344, -1); if ftell(fid) ~= 344, error('FILE_TOO_SHORT'); end, @FileMagic = unzerostring(fread(fid, [1, 4], '*char')); fseek(fid, 0, -1);
EXPRE !!!!!!switch(@FileMagic), case{'ni1', 'nii'}, @NIIFileType = 1; case {'n+1'}, @NIIFileType = 2; otherwise, @NIIFileType = 0; end, if $BFFWRITE && @NIIFileType == 2, @ImgDim.VoxOffset = max(@ImgDim.VoxOffset, 348 + numel(@IntermedData)); end

# check endian type, and maybe re-open file
FIELD !                       !uint32  !double  !1, 1                     !348     !HdrKey.SizeOfHdr      # 0x0000, 348
EXPRE !$BFFREAD           !!!!!if @HdrKey.SizeOfHdr > 16777216, fclose(fid); fid = fopen($FILENAME, 'r', 'ieee-be'); fseek(fid, 0, -1); @HdrKey.SizeOfHdr = double(fread(fid, [1, 1], '*uint32')); if @HdrKey.SizeOfHdr > 16777216, error('BAD_ANALYZE_FILE'); end, @Endian = 'ieee-be'; end

# other header fields
FIELD !                       !char    !char    !1, 10                    !        !HdrKey.DataType       # 0x0004, 'dsr' + \0 * 7
FIELD !                       !char    !char    !1, 18                    !        !HdrKey.DBName         # 0x000e, ''    + \0 * 18
FIELD !                       !int32   !double  !1, 1                     !0       !HdrKey.Extents        # 0x0020, 0
FIELD !                       !int16   !double  !1, 1                     !0       !HdrKey.SessionError   # 0x0024, 0
FIELD !                       !char    !char    !1, 1                     !0       !HdrKey.Regular        # 0x0026, 0
FIELD !                       !int8    !int8    !1, 1                     !0       !HdrKey.SliceOrdering  # 0x0027, 0 (NIfTi-1: MRI slice ordering)

# Header fields in ImageDimension
FIELD !                       !int16   !double  !1, 8                     !        !ImgDim.Dim            # 0x0028, e.g. [4 64 64 30 1 0 0 0]
FIELD !                       !single  !double  !1, 1                     !0       !ImgDim.IntentParam1   # 0x0038, ...
FIELD !                       !single  !double  !1, 1                     !0       !ImgDim.IntentParam2   # 0x003c, ...
FIELD !                       !single  !double  !1, 1                     !0       !ImgDim.IntentParam3   # 0x0040, ...
FIELD !                       !int16   !double  !1, 1                     !0       !ImgDim.IntentCode     # 0x0044, ...
FIELD !                       !int16   !double  !1, 1                     !4       !ImgDim.DataType       # 0x0046, 4
FIELD !                       !uint16  !double  !1, 1                     !16      !ImgDim.BitsPerPixel   # 0x0048, 16
FIELD !                       !int16   !double  !1, 1                     !0       !ImgDim.FirstSliceIndex# 0x004a, 0 (NIfTI-1: Slice start)
FIELD !                       !single  !double  !1, 8                     !        !ImgDim.PixSpacing     # 0x004c, e.g. [0 3 3 3.5 0 0 0 0]
FIELD !                       !single  !double  !1, 1                     !0       !ImgDim.VoxOffset      # 0x006c, 0 (348+ for n+1)
FIELD !                       !single  !double  !1, 1                     !1       !ImgDim.ScalingSlope   # 0x0070, 0
FIELD !                       !single  !double  !1, 1                     !0       !ImgDim.ScalingIntercept#0x0074, 0
FIELD !                       !int16   !double  !1, 1                     !0       !ImgDim.LastSliceIndex # 0x0078, 0
FIELD !                       !int8    !int8    !1, 1                     !0       !ImgDim.SliceTimeOrder # 0x007a, 0
FIELD !                       !int8    !int8    !1, 1                     !2       !ImgDim.NIftIUnits      # 0x007b, 0
FIELD !                       !single  !double  !1, 1                     !32767   !ImgDim.CalMaxDisplay  # 0x007c, 32767
FIELD !                       !single  !double  !1, 1                     !-32768  !ImgDim.CalMinDisplay  # 0x0080, -32768
FIELD !                       !single  !double  !1, 1                     !0       !ImgDim.SliceDuration  # 0x0084, 0
FIELD !                       !single  !double  !1, 1                     !0       !ImgDim.SliceTimeOffset# 0x0088, 0
FIELD !                       !int32   !double  !1, 1                     !32767   !ImgDim.GLMax          # 0x008c, 32767
FIELD !                       !int32   !double  !1, 1                     !-32768  !ImgDim.GLMin          # 0x0090, -32768
FIELD !                       !char    !char    !1, 80                    !        !DataHist.Description  # 0x0094, '' + \0 * 80
FIELD !                       !char    !char    !1, 24                    !        !DataHist.AuxFilename  # 0x00e4, '' + \0 * 24
EXPRE !!!!!!@HdrKey.DataType = unzerostring(@HdrKey.DataType);
EXPRE !!!!!!@HdrKey.DBName = unzerostring(@HdrKey.DBName);
EXPRE !!!!!!@DataHist.Description = unzerostring(@DataHist.Description);
EXPRE !!!!!!@DataHist.AuxFilename = unzerostring(@DataHist.AuxFilename);

# # # # # ANALYZE 7.5 START # # # # #

# header fields for DataHistory (Analyze75)
BLOOP !@NIIFileType == 0      ! ! !1 ! !Analyze75
FIELD !                       !int8    !int8    !1, 1                     !        !DataHist.Orientation  # 0x00fc, 'n'
FIELD !                       !uint8   !uint8   !1, 10                    !        !DataHist.Originator   # 0x00fd
FIELD !                       !char    !char    !1, 10                    !        !DataHist.Generated    # 0x0107, '' + \0 * 10
FIELD !                       !char    !char    !1, 10                    !        !DataHist.ScanNumber   # 0x0111, '' + \0 * 10
FIELD !                       !char    !char    !1, 10                    !        !DataHist.PatientID    # 0x011b, '' + \0 * 10
FIELD !                       !char    !char    !1, 10                    !        !DataHist.ExpiryDate   # 0x0125, '' + \0 * 10
FIELD !                       !char    !char    !1, 10                    !        !DataHist.ExpiryTime   # 0x012f, '' + \0 * 10
FIELD !                       !char    !char    !1, 3                     !        !DataHist.Hist_UN0     # 0x0139, '' + \0 * 3

# correctly handle fixed length strings
EXPRE !!!!!!if strcmpi(@Endian, 'ieee-le'), @DataHist.OriginSPM = 256 * double(@DataHist.Originator(2:2:end)) + double(@DataHist.Originator(1:2:end)); else, @DataHist.OriginSPM = 256 * double(@DataHist.Originator(1:2:end)) + double(@DataHist.Originator(2:2:end));end, if ~@DataHist.OriginSPM(end) == 0, @DataHist.OriginSPM = zsz(@DataHist.OriginSPM); end
EXPRE !!!!!!@DataHist.OriginString = unzerostring(char(@DataHist.Originator)); # SPM2/5 compatibility
EXPRE !!!!!!@DataHist.Generated = unzerostring(@DataHist.Generated);
EXPRE !!!!!!@DataHist.ScanNumber = unzerostring(@DataHist.ScanNumber);
EXPRE !!!!!!@DataHist.PatientID = unzerostring(@DataHist.PatientID);
EXPRE !!!!!!@DataHist.ExpiryDate = unzerostring(@DataHist.ExpiryDate);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -