Main Content

reposition

Update position of medical volume in patient coordinates

Since R2025a

    Description

    medVolRepositioned = reposition(medVol,tform) updates the spatial referencing of the medicalVolume object medVol according to the geometric transformation tform to change the position of the volume in the patient coordinate system. The underlying image data in the Voxels property of medVol remains unchanged.

    example

    Examples

    collapse all

    Apply a geometric transformation that changes the location of a medical volume in the patient coordinate system. This approach updates the spatial referencing of a medicalVolume object, which defines the mapping between the intrinsic and patient coordinate systems, without modifying or resampling the underlying voxel data.

    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);

    Display Unaligned Volumes

    Display the fixed and moving volumes in patient coordinates. Note that the volumes are not aligned due to differences in patient position in the scanners.

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

    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 location of the moving volume and align it with the fixed volume in patient coordinates.

    repositionedVolume = reposition(movingVolume,tform);

    Display Repositioned Volume

    Display the fixed and repositioned moving volume. Note that 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

    Medical volume, specified as a medicalVolume 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

    Repositioned medical volume, returned as a medicalVolume object. The VolumeGeometry property of medVolRepositioned contains an updated medicalref3d object whose intrinsic-to-world mapping reflects the geometric transformation. The voxel data stored in the Voxels property of medVolReposition is the same as that of the input volume medVol.

    Tips

    • Use the reposition object function to change the location of a medical volume in patient coordinates without resampling the underlying voxel data. For example, apply the geometric transformation returned by a registration function to display registered volumes in the patient coordinate system using volshow. If your application requires you to resample the voxel data to match another volume, such as to view image slices together as an overlay or perform voxelwise comparisons, use the resample function and specify the WorldTransform name-value argument.

    • To update the orientation of the voxel data without changing the position of the volume in the patient coordinate system, use the updateOrientation function.

    Version History

    Introduced in R2025a