# Help regarding RTK geometric projection

**URL:** <https://discourse.itk.org/t/help-regarding-rtk-geometric-projection/7225>\
**Category:** Algorithms\
**Tags:** rtk\
**Created:** [September 18, 2024, 3:37am UTC](https://discourse.itk.org/t/help-regarding-rtk-geometric-projection/7225 "2024-09-18T03:37:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ma1282029525](https://discourse.itk.org/user_avatar/discourse.itk.org/ma1282029525/32/3084_2.png) [@ma1282029525](https://discourse.itk.org/u/ma1282029525)\
**Post date:** [September 18, 2024, 3:37am UTC](https://discourse.itk.org/t/help-regarding-rtk-geometric-projection/7225/1 "2024-09-18T03:37:47Z")

</div>

I have calculated the projection matrix and verified the re-projection to confirm there are no issues. However, when I tried to add the calculated matrix using AddProjection, I encountered an error: WARNING: In D:\rtk\RTK-2.4.1\src\rtkThreeDCircularProjectionGeometry.cxx, line 357 DataObject (0000018E27CD88D0): Failed to AddProjection

---

<div class="post-metadata">

**Author:** ![ma1282029525](https://discourse.itk.org/user_avatar/discourse.itk.org/ma1282029525/32/3084_2.png) [@ma1282029525](https://discourse.itk.org/u/ma1282029525)\
**Post date:** [September 18, 2024, 3:38am UTC](https://discourse.itk.org/t/help-regarding-rtk-geometric-projection/7225/2 "2024-09-18T03:38:49Z")

</div>

```auto
Eigen::Matrix<double, 3, 4> getProjectionTransformMatrix3D(
	const std::vector<double>& srcX,
	const std::vector<double>& srcY,
	const std::vector<double>& srcZ,
	const std::vector<double>& dstU,
	const std::vector<double>& dstV,
	double detectorElementSize) {

	size_t n = srcX.size();
	Eigen::MatrixXd S(n * 2, 11);
	S.setZero();

	for (size_t i = 0; i < n; ++i) {
		S(2 * i, 0) = -srcX[i];
		S(2 * i, 1) = -srcY[i];
		S(2 * i, 2) = -srcZ[i];
		S(2 * i, 3) = -1;
		S(2 * i, 8) = dstU[i] * srcX[i];
		S(2 * i, 9) = dstU[i] * srcY[i];
		S(2 * i, 10) = dstU[i] * srcZ[i];

		S(2 * i + 1, 4) = -srcX[i];
		S(2 * i + 1, 5) = -srcY[i];
		S(2 * i + 1, 6) = -srcZ[i];
		S(2 * i + 1, 7) = -1;
		S(2 * i + 1, 8) = dstV[i] * srcX[i];
		S(2 * i + 1, 9) = dstV[i] * srcY[i];
		S(2 * i + 1, 10) = dstV[i] * srcZ[i];
	}

	Eigen::VectorXd C(n * 2);
	for (size_t i = 0; i < n; ++i) {
		C(2 * i) = -dstU[i];
		C(2 * i + 1) = -dstV[i];
	}

	Eigen::VectorXd Unknown = (S.transpose() * S).inverse() * S.transpose() * C;
	Eigen::Matrix<double, 3, 4> P;
	P << Unknown(0), Unknown(1), Unknown(2), Unknown(3),
		Unknown(4), Unknown(5), Unknown(6), Unknown(7),
		Unknown(8), Unknown(9), Unknown(10), 1;

	Eigen::Matrix3d A_inv = P.leftCols<3>();
	Eigen::Matrix3d A = A_inv.inverse();

	Eigen::Vector3d e_u = A.col(0);
	double L_u_cal = e_u.norm();
	double ratio = L_u_cal / detectorElementSize;

	Eigen::Matrix<double, 3, 4> new_P = ratio * P;

	return new_P;
}

```

This is my function for calculating the projection matrix

---

<div class="post-metadata">

**Author:** ![ma1282029525](https://discourse.itk.org/user_avatar/discourse.itk.org/ma1282029525/32/3084_2.png) [@ma1282029525](https://discourse.itk.org/u/ma1282029525)\
**Post date:** [September 18, 2024, 3:40am UTC](https://discourse.itk.org/t/help-regarding-rtk-geometric-projection/7225/3 "2024-09-18T03:40:12Z")

</div>

I even tried to generate a projection matrix from the projected points, but the generated matrix still couldn’t be added in

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [September 18, 2024, 3:35pm UTC](https://discourse.itk.org/t/help-regarding-rtk-geometric-projection/7225/4 "2024-09-18T15:35:16Z")

</div>

This question is maybe more appropriate for the [RTK mailing list](https://www.openrtk.org/RTK/project/contactus.html). But @simon.rit might answer it here, too.

---

<div class="post-metadata">

**Author:** ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)\
**Post date:** [September 18, 2024, 3:40pm UTC](https://discourse.itk.org/t/help-regarding-rtk-geometric-projection/7225/5 "2024-09-18T15:40:58Z")

</div>

I don’t have time to closely check code but the addition fails if it can’t decompose the projection matrix in parameters, see the code [here](https://github.com/RTKConsortium/RTK/blob/master/src/rtkThreeDCircularProjectionGeometry.cxx#L253). If you know the source and detector positions + the detector orientation, there is no need to compute the projection matrix yourself, just let RTK do it using [this version](https://github.com/RTKConsortium/RTK/blob/master/src/rtkThreeDCircularProjectionGeometry.cxx#L154).
