0001 function img = eidors_readimg( fname, format )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 if ~exist(fname,'file')
0028 error([fname,' does not exist']);
0029 end
0030
0031 if nargin < 2
0032
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, [] );
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
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');
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');
0088 dummy=fread(fid, [1],'float32');
0089 ed(:,i)=fread(fid, [1 1024],'float32');
0090 aux(i).int_value=fread(fid, [1 2],'int32');
0091 aux(i).EventText=fread(fid,[1 30],'int8');
0092 aux(i).int_Time=fread(fid, [1 ],'int32');
0093 aux(i).Medibus=fread(fid, [1 52],'float32');
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
0103
0104
0105
0106
0107 if 1
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
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
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
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
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
0174 [dixtalImages.datas,dixtalImages.images] = ExtractDixtalDatas(images);
0175
0176 function [dixtalDatas,images]=ExtractDixtalDatas(images);
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192 datas=[];
0193 imageL = size(images,2);
0194 for i=1:36
0195 datas(i,:) = images(32*32+i:imageL:end,:);
0196 end
0197
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