Forum

Author Topic: Add covariance matrix export  (Read 3201 times)

JRM

  • Jr. Member
  • **
  • Posts: 81
    • View Profile
Add covariance matrix export
« on: August 09, 2019, 10:15:06 AM »
Hi,

It would be great to export the co-variance matrix to a raster grid or as the scalar field of a point cloud, this would allow this information to be used with other GIS layers. Adding it to the report would be cool too !

Joe Adams

  • Newbie
  • *
  • Posts: 8
  • UAS for Science
    • View Profile
    • USGS NUSO
Re: Add covariance matrix export
« Reply #1 on: January 27, 2021, 07:50:40 PM »
Hi JRM:

Did you find a solution for this?

We very much would like an easy UI for exporting the covariance values also.

I did find Alexey posted a code snippet which accesses these values with Python. I currently don't have time or brain power to pursue this:

https://www.agisoft.com/forum/index.php?topic=11218.msg50653#msg50653

Joe.
Joe Adams
UAS Operator
USGS National Uncrewed Systems Office
Denver, Colorado

Paulo

  • Hero Member
  • *****
  • Posts: 1303
    • View Profile
Re: Add covariance matrix export
« Reply #2 on: January 27, 2021, 10:18:49 PM »
Hi all,

for each point_id in points = chunk.point_cloud.points the cov matrix is given in the internal coordinate system. To get the cov matrix in LSE CS (localEast, Localnorth, Up) with origin at center of chunk.region, by using propagation of variance-covariance law:

Code: [Select]
cov = points[point_id].cov
cov = R * cov * R.t()

where R is determined by:

Code: [Select]
M = chunk.transform.matrix
s = chunk.transform.scale
chunk.resetRegion()
m = chunk.crs.localframe(M.mulp(chunk.region.center))
T = m * M
R = s * T.rotation()

Now the transformed cov is a 3 x 3 matrix so exporting it as a scalar field would be problem...you could just export the vector field (Sx, Sy, Sz) using the sqrt of diagonal elements of transformed cov matrix.

For example relevant cov matrix for first point in chunk.point_cloud.points would be:
Code: [Select]
points[0].cov    # covariance matrix in internal CS
Out[7]: 2021-01-27 13:22:44
2021-01-27 13:22:44 Matrix([[3.0006225415490917e-07, -1.619653744455718e-07, -4.6811774723209965e-07],
2021-01-27 13:22:44        [-1.619653744455718e-07, 6.674043220300518e-07, 1.1982299383817008e-06],
2021-01-27 13:22:44        [-4.6811774723209965e-07, 1.1982299383817008e-06, 3.727560169863864e-06]])

R * points[0].cov * R.t()    # covariance matrix in LSE CS with origin at chunk region center
Out[8]: 2021-01-27 13:22:56
2021-01-27 13:22:56 Matrix([[0.0025407878501558807, 0.0007874548004021441, -0.004730312985074604],
2021-01-27 13:22:56        [0.000787454800402144, 0.0014958743002914435, -0.002598802301929944],
2021-01-27 13:22:56        [-0.004730312985074604, -0.0025988023019299436, 0.01712588634164101]])
« Last Edit: January 27, 2021, 10:53:11 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

Joe Adams

  • Newbie
  • *
  • Posts: 8
  • UAS for Science
    • View Profile
    • USGS NUSO
Re: Add covariance matrix export
« Reply #3 on: January 27, 2021, 11:05:45 PM »
Thank you Paul.

This is very helpful.

Joe
Joe Adams
UAS Operator
USGS National Uncrewed Systems Office
Denver, Colorado