diff --git a/include/libcamera/internal/matrix.h b/include/libcamera/internal/matrix.h
index f74cda103c72..f563c9cd3a42 100644
--- a/include/libcamera/internal/matrix.h
+++ b/include/libcamera/internal/matrix.h
@@ -24,6 +24,9 @@ LOG_DECLARE_CATEGORY(Matrix)
 template<typename T>
 bool matrixInvert(std::span<const T> dataIn, std::span<T> dataOut, unsigned int dim,
 		  std::span<T> scratchBuffer, std::span<unsigned int> swapBuffer);
+template<typename T>
+void matrixTranspose(std::span<const T> dataIn, std::span<T> dataOut,
+		     unsigned int rows, unsigned int cols);
 #endif /* __DOXYGEN__ */
 
 template<typename T, unsigned int Rows, unsigned int Cols>
@@ -115,6 +118,15 @@ public:
 		return inverse;
 	}
 
+	Matrix<T, Cols, Rows> transpose() const
+	{
+		Matrix<T, Cols, Rows> transposed;
+		matrixTranspose(std::span<const T>(data_),
+				std::span<T>(transposed.data_),
+				Rows, Cols);
+		return transposed;
+	}
+
 private:
 	/*
 	 * \todo The initializer is only necessary for the constructor to be
diff --git a/src/libcamera/matrix.cpp b/src/libcamera/matrix.cpp
index 9cb0885b3b54..b0cb073423c6 100644
--- a/src/libcamera/matrix.cpp
+++ b/src/libcamera/matrix.cpp
@@ -107,6 +107,16 @@ LOG_DEFINE_CATEGORY(Matrix)
  * \return The inverse of the matrix
  */
 
+/**
+ * \fn Matrix::transpose() const
+ * \brief Compute the transpose of the matrix
+ *
+ * This function computes the transpose of the matrix. It is only implemented
+ * for matrices of float and double types.
+ *
+ * \return The transpose of the matrix
+ */
+
 /**
  * \fn Matrix::operator[](size_t i)
  * \copydoc Matrix::operator[](size_t i) const
@@ -309,6 +319,23 @@ template bool matrixInvert<double>(std::span<const double> data, std::span<doubl
 				   unsigned int dim, std::span<double> scratchBuffer,
 				   std::span<unsigned int> swapBuffer);
 
+template<typename T>
+void matrixTranspose(std::span<const T> dataIn, std::span<T> dataOut,
+		     unsigned int rows, unsigned int cols)
+{
+	for (unsigned int row = 0; row < rows; ++row) {
+		for (unsigned int col = 0; col < cols; ++col)
+			dataOut[col * rows + row] = dataIn[row * cols + col];
+	}
+}
+
+template void matrixTranspose(std::span<const float> dataIn,
+			      std::span<float> dataOut,
+			      unsigned int rows, unsigned int cols);
+template void matrixTranspose(std::span<const double> dataIn,
+			      std::span<double> dataOut,
+			      unsigned int rows, unsigned int cols);
+
 /*
  * The value node shall be a list of numerical values. Its size shall be equal
  * to the product of the number of rows and columns of the matrix (Rows x
