Melanie
(M Samantha)
April 7, 2023, 9:16am
1
Hi
Could some please help me to save a LinearTransform as .mat file using commandline pls.
I have checked script repository , and tried chat GPT ,
Could find anything.
I generate 50-100 linear transforms (after model registration) with displacement data, that needs saving as .mat files , so I am hoping to do it CLI and loop
Thanks
lassoan
(Andras Lasso)
April 9, 2023, 1:52am
2
I would recommend to save as .txt file. It is human-readable and easy to read and write in both Slicer and Matlab.
Matlab reader and writer are available here:
function transform = cli_lineartransformread(filename, transformType)
%cli_transformread Read a single 4x4 linear transformation matrix from an "Insight Transform File V1.0" text file
%
% By default the output transform is in LPS anatomical coordinate sytem and
% defined according to ITK ("image processing") convention.
% If transformType is set to 'slicer' then the output transform is in RAS
% coordinate system and defined according to Slicer ("computer graphics")
% convention.
% See more details at: http://www.slicer.org/slicerWiki/index.php/Documentation/4.2/FAQ#The_registration_transform_file_saved_by_Slicer_does_not_seem_to_match_what_is_shown
%
if nargin < 2
transformType = 'itk';
end
allTransforms=cli_transformread(filename);
assert(length(allTransforms)==1, 'The transform file should contain exactly one transform');
assert(strcmpi(allTransforms{1}.Transform,'AffineTransform_double_3_3'), 'The transform file should contain an AffineTransform_double_3_3 transform');
This file has been truncated. show original
function cli_lineartransformwrite(outputfilename, transformMatrix, transformType)
%cli_transformwrite Write a single 4x4 linear transformation matrix to an "Insight Transform File V1.0" text file
%
% By default the output transform is in LPS anatomical coordinate sytem and
% defined according to ITK ("image processing") convention.
% If transformType is set to 'slicer' then the output transform is in RAS
% coordinate system and defined according to Slicer ("computer graphics")
% convention.
% See more details at: http://www.slicer.org/slicerWiki/index.php/Documentation/4.2/FAQ#The_registration_transform_file_saved_by_Slicer_does_not_seem_to_match_what_is_shown
%
if nargin < 3
transformType = 'itk';
end
assert(isequal(size(transformMatrix),[4 4]), 'transformMatrix size must be 4x4');
if (strcmpi(transformType,'itk'))
transform_lps=transformMatrix;
elseif (strcmpi(transformType, 'slicer'))
This file has been truncated. show original