function vol2exp(input_file, sample, output_file_base) %VOL2EXP writes input for the IRIS Explorer latin module. % % VOL2EXP( INPUT_FILE [, SAMPLE [, OUTPUT_FILE_BASE]] ) % % INPUT_FILE is the input .mnc or .img file. % % OUPUT_FILE_BASE: writes INPUT_FILE to OUPUT_FILE_BASE.exp. % Default is INPUT_FILE minus extension. % % SAMPLE is a 3 x 3 matrix whose rows are the start, step and stop % indices, and whose columns are the x y and z directions. Default is % [1 1 d.dim(1); 1 1 d.dim(2); 1 1 d.dim(3)] i.e. all the data. if nargin < 3 sinf=size(input_file,2) if input_file(sinf) == 'z' output_file_base=input_file(1:(sinf-7)) else output_file_base=input_file(1:(sinf-4)) end end d=fmris_read_image(input_file); if nargin < 2 sample=[1 1 d.dim(1); 1 1 d.dim(2); 1 1 d.dim(3)] end % For .mnc files, emma flips the slices if the voxel sizes are <0, % so we have to flip the voxel sizes and origin: ext=input_file((length(input_file)-2):length(input_file)); isanalyze= all(ext=='img') if d.vox(1)<0 & ~isanalyze d.origin(1)=d.origin(1)+d.vox(1).*d.dim(1); d.vox(1)=-d.vox(1); end if d.vox(2)<0 & ~isanalyze d.origin(2)=d.origin(2)+d.vox(2).*d.dim(2); d.vox(2)=-d.vox(2); end x=sample(1,1):sample(1,2):sample(1,3); y=sample(2,1):sample(2,2):sample(2,3); z=sample(3,1):sample(3,2):sample(3,3); sizes=[length(x) length(y) length(z)] m=[min(x) min(y) min(z); max(x) max(y) max(z)]; bbox=m.*[d.vox; d.vox]+[d.origin; d.origin] fid=fopen([output_file_base '.exp'],'w'); % first 3 are dimension sizes as 4-byte integers: fwrite(fid,sizes,'int'); % next 6 are bounding box as 4-byte floats: fwrite(fid,bbox,'float'); % rest are the data as 4-byte floats: fwrite(fid,d.data(x,y,z),'float'); fclose(fid) return