Forum

Author Topic: How do I set output size of orthomosaic  (Read 5393 times)

Samuel

  • Newbie
  • *
  • Posts: 2
    • View Profile
How do I set output size of orthomosaic
« on: December 19, 2017, 11:41:52 PM »
I have been developing some code to automatically process, save and export data. For part of the necessary use of the data I need the orthomosaic to be of a certain maximum dimension, using the gui I can just use the "Max. dimention (pix): " option to set the maximum size for the exported image.

My question is: How do I do that with python? the only options I have found in the API are dx, dy which the API makes sound to be the programmatic version of the gui's "Pixel size: "  option, or blockh, blockw which seem to relate to the "Split into blocks (pix):" option.

currently i am using some python code to resize the full sized orthomosaic down to what I need after exporting but every time it runs I get a "pixel count too large: could be a decompression bomb attack" warning.

PhotoScan Version: 1.3.2 build 4205 (64 bit)

mikeb

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: How do I set output size of orthomosaic
« Reply #1 on: January 12, 2018, 05:29:54 PM »
I'm also very interested in a solution regarding this problem.
I'm also running into the same problem. And I also need the function to export the orthomosaic in a specific dimension in pix.

Hope someone got an answer for this.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: How do I set output size of orthomosaic
« Reply #2 on: January 12, 2018, 09:49:12 PM »
Hello mikeb,

You can use the following methods related to orthomosaic to calculate the require export resolution:
chunk.orthomosaic.width
chunk.orthomosaic.height
chunk.orthomosaic.resolution

So if you need to export the orthomosaic using max-dimension = X, then I think you can use the following:

Code: [Select]
dx = dy = max(chunk.orthomosaic.width, chunk.orthomosaic.height) * chunk.orthomosaic.resolution / X
Best regards,
Alexey Pasumansky,
Agisoft LLC

mikeb

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: How do I set output size of orthomosaic
« Reply #3 on: January 15, 2018, 11:03:35 AM »
Thank you for your answer, but it still export a huge image.
I want the maximum size of the orthomosaic the same size as my exported DEM.
In the GUI I choose in the export window Max. dimension (pix) and choose 4122.
But if I do it in the python script the size is still the same. I think its not possible to use dx and dy the same so I just use one of it and still does not work. If I use dx and dy in the exportorthomosaic function it returns with an Runtime Error: Empty Raster.
Can you tell what I'm doing wrong. I want to use the same size as my DEM (max dimension = 4122)

Here is my codesnippet:

Code: [Select]
dx = dy = max(chunk.orthomosaic.width, chunk.orthomosaic.height) * chunk.orthomosaic.resolution / 4122.0

chunk.exportOrthomosaic(project_path + project_name + ".tif", image_format=PhotoScan.ImageFormatTIFF, format = PhotoScan.RasterFormatTiles, dy=dy, raster_transform=PhotoScan.RasterTransformNone, write_kml=False, write_world=True)

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: How do I set output size of orthomosaic
« Reply #4 on: January 15, 2018, 11:58:15 AM »
Hello mikeb,

Is your project referenced in WGS84?

If so, then you need to convert meters for dx and dy parameters to degrees.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: How do I set output size of orthomosaic
« Reply #5 on: January 15, 2018, 08:45:48 PM »
Hello mikeb,

Here's a small code for conversion from meters to lat/long values. As source export resolution it takes the DEM resolution:

Code: [Select]
import PhotoScan, math

dx = dy = chunk.elevation.resolution


coord = PhotoScan.Vector([0,0,0])
cam_num = 0
for camera in chunk.cameras:
if not camera.transform:
continue
coord += chunk.crs.project(chunk.transform.matrix.mulp(camera.center))
cam_num += 1

crd = (1. / cam_num) * coord

#crd = chunk.crs.project(chunk.transform.matrix.mulp(chunk.region.center))

v1 = crd.copy()
v2 = PhotoScan.Vector([crd.x + 0.001, crd.y, crd.z])
vm1 = chunk.crs.unproject(v1)
vm2 = chunk.crs.unproject(v2)
res_x = (vm2 - vm1).norm() * 1000

#latitude
v2 = PhotoScan.Vector([crd.x, crd.y + 0.001, crd.z])
vm2 = chunk.crs.unproject(v2)
res_y = (vm2 - vm1).norm() * 1000

dx = dx / res_x
dy = dy / res_y

path = project_path + project_name + ".tif"
chunk.exportOrthomosaic(path, image_format=PhotoScan.ImageFormatTIFF, format = PhotoScan.RasterFormatTiles, dx=dx, dy=dy, raster_transform=PhotoScan.RasterTransformNone, write_kml=False, write_world=True)
Best regards,
Alexey Pasumansky,
Agisoft LLC