123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- function header2hx(headerFileName,imgFileName,amiraScriptFileName)
- % Creates an Amira .hx script from a Pinnacle .header file. The .hx script
- % can then be run from inside Amira to open the image. The central idea is
- % that a separate .am file will not have to be created just to view an
- % image in Amira, thus saving hard drive space.
- %
- % Inputs: headerFileName: [char] % location of Pinnacle header file
- % imgFileName: [char] % location of Pinnacle data file
- % amiraScriptFileName: [char] % location of Amira .hx file
- %
- % Ryan T Flynn 10/26/06
- % ensure that the header file has the correct extension
- if strcmp(headerFileName,'.header');
- error([headerFileName ' does not have the .header extension.']);
- end
- % ensure that the data file has the correct extension
- if strcmp(imgFileName,'.img');
- error([imgFileName ' does not have the .img extension.']);
- end
- % ensure that the amira filename has the correct extension
- if strcmp(amiraScriptFileName,'.hx');
- error([imgFileName ' does not have the .hx extension.']);
- end
- fid = fopen(headerFileName,'r');
- if fid == -1
- error(['Unable to open ' headerFileName '.']);
- end
- tline = fgets(fid);
- while tline ~= -1
- % check the line for key words
- if length(findstr(tline,'x_dim')) & ~length(findstr(tline,'fname_index_start'))
- eval(tline); % run the line to get x_dim
- elseif length(findstr(tline,'y_dim'))
- eval(tline); % run the line to get y_dim
- elseif length(findstr(tline,'z_dim'))
- eval(tline); % run the line to get z_dim
- elseif length(findstr(tline,'x_pixdim'))
- eval(tline); % run the line to get x_pixdim
- elseif length(findstr(tline,'y_pixdim'))
- eval(tline); % run the line to get y_pixdim
- elseif length(findstr(tline,'z_pixdim'))
- eval(tline); % run the line to get z_pixdim
- elseif length(findstr(tline,'x_start'))
- eval(tline); % run the line to get x_start
- elseif length(findstr(tline,'y_start'))
- eval(tline); % run the line to get x_start
- elseif length(findstr(tline,'z_start'))
- eval(tline); % run the line to get x_start
- elseif length(findstr(tline,'bytes_pix'))
- eval(tline); % number of bytes per pixel
- elseif length(findstr(tline,'byte_order'))
- eval(tline); % number of bytes per pixel
- end
- tline = fgets(fid);
- end
- fclose(fid);
- % calculate axes for the image
- x = x_start + [0:x_dim-1]*x_pixdim;
- y = y_start + [0:y_dim-1]*y_pixdim;
- z = z_start + [0:z_dim-1]*z_pixdim;
- % deduce the data type of the img file
- if bytes_pix == 2
- dataType = 'short 1';
- elseif bytes_pix == 4
- dataType = 'float 1';
- end
- % assign little of big endian byte orders
- if byte_order == 0
- byteOrder = 'little';
- elseif byte_order == 1
- byteOrder = 'big';
- else
- error(['Unknown byte order in ' headerFileName '.']);
- end
-
- % create the .hx file
- fid = fopen(amiraScriptFileName,'w');
- % name of the structure that will be opened in Amira
- amiraStructName = regexprep(amiraScriptFilleName,'.hx','');
- % create Amira script
- fprintf(fid,'# Amira Script\n');
- fprintf(fid,['remove ' imgFileName '\n']);
- fprintf(fid,'\n');
- fprintf(fid,'set hideNewModules 0\n');
- fprintf(fid,['[ load -raw ' imgFileName ' ' byteOrder ' xfastest ' dataType ' ' num2str(x_dim) ' ' num2str(y_dim) ' ' num2str(z_dim) ...
- ' ' num2str(x(1)) ' ' num2str(x(end)) ' ' num2str(y(1)) ' ' num2str(y(end)) ' ' num2str(z(1)) ' ' num2str(z(end)) ...
- '] setLabel ' imgFileName '\n']);
- fprintf(fid,[imgFileName ' setIconPosition 20 10\n']);
- fprintf(fid,[imgFileName ' flip 1\n']); % flip the data along the y-axis
- fprintf(fid,[imgFileName ' fire\n']);
- fprintf(fid,[imgFileName ' setViewerMask 65535\n']);
- fprintf(fid,'set hideNewModules 0\n');
- fclose(fid);
|