eidors_saveimg

PURPOSE ^

EIDORS saveimg - save reconstructed image files in formats

SYNOPSIS ^

function eidors_saveimg( img, fname, format )

DESCRIPTION ^

 EIDORS saveimg - save reconstructed image files in formats
    of various EIT equipment manufacturers
 eidors_saveimg( img, fname, format )

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

 Usage
 eidors_saveimg( img,fname,format )
     img   = eidors image structure
     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 eidors_saveimg( img, fname, format )
0002 % EIDORS saveimg - save reconstructed image files in formats
0003 %    of various EIT equipment manufacturers
0004 % eidors_saveimg( img, fname, format )
0005 %
0006 % Currently the list of supported file formats is:
0007 %    - NATIVE "e3d" file format
0008 %        format = "E3D"
0009 %    - MCEIT (Goettingen / Viasys) "igt" file format
0010 %        format = "IGT"
0011 %
0012 % Usage
0013 % eidors_saveimg( img,fname,format )
0014 %     img   = eidors image structure
0015 %     fname = file name
0016 %
0017 %  If format is unspecified, we attempt to autodetect.
0018 
0019 % (C) 2009 by Bartlomiej Grychtol. Licensed under GPL v2 or v3
0020 % $Id: eidors_saveimg.m 1883 2009-06-23 09:17:33Z aadler $
0021 
0022 
0023 switch nargin
0024     case 2
0025         fmt = detect_format(fname);
0026         if isempty( fmt )
0027             error('file format unspecified, can`t autodetect');
0028         end
0029     case 3
0030         fmt1 = detect_format(fname);
0031         fmt = lower(format);
0032         if isempty(fmt1);
0033             fname = [fname '.' fmt];
0034         else
0035             if ~strcmp(fmt1, fmt)
0036                 error('The extension specified in file name doesn''t match the file format');
0037             end
0038         end
0039     otherwise
0040        error('Usage: eidors_saveimg( img , fname, format )');       
0041 end
0042 
0043 
0044 switch fmt
0045     case 'igt'
0046         mceit_saveimg( img, fname );
0047     case 'e3d'
0048         native_saveimg( img, fname);
0049     otherwise
0050         error('eidors_readdata: file "%s" format unknown', fmt);
0051 end
0052 
0053 
0054 
0055 
0056 %%
0057 function fmt = detect_format( fname ) 
0058 
0059 dotpos = find(fname == '.');
0060 if isempty( dotpos )
0061     fmt = [];
0062 else
0063     dotpos= dotpos(end);
0064     format= fname( dotpos+1:end );
0065     fmt= lower(format);
0066 end
0067 
0068 
0069 
0070 %%
0071 function fid = open_file( fname );
0072 
0073 if exist(fname,'file')
0074     disp('File already exists.');
0075     reply = input('Overwrite? Y/N [Y]: ', 's');
0076     if isempty(reply), reply = 'Y'; end
0077     reply = lower(reply);
0078     
0079     if ~strcmp(reply,'y');
0080         fid = -1;
0081         return;
0082     end
0083 end
0084 fid = fopen( fname ,'w');
0085 
0086 
0087 
0088 
0089 
0090 
0091 %%
0092 function mceit_saveimg( img, fname );
0093 % mceit_readimg - saves IGT files.
0094 
0095 fid = open_file( fname );
0096 if fid < 0
0097     error('Cannot open file.');
0098 end
0099 
0100 n = size(img.elem_data,1);
0101 if n == 912
0102    %already the right format
0103    fwrite(fid,img.elem_data','4*float');
0104 else
0105    data = img2igt(img);
0106    fwrite(fid, data , '4*float');
0107 end
0108 
0109 fclose(fid);
0110 
0111 %%
0112 function native_saveimg( img, fname )
0113 % native_saveimg - saves E3D file.
0114 % E3D file is a zipped matlab v6 compatible .mat file called "e3d.temp"
0115 % containing one eidors image struct variable named "img".
0116 
0117 % save temporary mat file
0118 if ~exist('OCTAVE_VERSION') && str2double(version('-release')) < 14
0119     save('e3d.temp', 'img');
0120 else
0121     save('e3d.temp', 'img', '-v6');
0122 end
0123 zip('temp.zip','e3d.temp');
0124 movefile('temp.zip',fname);
0125 delete e3d.temp

Generated on Wed 21-Jun-2017 09:29:07 by m2html © 2005