Forum

Author Topic: Crop to region bounded by control points  (Read 4968 times)

Dragline

  • Newbie
  • *
  • Posts: 34
    • View Profile
Crop to region bounded by control points
« on: May 08, 2018, 09:15:17 PM »
I typically fly an area larger than necessary to ensure that control points are present in many photos. This means that a large amount of the DEM that is produced is not up to our quality standards. Currently I use global mapper to crop the area of the DEM that is outside of the boundary of the control points. It would be nice to be able to automate this task. Maybe offer this in the DEM export dialog box? Possibly also allow for a buffer region beyond the control point boundary?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Crop to region bounded by control points
« Reply #1 on: May 08, 2018, 09:19:25 PM »
Hello Dragline,

I can suggest to consider importing the shape file that would define the export area, as it seems more convenient.

But if you need to create the export boundary basing on the markers, it can be also done, but should all the markers used for that and what would be their order?
Best regards,
Alexey Pasumansky,
Agisoft LLC

Dragline

  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: Crop to region bounded by control points
« Reply #2 on: May 08, 2018, 09:28:28 PM »
I like the shapefile idea. I'll give that a try. This should work for when I am working with my permanent control points

In regards to a more automated solution. I imagine creating a polygon that surrounds all control points which is of a minimal perimeter.

Something like the boundary shown in this image:



The more automated solution would be helpful for when temporary control points are used.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Crop to region bounded by control points
« Reply #3 on: May 08, 2018, 09:54:19 PM »
Hello Dragline,

Here's a quick basic script that takes the markers in their project order and uses them to create a shape vertices, the shape is automatically set as outer boundary:

Code: [Select]
chunk = PhotoScan.app.document.chunk
T = chunk.transform.matrix
crs = chunk.crs
if not chunk.shapes:
chunk.shapes = PhotoScan.Shapes()
chunk.shapes.crs = chunk.crs

shape = chunk.shapes.addShape()
shape.label = "boundary"
shape.type = PhotoScan.Shape.Polygon
shape.boundary_type = PhotoScan.Shape.BoundaryType.OuterBoundary

coords = [crs.project(T.mulp(marker.position)) for marker in chunk.markers]
shape.vertices = [PhotoScan.Vector([coord.x, coord.y]) for coord in coords]

If you need add some "buffer" I think that you can recalculate the vertices' locations, for example, move the vertex away from the area center by the line that connects the origin and the old vertex location. Let me know, if you need any help with that.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Endure1

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Crop to region bounded by control points
« Reply #4 on: October 29, 2020, 05:35:56 AM »
Hello Dragline,

I can suggest to consider importing the shape file that would define the export area, as it seems more convenient.

But if you need to create the export boundary basing on the markers, it can be also done, but should all the markers used for that and what would be their order?

Would you post the snippit of code used to import the shape file to define the export area please?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Crop to region bounded by control points
« Reply #5 on: November 17, 2020, 09:21:29 PM »
Hello Endure1,

If in the external file with the shapes contains only polygonal shapes that should be used for the export area definition, you can specify that on import:
Code: [Select]
chunk.importShapes(path, boundary_type= Metashape.Shape.OuterBoundary)
Then in the export function use clip_to_boundary = True argument.
Best regards,
Alexey Pasumansky,
Agisoft LLC