Main Content

reposition

Update intrinsic-to-world mapping of spatial referencing object

Since R2025a

    Description

    repositionedR = reposition(R,tform) updates the intrinsic-to-world mapping described by the medicalref3d object R according to the geometric transformation tform, and returns a new medicalref3d object, repositionedR. Use this function to update the position of a medical volume whose spatial referencing is defined by R in the patient coordinate system.

    example

    Examples

    collapse all

    Apply a geometric transformation that changes the intrinsic-to-world mapping described by a medicalref3d object. The medicalref3d object describes the position of a medical volume in the patient coordinate system, and updating the mapping repositions the volume in world coordinates.

    Download and Import Images

    Download a modified version of the 3-D CT and MRI data sets from The Retrospective Image Registration Evaluation (RIRE) Dataset, provided by Dr. Michael Fitzpatrick. For more information, see the RIRE Project homepage. The modified data set contains one CT scan and one MRI scan from the same patient stored in the NRRD file format. The size of the entire data set is approximately 35 MB. Download the data set from the MathWorks® website, then unzip the folder.

    zipFile = matlab.internal.examples.downloadSupportFile("medical", ...
        "MedicalRegistrationNRRDdataLPS.zip");
    filepath = fileparts(zipFile);
    unzip(zipFile,filepath)

    Read the CT and MRI volumes as medicalVolume objects.

    filenameCT = fullfile(filepath,"supportfilesNRRD","Patient007CT.nrrd");
    movingVolume = medicalVolume(filenameCT);
    
    filenameMRI = fullfile(filepath,"supportfilesNRRD","Patient007MRT1.nrrd");
    fixedVolume = medicalVolume(filenameMRI);

    Extract the medicalref3d object that describes the spatial referencing for the moving volume.

    R = movingVolume.VolumeGeometry
    R = 
      medicalref3d with properties:
    
                     VolumeSize: [512 512 28]
                       Position: [28×3 double]
                 VoxelDistances: {[0.6536 0 0]  [0 0.6536 0]  [0 0 4]}
        PatientCoordinateSystem: "LPS+"
                   PixelSpacing: [0.6536 0.6536]
                       IsAffine: 1
                  IsAxesAligned: 1
                        IsMixed: 0
    
    

    Apply Transformation to Spatial Referencing of Moving Volume

    Apply a geometric transformation calculated using the Moment of Mass registration technique in the Medical Registration Estimator app. To learn how to calculate and export the transformation from the app, see Rigid Registration Using Medical Registration Estimator App. Specify the 4-by-4 transformation matrix from the app. The transformation maps the moving volume to the fixed volume, in the patient coordinate system.

    A = [1.0000    0.0041    -0.0004    -6.0548;
        -0.0041    1.0000    -0.0020    -19.9711;
         0.0042    0.0200     1.0000    -5.4140;
         0         0          0          1.0000];

    Create a geometric transformation object defined by the matrix A.

    tform = affinetform3d(A);

    Apply the transformation to update the spatial referencing associated with the moving volume.

    repositionedR = reposition(R,tform)
    repositionedR = 
      medicalref3d with properties:
    
                     VolumeSize: [512 512 28]
                       Position: [28×3 double]
                 VoxelDistances: {[0.6536 -0.0027 0.0027]  [0.0027 0.6536 0.0131]  [-0.0016 -0.0080 4]}
        PatientCoordinateSystem: "LPS+"
                   PixelSpacing: [0.6537 0.6536]
                       IsAffine: 1
                  IsAxesAligned: 0
                        IsMixed: 0
    
    

    Create a new medicalVolume object that associates the moving voxel data with the repositioned spatial referencing object.

    repositionedVolume = medicalVolume(movingVolume.Voxels,repositionedR);

    Display Repositioned Volume

    Display the fixed and repositioned moving volume. The volumes are now aligned in the patient coordinate system.

    viewer2 = viewer3d(BackgroundColor="black",BackgroundGradient="off");
    
    volshow(fixedVolume, ...
        Parent=viewer2, ...
        RenderingStyle="Isosurface", ...
        IsosurfaceValue=0.05, ...
        Colormap=[1 0 1], ...
        Alphamap=1);
    
    volshow(repositionedVolume, ...
        Parent=viewer2, ...
        RenderingStyle="Isosurface", ...
        IsosurfaceValue=0.05, ...
        Colormap=[0 1 0], ...
        Alphamap=1);

    Input Arguments

    collapse all

    Spatial referencing information, specified as a medicalref3d object.

    Geometric transformation, specified as a geometric transformation object or a vector of geometric transformation objects. tform should describe a world transformation in the patient coordinate system, such as one calculated using a registration algorithm. This table lists the types of geometric transformation objects this argument accepts.

    Geometric Transformation ObjectDescription
    transltform3dTranslation transformation
    rigidtform3dRigid transformation, consisting of translation and rotation
    simtform3dSimilarity transformation, consisting of translation, rotation, and isotropic scaling
    affinetform3dAffine transformation, consisting of translation, rotation, anisotropic scaling, reflection, and shearing

    If you specify a vector of geometric transformation objects, the function applies the transformations in the order they appear in the vector.

    Output Arguments

    collapse all

    Transformed spatial referencing information, returned as a medicalref3d object. The properties of repositionedR reflect the updated intrinsic-to-world mapping after applying the transformation.

    Version History

    Introduced in R2025a