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 if ~exist(fname,'file')
0026 error([fname,' does not exist']);
0027 end
0028
0029 if nargin < 2
0030
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, [] );
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
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
0073
0074
0075
0076
0077 if 1
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
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
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
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
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
0144 [dixtalImages.datas,dixtalImages.images] = ExtractDixtalDatas(images);
0145
0146 function [dixtalDatas,images]=ExtractDixtalDatas(images);
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162 datas=[];
0163 imageL = size(images,2);
0164 for i=1:36
0165 datas(i,:) = images(32*32+i:imageL:end,:);
0166 end
0167
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