This is the code that I looking for in order to convert the physical points to the pixel array.

**I have an issue regarding the m_PhysicalPointToIndex calculation here.**

I just implemented the code as below.

In the beginning, I have initialized m_Direction, m_InverseDirection, m_IndexToPhysicalPoint and m_PhysicalPointToIndex to identity.

Then I have implemented the similar functionality in python as in the aforementioned C++ code (i.e. ComputeIndexToPhysicalPointMatrices)

But, then I have got an error as indicated below. I know that the inverse of (m_Direction * scale) gives a Singular matrix because these are diagonal matrices.

**My question is that how can I calculate m_PhysicalPointToIndex since this matrix is needed in order to calculate the pixel indices in TransformPhysicalPointToIndex function ?**

Any help will be appreciated.

```
VImageDimension = 3
MatrixType = itk.Matrix[itk.D, VImageDimension, VImageDimension]
m_Direction = MatrixType()
m_Direction.SetIdentity()
m_InverseDirection = MatrixType()
m_InverseDirection.SetIdentity()
m_IndexToPhysicalPoint = MatrixType()
m_IndexToPhysicalPoint.SetIdentity()
m_PhysicalPointToIndex = MatrixType()
m_PhysicalPointToIndex.SetIdentity()
scale = MatrixType()
# Compute helper matrices used to transform Index coordinates to
# PhysicalPoint coordinates and back. This method is virtual and will be
# overloaded in derived classes in order to provide backward compatibility
# behavior in classes that did not used to take image orientation into
# account.
for i in range(VImageDimension):
# scale(i, i) = m_Spacing[i]
scale.GetVnlMatrix().put(i,i,m_Spacing[i])
m_IndexToPhysicalPoint = m_Direction * scale
m_PhysicalPointToIndex = m_IndexToPhysicalPoint.GetInverse()
```

The Error Message is below.

```
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-121-a723dfc49746> in <module>()
8 scale.GetVnlMatrix().put(i,i,m_Spacing[i])
9 m_IndexToPhysicalPoint = m_Direction * scale
---> 10 m_PhysicalPointToIndex = m_IndexToPhysicalPoint.GetInverse()
RuntimeError: c:\p\ipp\standalone-build\itks\modules\core\common\include\itkMatrix.h:252:
itk::ERROR: Singular matrix. Determinant is 0.
```