ITK图像下标与物理位置的转换及内部计算
描述
ITK本身提供了图像物理位置和图像下标的转换接口,即在提供了准确的必要图像信息(包括origin, spacing, direction of the image samples )之后,可以使用
T
r
a
n
s
f
o
r
m
P
h
y
s
i
c
a
l
P
o
i
n
t
T
o
I
n
d
e
x
(
)
TransformPhysicalPointToIndex()
TransformPhysicalPointToIndex() ,将物理位置转换为图像下标,函数返回bool值,表明该物理点是否在图像内部。
T
r
a
n
s
f
o
r
m
I
n
d
e
x
T
o
P
h
y
s
i
c
a
l
P
o
i
n
t
TransformIndexToPhysicalPoint
TransformIndexToPhysicalPoint , 将图像下标转为物理位置点。
其内部转换关系如下
图像下标index 转物理 坐标
其中
I
⃗
\vec {I}
I: 图像空间下标
P
⃗
\vec{P}
P:
I
⃗
\vec {I}
I对应的待求的物理空间点
O
⃗
\vec{O}
O: 图像origin
D
⃗
\vec{D}
D: direction的余弦矩阵(正交),表示图像与物理空间坐标系的方向关系
S
⃗
\vec{S}
S: 像素间距
上述过程也可看作一个线性变换:
Matlab实现示例
% Non-identity Spacing and Direction
spacing=diag( [0.9375, 0.9375, 1.5] );
direction=[0.998189, 0.0569345, -0.0194113;
0.0194429, -7.38061e-08, 0.999811;
0.0569237, -0.998378, -0.00110704];
point = origin + direction * spacing * LeftEyeIndex
C/C++代码mathematical expansion
using MatrixType = itk::Matrix<double, Dimension, Dimension>;
MatrixType SpacingMatrix;
SpacingMatrix.Fill( 0.0F );
const ImageType::SpacingType & ImageSpacing = image->GetSpacing();
SpacingMatrix( 0,0 ) = ImageSpacing[0];
SpacingMatrix( 1,1 ) = ImageSpacing[1];
SpacingMatrix( 2,2 ) = ImageSpacing[2];
const ImageType::DirectionType & ImageDirectionCosines =
image->GetDirection();
const ImageType::PointType &ImageOrigin = image->GetOrigin();
using VectorType = itk::Vector< double, Dimension >;
VectorType LeftEyeIndexVector;
LeftEyeIndexVector[0]= LeftEyeIndex[0];
LeftEyeIndexVector[1]= LeftEyeIndex[1];
LeftEyeIndexVector[2]= LeftEyeIndex[2];
ImageType::PointType LeftEyePointByHand =
ImageOrigin + ImageDirectionCosines * SpacingMatrix * LeftEyeIndexVector;
2021.12.28增加
image orientation 与 direction
image orientation
image orientation 描述的是,采集患者数据时,患者自身坐标系与采集设备坐标系的空间关系,比如正卧,半躺,前倾等。该数据说明了采集后的图像中,患者的姿态问题。
比如,假设数据准确,不必看图就可以直接根据orientation计算出患者是趴着扫描的还是躺着、斜着扫描的。
比如 大部分图像的余弦向量为(1,0,0)和(0,1,0),某个图像的为(1,0,0)和(0,-1,0),则该图像经过重建后,就与正常图像是相反的,需要将其旋转180度得到正常体位的图像。但图像是反的这个事情,本身并不是orientation这个东西决定的,图像内部数据已经是反着存储的,orientation只是提供了一个表征说明。(图像重建不依赖与orientation ?)
orientation 属于 dicom概念。
image direction
itk的image direction 描述的是itk图像中, 像素坐标与物理坐标对应的一种关系。即怎样从图像的像素坐标计算出其物理坐标。 属于itk图像概念。调整direction可以实现内容旋转的效果。