Forum

Author Topic: Syntax for exportRaster image compression  (Read 4426 times)

w28

  • Newbie
  • *
  • Posts: 11
    • View Profile
Syntax for exportRaster image compression
« on: September 06, 2023, 05:31:08 AM »
What's the proper syntax for setting the image compression for the exportRaster method? I'm trying to export an RGB orthomosaic to a Geotiff with JPG compression, quality=90, using the code below:

Code: [Select]
import Metashape

chunk = Metashape.app.document.chunk

compression = Metashape.ImageCompression
compression.tiff_compression = Metashape.ImageCompression.TiffCompressionJPEG
compression.jpeg_quality = 90


out_projection = Metashape.OrthoProjection()
out_projection.type = Metashape.OrthoProjection.Type.Planar
out_projection.crs = Metashape.CoordinateSystem("EPSG::32610")

chunk.exportRaster(path = 'D:\my\output\path\geotiff.tif',
                    source_data = Metashape.DataSource.OrthomosaicData,
                    format = Metashape.RasterFormatTiles,
                    image_format = Metashape.ImageFormatTIFF,
                    image_compression = compression,
                    save_alpha = True,
                    white_background = True,
                    resolution_x = 0.10,
                    resolution_y = 0.10,
                    projection = out_projection
                    )


But I keep getting this error.

Code: [Select]
TypeError: invalid value type
I'm guessing I must have the ImageCompression syntax wrong, but I haven't been able to find an example of the correct way of doing this in the forums.
« Last Edit: September 06, 2023, 06:42:40 AM by w28 »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15177
    • View Profile
Re: Syntax for exportRaster image compression
« Reply #1 on: September 06, 2023, 06:20:28 PM »
Hello w28,

I think you need to use compression = Metashape.ImageCompression() assignment (with the brackets), like for OrthoProjection variable.

Note that if you are checking it in Metashape Console pane, you may need to re-start Metashape, as with the wrong assignment ImageComprassion class could be broken already.
Best regards,
Alexey Pasumansky,
Agisoft LLC

w28

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Syntax for exportRaster image compression
« Reply #2 on: September 06, 2023, 07:01:32 PM »
That worked!  Restarting was key, since I think the previous mistake I made had broken things.  Thanks!