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  "img" file format 
        format = "DIXTAL-IMG"
    - DRAEGER  "bin" file format 
        format = "DRAEGER-BIN"
    - 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  "img" file format
0010 %        format = "DIXTAL-IMG"
0011 %    - DRAEGER  "bin" file format
0012 %        format = "DRAEGER-BIN"
0013 %    - NATIVE "e3d" file format
0014 %        format = "e3d" or "NATIVE"
0015 %
0016 % Usage
0017 % img = eidors_readimg( fname, format )
0018 %     img   = eidors image structure
0019 %     img.elem_data = reconstructed image matrix NumPixels x NumFrames
0020 %     fname = file name
0021 %
0022 %  If format is unspecified, we attempt to autodetect.
0023 
0024 % (C) 2009 by Bartlomiej Grychtol. Licensed under GPL v2 or v3
0025 % $Id: eidors_readimg.m 6233 2022-02-15 15:05:40Z aadler $
0026 
0027 if ~exist(fname,'file')
0028    error([fname,' does not exist']);
0029 end
0030 
0031 if nargin < 2
0032 % unspecified file format, autodetect
0033    dotpos = find(fname == '.');
0034    if isempty( dotpos ) 
0035       error('file format unspecified, can`t autodetect');
0036    else
0037       dotpos= dotpos(end);
0038       format= fname( dotpos+1:end );
0039    end
0040 end
0041 fmt= lower(format);
0042 
0043 switch fmt
0044     case {'igt','mceit'}
0045         img = mceit_readimg( fname );
0046     case {'dixtal-img'}
0047         img = read_dixtal_img( fname, 1, [] ); % Guess that FS=50
0048     case {'bin','draeger-bin'}
0049         img = read_draeger_bin( fname );
0050     case {'e3d','native'}
0051         img = native_readimg( fname );
0052     otherwise
0053         error('eidors_readdata: file "%s" format unknown', fmt);
0054 end
0055 
0056 
0057 
0058 
0059 %%
0060 function img = mceit_readimg( fname )
0061 % mceit_readimg - reads in IGT files.
0062 
0063 fid = fopen(fname,'r');
0064 igt = fread(fid, inf,'4*float');
0065 fclose(fid);
0066 
0067 igt = reshape(igt, [], 912);
0068 
0069 img = igt2img(igt);
0070 
0071 img.name = ['Read from ' fname];
0072 
0073 %%
0074 function img = read_draeger_bin( fname );
0075     fid=fopen(fname,'rb');
0076     getarray=fread(fid, [1 inf],'int8');
0077     frame_length=length(getarray)/4358;
0078     fclose(fid);
0079 
0080     fmdl = mk_grid_model([],linspace(+1,-1,33),linspace(+1,-1,33));
0081     fmdl = rmfield(fmdl,'mdl_slice_mapper'); % set axis to match Draeger format
0082 
0083     ed=zeros(1024,frame_length);     
0084     fid=fopen(fname,'rb');
0085     aux = struct([]);
0086     for i=1:frame_length
0087         time_stamp=fread(fid, [1 2],'float32');  %read time stamp
0088         dummy=fread(fid, [1],'float32');   %read dummy
0089         ed(:,i)=fread(fid, [1 1024],'float32');%read pixel values for each frame
0090         aux(i).int_value=fread(fid, [1 2],'int32');  %read MinMax, Event Marker,
0091         aux(i).EventText=fread(fid,[1 30],'int8');
0092         aux(i).int_Time=fread(fid, [1 ],'int32'); %Timing Error
0093         aux(i).Medibus=fread(fid, [1 52],'float32'); %ventilator data
0094         
0095     end
0096     fclose(fid);
0097     img = mk_image(fmdl,ed);
0098     img.aux = aux;
0099 
0100 %%
0101 function img = native_readimg( fname )
0102 % native_readimg - reads in native E3D files.
0103 % E3D file is a zipped matlab v6 compatible .mat file called "e3d.temp"
0104 % containing one eidors image struct variable named "img".
0105 
0106 
0107 if 1 % COMPATIBILITY WITH Matlab 6.5 and Octave we can't use output files
0108    unzip(fname);
0109    tempfile = 'e3d.temp';
0110 else
0111    files = unzip(fname);
0112    if numel(files) > 1
0113        error(['File %s is not a proper E3D file. '...
0114            'The archive contains more than one file'],fname);
0115    end
0116    tempfile = files{1};
0117 end
0118 
0119 S = load(tempfile,'-mat');
0120 delete(tempfile);
0121 if numel(fieldnames(S)) > 1
0122      warning(['File %s is not a proper E3D file. '...
0123         'The mat file contains more than one variable. Strugling on.'],fname);
0124 end
0125 
0126 if isfield(S,'img')
0127     img = S.img;
0128 else
0129     error(['File %s is not a proper E3D file. '...
0130         'The mat file does not contain an "img" variable.'],fname);
0131 end
0132 
0133 
0134 
0135 function [dixtalImages]=read_dixtal_img(file_name,skipHeader,Fs);
0136 % [dixtalImages]=OpenDixtalImages(file_name,skipHeader,Fs)
0137 %
0138 % Read the Dixtal images at file_name
0139 % input:
0140 %       - file_name:  Name and place of the dixtal file
0141 %       - skipHeader: skip Dixtal header
0142 %       - Fs:         sampling frequency (50 if empty)
0143 %
0144 % output:
0145 %       - dixtalImages: structure with the following fields:
0146 %           Fs:      sampling frequency
0147 %           datas:   analogue channel 2
0148 %           images:  Dixtal images
0149 
0150 if(isempty(Fs)==0)
0151     dixtalImages.Fs = Fs;
0152 else
0153     dixtalImages.Fs = 50;
0154 end
0155 
0156 fid=fopen(file_name,'r','ieee-be');
0157 [fname, mode, mformat] = fopen(fid);
0158 
0159 %if skip header is selceted, skip the header
0160 if (skipHeader == 1)
0161     for i=1:42
0162         tline = fgetl(fid);
0163     end
0164 end
0165 a=fread(fid,'*float32','ieee-be');
0166 fclose(fid);
0167 
0168 % Reshape the Images
0169 offset = 1*32+4;
0170 imageL = 32*32 + offset;
0171 long = floor(length(a)/(imageL));
0172 images = reshape(a(1:long*imageL),imageL,long);
0173 % extracts data chanels
0174 [dixtalImages.datas,dixtalImages.images] = ExtractDixtalDatas(images);
0175 
0176 function [dixtalDatas,images]=ExtractDixtalDatas(images);
0177 % [dixtalAnalogs,images]=ExtractDixtalDatas(fname)
0178 % Extract the analog recording and the ECG from the reconstructed images of
0179 %       - dixtalDatas structure with the following fields:
0180 %           analog1: analogue channel 1
0181 %           analog2: analogue channel 2
0182 %           tbc_ecg: ECG correctness TO BE CONFIRMED
0183 %           tbc_timeStamp: Timestamp correctness TO BE CONFIRMED
0184 %           tbc_sync1: synchronization signal correctness TO BE CONFIRMED
0185 %           tbc_sync2: synchronization signal correctness TO BE CONFIRMED
0186 % !All fields starting with tbc_ are first guess signal is saved to not loos
0187 % the data but shall be investigated!
0188 %       - images: EIT images without the Dixtal data
0189 
0190 
0191 % read the datas
0192 datas=[];
0193 imageL = size(images,2);
0194 for i=1:36
0195     datas(i,:) = images(32*32+i:imageL:end,:);
0196 end
0197 %remove the datas form the image
0198 images = images(1:32*32,:);
0199 
0200 dixtalDatas.analog1 = reshape(datas(8:12,:),1,5*size(datas,2));
0201 dixtalDatas.analog2 = reshape(datas(14:18,:),1,5*size(datas,2));
0202 dixtalDatas.tbc_ecg = reshape(datas(20:24,:),1,5*size(datas,2));
0203 dixtalDatas.tbc_sync1 = datas(1,:);
0204 dixtalDatas.tbc_sync2 = datas(25,:);
0205 dixtalDatas.tbc_timeStamp = datas(2,:);
0206

Generated on Fri 30-Dec-2022 19:44:54 by m2html © 2005