Forum

Author Topic: Export orthomosaic per MultiPlane  (Read 1805 times)

htk

  • Newbie
  • *
  • Posts: 3
    • View Profile
Export orthomosaic per MultiPlane
« on: August 31, 2018, 01:41:20 PM »
I want to export each wavelength sensor to different orthomosaics, when using
Code: [Select]
chunk.addPhotos(..., PhotoScan.MultiplaneLayout)
I noticed that
Code: [Select]
chunk.raster_transform.formula allows me to select one using 'B1', ..., 'B4'. However, the meaning of them is not respective to my input in images (REG, RED, GRE, NIR). Moreover,
Code: [Select]
chunk.cameras[0].planes also shows a different order.

  • How can I exporte each wavelength (REG, RED, GRE, NIR) seperately and know which one is which?
  • What do the B1, B2, B3 and B4 stand for?
  • Why aren't they REG, RED, GRE and NIR?
  • Why are the orders of the planes and what I specified in images inconsistent?

This is the code I currently use to do this, but it seems hacky and possibly buggy.

Code: [Select]
import PhotoScan

document = PhotoScan.app.document
chunk = document.chunk

images = [
    ['a_REG.TIF', 'a_RED.TIF', 'a_GRE.TIF', , 'a_NIR.TIF', ],
    ['b_REG.TIF', 'b_RED.TIF', 'b_GRE.TIF', , 'b_NIR.TIF', ],
    ['c_REG.TIF', 'c_RED.TIF', 'c_GRE.TIF', , 'c_NIR.TIF', ],
    ...
]

chunk.addPhotos(images, PhotoScan.MultiplaneLayout)
....
chunk.buildOrthomosaic(...)

# for each camera, find out the order of the REG, RED, GRE and NIR planes,
# all tuples should be the same, otherwise the order seems undefined,
# the order is in general different from the one using in the images-subarrays.

channels = {
    tuple(p.label[-3:] for p in cam.planes)
    for cam in chunk.cameras
}

# make sure that the order is consistent among camera's
assert len(channels) == 1, "Found inconsistent planes or plane orders on differnt cameras: " + str(channels)
# extract the one order.
channels = list(next(iter(channels)))

Match these orders with the 'B1' ... 'B4' bands created by
for band, channel in zip(['B1', 'B2', 'B3', 'B4'], channels):
    # select one band
    chunk.raster_transform.formula = [band]
    # export that band as an orthamosaic
    chunk.exportOrthomosaic(project_path + project_name + "_" + channel + ".tif", image_format=PhotoScan.ImageFormatTIFF,
                        format=PhotoScan.RasterFormatTiles, raster_transform=PhotoScan.RasterTransformValue,
                        write_kml=False, write_world=True, tiff_overviews=False, write_alpha=True, progress=progress)


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14854
    • View Profile
Re: Export orthomosaic per MultiPlane
« Reply #1 on: August 31, 2018, 07:13:51 PM »
Hello htk,

The order of input bands in PhotoScan (B1, B2, B3...) for MicaSense RedEdge and Parrot Sequoia cameras is selected according to the central wavelength information from the image meta data.
For such cases you can use this workaround similar to yours:
Code: [Select]
order = {"Blue": "B5", "Green": "B3", "Red": "B2", "NIR": "B4", "Rededge": "B1"}
for sensor in chunk.sensors:
    chunk.raster_transform.formula = order[sensor.bands[0]]
    chunk.exportOrthomosaic(project_path + project_name + "_" + sensor.bands[0] + ".tif", image_format=PhotoScan.ImageFormatTIFF,
                        format=PhotoScan.RasterFormatTiles, raster_transform=PhotoScan.RasterTransformValue,
                        write_kml=False, write_world=True, tiff_overviews=False, write_alpha=True, progress=progress)
Best regards,
Alexey Pasumansky,
Agisoft LLC

htk

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Export orthomosaic per MultiPlane
« Reply #2 on: September 03, 2018, 02:52:05 PM »
Thanks!

I updated the code a little bit, in particular formula should be a list.

Code: [Select]
sensor_to_band = {"Blue": "B5", "Green": "B3", "Red": "B2", "NIR": "B4", "Red edge": "B1"}
for sensor in chunk.sensors:
    sensor = sensor.bands[0]
    band = sensor_to_band[sensor]
    chunk.raster_transform.formula = [band]
    fn = project_name + "_" + sensor + ".tif"

    chunk.exportOrthomosaic(project_path + fn,
                            image_format=PhotoScan.ImageFormatTIFF,
                            format=PhotoScan.RasterFormatTiles, raster_transform=PhotoScan.RasterTransformValue,
                            write_kml=False, write_world=True, tiff_overviews=False, write_alpha=True,
                            progress=progress)

htk

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Export orthomosaic per MultiPlane
« Reply #3 on: September 04, 2018, 06:17:20 PM »
Hi Alexey,

I used your code to calculate the orthomosaic for all channels at once, using MultiPlaneLayout, and used a script to calculate them seperately, using FlatLayout during addPhotos.

Using the cosine distance on a histogram binned from 0 to 65536, I noticed the REG and GRE channels seem to be mixed up.

Code: [Select]
at once channel RED matches most with seperate channel RED at histogram cosine distance of 0.0081
other distances:  REG     GRE     NIR
                  0.0834  0.0135  0.0398
at once channel REG matches most with seperate channel GRE at histogram cosine distance of 0.0050
other distances:  RED     REG     NIR
                  0.0053  0.0755  0.0345
at once channel GRE matches most with seperate channel REG at histogram cosine distance of 0.0024
other distances:  RED     GRE     NIR
                  0.0838  0.0904  0.0284
at once channel NIR matches most with seperate channel NIR at histogram cosine distance of 0.0032
other distances:  RED     REG     GRE
                  0.0354  0.0194  0.0431

Visually this also seems to be true:

https://gist.github.com/prinsherbert/9134fd04562708228714b79da37d51c5

Are you sure this should not be updated? Did you mix up GRE and REG?

Code: [Select]
order = {"Blue": "B5", "Green": "B1", "Red": "B2", "NIR": "B4", "Rededge": "B3"}
Thanks in advance!
« Last Edit: September 04, 2018, 06:19:19 PM by htk »