Documentation Center

  • Trial Software
  • Product Updates

worldToSubscript

Class: imref3d

World coordinates to row and column subscripts

Syntax

[I,J,K] = worldToSubscript(R,xWorld,yWorld,zWorld)

Description

[I,J,K] = worldToSubscript(R,xWorld,yWorld,zWorld) maps point locations from the world system (xWorld,yWorld,zWorld) to subscript arrays I, J, and K, based on the relationship defined by the spatial referencing object R. I, J, and K are the row, column, and plane subscripts of the image voxels identified by their world coordinates (xWorld, yWorld, zWorld). xWorld, yWorld, and zWorld must have the same size. I, J, and K have the same size as xWorld, yWorld, and zWorld. For an m-by-n-by-p image, 1 <= I <= M, 1 <= J <= N, and 1 <= K <= P. If a point xWorld(k), yWorld(k), zWorld(k) falls outside the image, as defined by contains(R,xWorld, yWorld, zWorld), worldToSubscript sets the returned subscripts, I(k), J(k), and K(k) to NaN.

Input Arguments

R

Spatial referencing object, imref3d, associated with an image.

xWorld

Coordinates along the X dimension in world system, specified as a numeric scalar or vector

yWorld

Coordinates along the Y dimension in world system, specified as a numeric scalar or vector

zWorld

Coordinates along the Z dimension in world system, specified as a numeric scalar or vector

Output Arguments

I

Row coordinates, returned as a numeric scalar or vector the same size as yWorld.

J

Column coordinates, returned as a numeric scalar or vector the same size as xWorld.

K

Plane coordinates, returned as a numeric scalar or vector the same size as zWorld.

Examples

expand all

Convert World Coordinates to Subscripts

Read an image.

 I = imread('peppers.png');

Create an imref3d object and associate it with the image.

 R = imref3d(size(I))
R = 

 imref3d

  Properties:
           XWorldLimits: [0.5000 512.5000]
           YWorldLimits: [0.5000 384.5000]
           ZWorldLimits: [0.5000 3.5000]
              ImageSize: [384 512 3]
    PixelExtentInWorldX: 1
    PixelExtentInWorldY: 1
    PixelExtentInWorldZ: 1
    ImageExtentInWorldX: 512
    ImageExtentInWorldY: 384
    ImageExtentInWorldZ: 3
       XIntrinsicLimits: [0.5000 512.5000]
       YIntrinsicLimits: [0.5000 384.5000]
       ZIntrinsicLimits: [0.5000 3.5000]

Convert the world coordinates to subscripts.

[m n p] = worldToSubscript(R,30,50,3)
m =

     50

n =

     30

p =

     3
Was this topic helpful?