Code covered by the BSD License  

Highlights from
simulate motion in Cartesian MRI

image thumbnail

simulate motion in Cartesian MRI

by

 

24 May 2013 (Updated )

Simulates Point Spread Function (PSF) and k-space data for motion in Cartesian sequences.

getReorderLinesCartesian( varargin )
function [ idxY, idxZ ] = getReorderLinesCartesian( varargin )
%Define lines to be sampled in a Cartesian MRI experiment
%
% [ idxY, idxZ ] = getReorderLinesCartesian( 'param1', value1, 'param2', value2, ... )
%
% Paramters
% =========
%       reorderString       'linear' / 'shuffle' / 'random'  +  yours
%
%       szY                 y-size ( == No. of Phase Encoding lines per partition )
%
%       szZ                 z-size ( == No. of partitions; default: 1 )
%
%       Nexc                No. of excitations (if different from available k-space lines)
%
%
% Output
% ======
%
%   idxY    -   line indices for the y-dimension
%               (often referred to as phase encoding)
%
%               size(idxY) = [ Nexc    1 ]
%
%
%   idxZ    -   line indices for the y-dimension
%               (often referred to as partition encoding)
%
%               size(idxZ) = [ Nexc    1 ]
%
% Examples
% ========
%
%   Standard (linear) 2D acquisition using 256 lines:
%      idxY = getReorderLinesCartesian( 'reorderString', 'linear', 'szY', 256 );
%   
%   random 2D acquisition using 256 lines:
%      idxY = getReorderLinesCartesian( 'reorderString', 'random', 'szY', 256 );
%
%   3D linear 256 phase-encoding lines, 32 partitions:
%      idxY = getReorderLinesCartesian( 'reorderString', 'random', 'szY', 256, 'szZ', 32 );

% michael.voelker@mr-bavaria.de, 2013

    % parse input as key/value pairs
    p = inputParser;
    isPosInteger = @(n) validateattributes( n, {'numeric'}, {'nonempty', 'scalar', 'real', 'finite', 'positive', 'integer'});
    p.addParamValue( 'reorderString', [], @(s) validateattributes( s, {'char'}, {'nonempty'} ) );
    p.addParamValue( 'szY', [], @(n) isPosInteger(n) );
    p.addParamValue( 'szZ',  1, @(n) isPosInteger(n) );
    p.addParamValue( 'Nexc',[], @(n) isPosInteger(n) );

    p.parse( varargin{:} )

    reorderString = lower( p.Results.reorderString );   % save the results
    szY  = p.Results.szY;
    szZ  = p.Results.szZ;
    Nexc = p.Results.Nexc;
    
    if isempty(reorderString)
        error( 'getReorderLinesCartesian:BadReordering', 'Missing input "reorderString". Must be a string specifying the desired reordering.' )
    end
    if isempty(szY)
        error( 'getReorderLinesCartesian:BadNumPElines', 'Missing input "szY": Must be a positive scalar integer.' )
    end
    if isempty(Nexc)
        Nexc = szY * szZ;
    end
    Nlines = szY * szZ;

    allowedReorderings = lower( { 'linear', 'shuffle', 'random' } );
    
    switch reorderString

        case allowedReorderings(1)          % 'linear'
            % The most simple way through k-space:
            % idx_Y = 1,2,3, ..., n, 1,2,3, ..., n, 1,2,3, ..., n, 1,2,3, ..., n,
            % idx_Z = 1,1,1,1,1,..., 2,2,2,2,2,..., 3,3,3,3,3,..., 4,4,4,4,4,...,

            linIdx       = 1 + mod( 0:Nexc-1, Nlines);
            [idxY, idxZ] = ind2sub( [szY szZ],  linIdx );


        case allowedReorderings(2)          % 'shuffle'
            % Shuffle the lines randomly, but each line should be sampled

            if Nexc >= Nlines       % oversampled
                linIdx = mod( randperm(Nexc), Nlines) + 1;
                [idxY, idxZ] = ind2sub( [szY szZ], linIdx );

            else                    % undersampled
                [idxY, idxZ] = ind2sub( [szY szZ],  mod( randperm(Nlines, Nexc), Nlines) + 1 );
            end


        case allowedReorderings(3)          % 'random'
            % Sample k-space pure randomly, lines may be skipped or sampled multiple times

            [idxY, idxZ] = ind2sub( [szY szZ],  randi(Nlines, Nexc, 1) );

            
        % case allowedReorderings(4)          % 'myreordering'
            % your code here!


        otherwise
            str = char( allowedReorderings ).';                 % cell-to-string
            str = [str; repmat(', '.', [1 size(str,2)])];       % separate entries with commas
            str(end-1:end) = ' ';                               % remove the last comma
            error('getReorderLinesCartesian:ReorderUnknown', 'Unknown reordering type "%s"\nAllowed reordering types are:\n%s', reorderString, str(:).' )
    end


    % be sure we have column vectors
    idxY = idxY(:);
    idxZ = idxZ(:);


end % of getReorderLinesCartesian()

Contact us