Home > eidors > interface > eidors_readimg.m

eidors_readimg

PURPOSE ^

EIDORS readimg - read reconstructed image files from

SYNOPSIS ^

function img = eidors_readimg( fname, format )

DESCRIPTION ^

 EIDORS readimg - read reconstructed image files from
       various EIT equipment manufacturers
  img = eidors_readimg( fname, format )

 Currently the list of supported file formats is:
    - MCEIT (Goettingen / Viasys) "igt" file format 
        format = "IGT" or "MCEIT"
    - DIXTAL (Goettingen / Viasys) "img" file format 
        format = "DIXTAL-IMG"
    - NATIVE "e3d" file format
        format = "e3d" or "NATIVE"

 Usage
 img = eidors_readimg( fname, format )
     img   = eidors image structure
     img.elem_data = reconstructed image matrix NumPixels x NumFrames
     fname = file name

  If format is unspecified, we attempt to autodetect.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function img = eidors_readimg( fname, format )
0002 % EIDORS readimg - read reconstructed image files from
0003 %       various EIT equipment manufacturers
0004 %  img = eidors_readimg( fname, format )
0005 %
0006 % Currently the list of supported file formats is:
0007 %    - MCEIT (Goettingen / Viasys) "igt" file format
0008 %        format = "IGT" or "MCEIT"
0009 %    - DIXTAL (Goettingen / Viasys) "img" file format
0010 %        format = "DIXTAL-IMG"
0011 %    - NATIVE "e3d" file format
0012 %        format = "e3d" or "NATIVE"
0013 %
0014 % Usage
0015 % img = eidors_readimg( fname, format )
0016 %     img   = eidors image structure
0017 %     img.elem_data = reconstructed image matrix NumPixels x NumFrames
0018 %     fname = file name
0019 %
0020 %  If format is unspecified, we attempt to autodetect.
0021 
0022 % (C) 2009 by Bartlomiej Grychtol. Licensed under GPL v2 or v3
0023 % $Id: eidors_readimg.m 4151 2013-06-07 13:41:16Z aadler $
0024 
0025 if ~exist(fname,'file')
0026    error([fname,' does not exist']);
0027 end
0028 
0029 if nargin < 2
0030 % unspecified file format, autodetect
0031    dotpos = find(fname == '.');
0032    if isempty( dotpos ) 
0033       error('file format unspecified, can`t autodetect');
0034    else
0035       dotpos= dotpos(end);
0036       format= fname( dotpos+1:end );
0037    end
0038 end
0039 fmt= lower(format);
0040 
0041 switch fmt
0042     case {'igt','mceit'}
0043         img = mceit_readimg( fname );
0044     case {'dixtal-img'}
0045         img = read_dixtal_img( fname, 1, [] ); % Guess that FS=50
0046     case {'e3d','native'}
0047         img = native_readimg( fname );
0048     otherwise
0049         error('eidors_readdata: file "%s" format unknown', fmt);
0050 end
0051 
0052 
0053 
0054 
0055 %%
0056 function img = mceit_readimg( fname )
0057 % mceit_readimg - reads in IGT files.
0058 
0059 fid = fopen(fname,'r');
0060 igt = fread(fid, inf,'4*float');
0061 fclose(fid);
0062 
0063 igt = reshape(igt, [], 912);
0064 
0065 img = igt2img(igt);
0066 
0067 img.name = ['Read from ' fname];
0068 
0069 
0070 %%
0071 function img = native_readimg( fname )
0072 % native_readimg - reads in native E3D files.
0073 % E3D file is a zipped matlab v6 compatible .mat file called "e3d.temp"
0074 % containing one eidors image struct variable named "img".
0075 
0076 
0077 if 1 % COMPATIBILITY WITH Matlab 6.5 and Octave we can't use output files
0078    unzip(fname);
0079    tempfile = 'e3d.temp';
0080 else
0081    files = unzip(fname);
0082    if numel(files) > 1
0083        error(['File %s is not a proper E3D file. '...
0084            'The archive contains more than one file'],fname);
0085    end
0086    tempfile = files{1};
0087 end
0088 
0089 S = load(tempfile,'-mat');
0090 delete(tempfile);
0091 if numel(fieldnames(S)) > 1
0092      warning(['File %s is not a proper E3D file. '...
0093         'The mat file contains more than one variable. Strugling on.'],fname);
0094 end
0095 
0096 if isfield(S,'img')
0097     img = S.img;
0098 else
0099     error(['File %s is not a proper E3D file. '...
0100         'The mat file does not contain an "img" variable.'],fname);
0101 end
0102 
0103 
0104 
0105 function [dixtalImages]=read_dixtal_img(file_name,skipHeader,Fs);
0106 % [dixtalImages]=OpenDixtalImages(file_name,skipHeader,Fs)
0107 %
0108 % Read the Dixtal images at file_name
0109 % input:
0110 %       - file_name:  Name and place of the dixtal file
0111 %       - skipHeader: skip Dixtal header
0112 %       - Fs:         sampling frequency (50 if empty)
0113 %
0114 % output:
0115 %       - dixtalImages: structure with the following fields:
0116 %           Fs:      sampling frequency
0117 %           datas:   analogue channel 2
0118 %           images:  Dixtal images
0119 
0120 if(isempty(Fs)==0)
0121     dixtalImages.Fs = Fs;
0122 else
0123     dixtalImages.Fs = 50;
0124 end
0125 
0126 fid=fopen(file_name,'r','ieee-be');
0127 [fname, mode, mformat] = fopen(fid);
0128 
0129 %if skip header is selceted, skip the header
0130 if (skipHeader == 1)
0131     for i=1:42
0132         tline = fgetl(fid);
0133     end
0134 end
0135 a=fread(fid,'*float32','ieee-be');
0136 fclose(fid);
0137 
0138 % Reshape the Images
0139 offset = 1*32+4;
0140 imageL = 32*32 + offset;
0141 long = floor(length(a)/(imageL));
0142 images = reshape(a(1:long*imageL),imageL,long);
0143 % extracts data chanels
0144 [dixtalImages.datas,dixtalImages.images] = ExtractDixtalDatas(images);
0145 
0146 function [dixtalDatas,images]=ExtractDixtalDatas(images);
0147 % [dixtalAnalogs,images]=ExtractDixtalDatas(fname)
0148 % Extract the analog recording and the ECG from the reconstructed images of
0149 %       - dixtalDatas structure with the following fields:
0150 %           analog1: analogue channel 1
0151 %           analog2: analogue channel 2
0152 %           tbc_ecg: ECG correctness TO BE CONFIRMED
0153 %           tbc_timeStamp: Timestamp correctness TO BE CONFIRMED
0154 %           tbc_sync1: synchronization signal correctness TO BE CONFIRMED
0155 %           tbc_sync2: synchronization signal correctness TO BE CONFIRMED
0156 % !All fields starting with tbc_ are first guess signal is saved to not loos
0157 % the data but shall be investigated!
0158 %       - images: EIT images without the Dixtal data
0159 
0160 
0161 % read the datas
0162 datas=[];
0163 imageL = size(images,2);
0164 for i=1:36
0165     datas(i,:) = images(32*32+i:imageL:end,:);
0166 end
0167 %remove the datas form the image
0168 images = images(1:32*32,:);
0169 
0170 dixtalDatas.analog1 = reshape(datas(8:12,:),1,5*size(datas,2));
0171 dixtalDatas.analog2 = reshape(datas(14:18,:),1,5*size(datas,2));
0172 dixtalDatas.tbc_ecg = reshape(datas(20:24,:),1,5*size(datas,2));
0173 dixtalDatas.tbc_sync1 = datas(1,:);
0174 dixtalDatas.tbc_sync2 = datas(25,:);
0175 dixtalDatas.tbc_timeStamp = datas(2,:);
0176

Generated on Fri 01-Jun-2018 15:59:55 by m2html © 2005