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

📄 ge_hdr_read.m

📁 mri_toolbox是一个工具用来MRI. 来自于SourceForge, 我上传这个软件,希望能结识对医疗软件感兴趣的兄弟.
💻 M
📖 第 1 页 / 共 4 页
字号:
function [ ge ] = ge_hdr_read(imageFileName)

% ge_hdr_read - Reads the header info from a GE LX2 or 5.X file
% 
% [ge,im_offset] = ge_hdr_read('imageFileName')
%
% ge is a struct with fields:
% 
% ge.hdr.suite  - suite header
% ge.hdr.exam   - exam header
% ge.hdr.series - series header
% ge.hdr.image  - image header
% ge.hdr.pixel  - pixel header
% 
% ge.img.offset  - the byte offset to the image data
% 
% This function assumes the image file is big endian.  It can
% automatically determine LX2 format (SGI) and 5.X format (Sun);
% other formats fail.
% 
% See also ge_vol_read
% 


% $Revision: 1.4 $ $Date: 2004/02/07 01:41:51 $

% Souheil J. Inati  <souheil.inati@nyu.edu> at 03/2003
% Dartmouth College, May 2000
% 
% Darren.Weber_at_radiology.ucsf.edu, March 2003
% - Substantially redesigned file handling and function
%   call structures for integration with mri_toolbox at 
%   http://eeg.sf.net
% - Requested permission to distribute code under GPL licence
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% DLW, found this note in an FSL list message:
%This is further confounded by the GE image format I.001 or I.MR
%formats where the data following the header is inverted (top of the
%image for bottom).



fprintf('\nGE_HDR_READ\n'); tic

fprintf('...reading %s\n',imageFileName);

% Open the Image File
[fid,message] = fopen(imageFileName,'r','b'); % 'b' = Big-Endian format
if fid == -1, error(message); end

% Check for the magic number at the first word
magic = fread(fid,1,'int32');
if magic == 1229801286,
    % This is a 5.X format image
    fprintf('...identified Signa 5.X format\n');
    byte_align = 0;
    ge.hdr.pixel.offset = 0;
    ge.hdr.suite.size   = 114;
    ge.hdr.exam.size    = 1024;
    ge.hdr.series.size  = 1020;
    ge.hdr.image.size   = 1022;
else
    % Magic no. not at the 1st word, try at the LX2 position
    fseek(fid,3228,-1);
    magic = fread(fid,1,'int32');
    if magic == 1229801286,
        % This is an LX2 format image
        fprintf('...identified LX2 format\n');
        byte_align = 1;
        ge.hdr.pixel.offset = 3228;
        ge.hdr.suite.size   = 116;
        ge.hdr.exam.size    = 1040;
        ge.hdr.series.size  = 1028;
        ge.hdr.image.size   = 1044;
    else
        msg = 'This is not a 5.X or LX2 format image.  No Magic Number.';
        error(msg);
    end
end

% Load the pixel header
fseek(fid,ge.hdr.pixel.offset,-1);
ge = ge_readHeaderPixel(fid, byte_align, ge); % see subfunc below


% Check for epirecon images
if (ge.hdr.pixel.img_l_dbHdr == 0 & byte_align == 0),
    error('This is an epirecon image. No header!');
end

% Compute the offsets
ge.hdr.suite.offset  = ge.hdr.pixel.img_p_dbHdr;
ge.hdr.exam.offset   = ge.hdr.suite.offset  + ge.hdr.suite.size;
ge.hdr.series.offset = ge.hdr.exam.offset   + ge.hdr.exam.size;
ge.hdr.image.offset  = ge.hdr.series.offset + ge.hdr.series.size;
ge.img.offset        = ge.hdr.pixel.offset  + ge.hdr.pixel.img_hdr_length;



% Load the suite header
fseek(fid,ge.hdr.suite.offset,-1);
ge.hdr.suite = ge_readHeaderSuite(fid, byte_align); % see subfunc below

% Load the exam header
fseek(fid,ge.hdr.exam.offset,-1);
ge.hdr.exam = ge_readHeaderExam(fid, byte_align); % see subfunc below

% Load the series header
fseek(fid,ge.hdr.series.offset,-1);
ge.hdr.series = ge_readHeaderSeries(fid, byte_align); % see subfunc below

% Load the image header
fseek(fid,ge.hdr.image.offset,-1);
ge.hdr.image = ge_readHeaderImage(fid, byte_align); % see subfunc below

% Close the file
fclose(fid);

t=toc; fprintf('...done (%5.2f sec).\n',t);

return




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function su_hdr = ge_readHeaderSuite(fid, byte_align)

% Loads the suite header from an image file (with fid)
% and returns it as a structure.
% 
% if byte_align = 1 then 32-bit alignment (SGI, LX2 format)
% if byte_align = 0 then 16-bit alignment (Sun, 5.X format)

% define the structure and read
su_hdr = struct('su_id', fread(fid,4,'char'));                   % Suite ID
su_hdr = setfield(su_hdr, 'su_uniq', fread(fid,1,'int16'));      % The Make-Unique Flag
su_hdr = setfield(su_hdr, 'su_diskid', fread(fid,1,'char'));     % Disk ID
su_hdr = setfield(su_hdr, 'prodid', fread(fid,13,'char'));       % Product ID
su_hdr = setfield(su_hdr, 'su_verscre', fread(fid,2,'char'));    % Genesis Version
su_hdr = setfield(su_hdr, 'su_verscur', fread(fid,2,'char'));    % Genesis Version
su_hdr = setfield(su_hdr, 'su_checksum', fread(fid,1,'uint32')); % Suite Record Checksum
su_hdr = setfield(su_hdr, 'su_padding', fread(fid,85,'char'));   % Spare Space
fseek(fid,1,0); % 16-bit alignment
if byte_align, fseek(fid,2,0); end % 32-bit alignment

return





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function ex_hdr = ge_readHeaderExam(fid, byte_align)

% Loads the exam header from the image file
% and returns it as a structure.
% 
% if byte_align = 1 then 32-bit alignment (SGI, LX2 format)
% if byte_align = 0 then 16-bit alignment (Sun, 5.X format)

% define the structure and read ifseek(fid,1,0);  % byte align the data
% to overcome the byte alignment problems
% break up the assignment into pieces using the setfield function
ex_hdr = struct('ex_suid', fread(fid,4,'uchar')); %Suite ID for this Exam%
ex_hdr = setfield(ex_hdr, 'ex_uniq', fread(fid,1,'int16'));        %The Make-Unique Flag%
ex_hdr = setfield(ex_hdr, 'ex_diskid', fread(fid,1,'uchar'));      %Disk ID for this Exam%
fseek(fid,1,0); % 16-bit alignment
ex_hdr = setfield(ex_hdr, 'ex_no', fread(fid,1,'uint16'));         %Exam Number%
ex_hdr = setfield(ex_hdr, 'hospname', fread(fid,33,'uchar'));      %Hospital Name%
fseek(fid,1,0); % 16-bit alignment
ex_hdr = setfield(ex_hdr, 'detect', fread(fid,1,'int16'));         %Detector Type%

⌨️ 快捷键说明

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