Code covered by the BSD License
-
ffablankheader()
-
ffahdr2precision( header );
-
ffaopen(filename, permission)...
-
ffaread(filename, offsetFlag)
function [data, header, count] = ffaread(filename, offsetFlag);
-
ffareaddata(fid, header, offs...
-
ffareadsubset(fid, header, po...
-
ffawrite( filename, header, d...
-
ffawritesubset( filename, hea...
-
contents.m
-
ffaWriteExample.m
-
View all files
from
Read and write ffA volume formats
by Stephen Purves
Users can easily move 3D volume data between Matlab and ffA's SVI Pro / SEA 3D Pro
|
| ffawrite( filename, header, data )
|
function [ header ] = ffawrite( filename, header, data )
%
% function [ header ] = ffawrite( filename, header, data )
%
% Writes out an the specified data to a .ffa file.
%
% The return header will contain the raw header string written
% and the numvoxels field will indicate the number actually written
if nargin ~= 3
disp('Wrong number of arguments')
return
end
if isempty(filename)
disp('A filename must be specified')
return
end
fid = fopen( filename, 'w' );
%
% Write the header information
%
header.raw = [];
TAB = char(9);
SEMICOLON = char(59);
LINEFEED = char(10);
ENDHEADER = 'ENDHEADER.';
MAGIC = hex2dec( 'abc2' );
header.raw = [ 'FFAID:' TAB num2str(header.ffaid) SEMICOLON LINEFEED ];
header.raw = [ header.raw 'SIGNFLAG:' TAB num2str(header.signflag) TAB SEMICOLON LINEFEED ];
header.raw = [ header.raw 'FLOATFLAG:' TAB num2str(header.floatflag) TAB SEMICOLON LINEFEED ];
header.raw = [ header.raw 'DATABITS:' TAB num2str(header.databits) TAB SEMICOLON LINEFEED ];
header.raw = [ header.raw 'VOXELBITS:' TAB num2str(header.voxelbits) TAB SEMICOLON LINEFEED ];
header.raw = [ header.raw 'NUMDIMS:' TAB num2str(header.numdims) TAB SEMICOLON LINEFEED ];
header.raw = [ header.raw 'SIZE[]:' TAB num2str(header.size(1)) TAB SEMICOLON LINEFEED ...
TAB num2str(header.size(2)) TAB SEMICOLON LINEFEED TAB num2str(header.size(3)) TAB SEMICOLON LINEFEED ];
header.raw = [ header.raw 'ORIGIN[]:' TAB num2str(header.origin(1)) TAB SEMICOLON LINEFEED ...
TAB num2str(header.origin(2)) TAB SEMICOLON LINEFEED TAB num2str(header.origin(3)) TAB SEMICOLON LINEFEED ];
header.raw = [ header.raw 'LABEL[]:' TAB header.label.x TAB SEMICOLON LINEFEED TAB header.label.y ...
TAB SEMICOLON LINEFEED TAB header.label.z TAB SEMICOLON LINEFEED ];
header.raw = [ header.raw 'SCALE[]:' TAB num2str(header.scale(1)) TAB SEMICOLON LINEFEED TAB num2str(header.scale(2)) TAB ...
SEMICOLON LINEFEED TAB num2str(header.scale(3)) TAB SEMICOLON LINEFEED ];
header.raw = [ header.raw 'UNITNAME[]:' TAB header.unitname.x TAB SEMICOLON LINEFEED TAB header.unitname.y TAB ...
SEMICOLON LINEFEED TAB header.unitname.z TAB SEMICOLON LINEFEED ];
len = length( header.raw );
diff = 589 - len;
while ( diff > 0 )
header.raw = [ header.raw LINEFEED ];
diff = diff - 1;
end
header.raw = [ header.raw ENDHEADER LINEFEED ];
hdrcount = fwrite(fid, header.raw, 'char');
%
% Write the magic number
%
fwrite(fid, MAGIC, 'int32');
%
% Write the data
%
precision = ffahdr2precision( header );
if (header.scale(1) < 0)
data = flipdim(data,1);
end
if (header.scale(2) < 0)
data = flipdim(data,2);
end
if (header.scale(3) < 0)
data = flipdim(data,3);
end
data = reshape( data, [1 prod(size(data))] );
numvox = length(data);
header.numvoxels = fwrite(fid, data, precision );
fclose(fid);
|
|
Contact us at files@mathworks.com