Forum

Author Topic: Orthophoto rotation  (Read 2966 times)

picare

  • Newbie
  • *
  • Posts: 32
    • View Profile
Orthophoto rotation
« on: November 10, 2020, 06:17:01 PM »
Hi,

I am trying to export an orthophoto and apply a rotation of 90 degrees.

I use Metashape.app.document.chunk.exportRaster() to export a raster. It works fine.

It seems the argument world_transform is made for this. It is a 3x2 matrix (rotation and translation in XY ??)

While applying the next matrix to world_transform, i get a blank very little file:
Metashape.Matrix([[math.cos(anglerad),-math.sin(anglerad),0],[math.sin(anglerad),math.cos(anglerad),0]])

Someone knows what parameters have to be in this matrix, or is it possible to rotate an orthophoto and shift it before exporting?

picare

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Orthophoto rotation
« Reply #1 on: November 24, 2020, 01:28:44 PM »
Anyone has an idea about making a rotation of an orthophoto while exporting it?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14843
    • View Profile
Re: Orthophoto rotation
« Reply #2 on: November 26, 2020, 07:54:38 PM »
Hello picare,

Can you please check, if the following code works properly for 90-degrees clockwise rotation for exported orthomosaic:

Code: [Select]
import Metashape
chunk = Metashape.app.document.chunk
ortho = chunk.orthomosaic
w = ortho.width
h = ortho.height
t = ortho.top
b = ortho.bottom
l = ortho.left
r = ortho.right

A = 0
B = (r - l) / w
C = l
D = (t - b) / h
E = 0
F = b

region = Metashape.BBox()
region.min = Metashape.Vector([l, b])
region.max = Metashape.Vector([r, t])
M = Metashape.Matrix([[A, B, C], [D, E, F]])
chunk.exportRaster("D:/ortho-90.jpg", world_transform = M, region = region)
Best regards,
Alexey Pasumansky,
Agisoft LLC

picare

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Orthophoto rotation
« Reply #3 on: November 27, 2020, 01:30:40 PM »
Hi Alexey, thank you for your response.

The code you provided cut the right part of a cylindrical ortho, and, for an plane ortho, it cut the top part.
No effect on the rotation and position..

The CRS is Local coordinates.

What is the default matrix  (like ([1,0,l][0,1,b] ) ? Is it reconstructed for each export?
« Last Edit: November 27, 2020, 02:00:54 PM by picare »

picare

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Orthophoto rotation
« Reply #4 on: January 12, 2022, 07:12:41 PM »
Hi? I finally restarted my tests and find how to export with a rotation:

on your code, juste invert b/l and r/t like that:
Code: [Select]
region.min = Metashape.Vector([b, l])
region.max = Metashape.Vector([t, r])

My problem now is a jpeg is well exported with the rotation, but the georeference informations is not the good one:
tfw or jgw files are like that, so QGIS and ArcGis make a rotation to have the original image "unrotated", like the original!
Code: [Select]
0
0.005
0.005
0
-7.851481764038356
6738.759166666668

whereas it should be like that:
Code: [Select]
0.005
0
0
-0.005
6738.759166666668
-7.851481764038356

Playing with north_up=False or True has no effect on the tfw or jgw file :(
Do you have any final idea to close this subject?