Forum

Author Topic: Load images as multiplane cameras  (Read 10114 times)

Gall

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Load images as multiplane cameras
« on: June 24, 2016, 01:08:43 PM »
Hello,

I'm trying to load the first trigger of a MicaSense RedEdge camera to see if this is possible to load a multispectral project from Python. Everything seems to load properly but, if I change the master channel of the chunk, every channel except default displays the last added image.
So, is it possible to load such project from Python?

Here is my test script :

Code: [Select]
import PhotoScan as ps
import glob
import os.path as op

doc = ps.app.document
# Clean project
doc.remove(doc.chunks)

# Multispectral image folder
folder = ps.app.getExistingDirectory('Image folder')
images = glob.iglob(op.join(folder, '*.tif'))

chunk = doc.addChunk()

# Load first image to create sensor
chunk.addPhotos([next(images)])

for path in images:
print(path)
if(len(chunk.cameras) > 1):
chunk.remove([chunk.cameras[-1]])
break

new_cam = chunk.addCamera()
new_cam.open(path)

rig_index = int(new_cam.photo.meta['Pix4D/RigCameraIndex'])
print(new_cam.photo.meta['Pix4D/BandName'], new_cam.photo.meta['Pix4D/RigCameraIndex'])
if(rig_index == 0):
new_cam.sensor = sensor
continue

sensor = chunk.sensors[0]
if(sensor.plane_count <= rig_index):
sensor.plane_count = rig_index + 1
print(sensor.plane_count)

new_sensor = sensor.planes[rig_index]
new_sensor.width, new_sensor.height = sensor.width, sensor.height
new_sensor.focal_length = sensor.focal_length
new_sensor.pixel_size = sensor.pixel_size

cam = chunk.cameras[-2]
print(len(cam.planes), rig_index)
# cam.planes[rig_index].open(path)
cam.planes[rig_index].photo = new_cam.photo
cam.planes[rig_index].sensor = new_sensor
chunk.remove([new_cam])

Here is some output I have for the loaded trigger :
Code: [Select]
>>> chunk = doc.chunk
>>> cam = chunk.cameras[0]
>>> for c in cam.planes:
... print(id(c.photo), c.photo, c.photo.layer, c.key)
...
2016-06-24 11:44:59 556574208 <Photo 'F:/Home/micasense/raw/0000SET_000_0044_1.tif'> 0 0
2016-06-24 11:44:59 556574208 <Photo 'F:/Home/micasense/raw/0000SET_000_0044_2.tif'> 0 0
2016-06-24 11:44:59 556574208 <Photo 'F:/Home/micasense/raw/0000SET_000_0044_3.tif'> 0 0
2016-06-24 11:44:59 556574208 <Photo 'F:/Home/micasense/raw/0000SET_000_0044_4.tif'> 0 0
2016-06-24 11:44:59 556574208 <Photo 'F:/Home/micasense/raw/0000SET_000_0044_5.tif'> 0 0
>>> print(id(cam.photo), cam.photo)
2016-06-24 12:04:38 556574160 <Photo 'F:/Home/micasense/raw/0000SET_000_0044_1.tif'>
With chunk.master_channel set to -1 0000SET_000_0044_1.tif is displayed and with any other value only 0000SET_000_0044_5.tif is displayed.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15090
    • View Profile
Re: Load images as multiplane cameras
« Reply #1 on: July 15, 2016, 07:17:37 PM »
Hello Gall,

Unfortunately, at the moment it is not possible to create multiplane chunks using Python. The problem is that there's no assign certain bands to the planes, even though you can properly input the parameters for newly created planes.
We'll try to implement the missing functionality of Python API in one of the upcoming updates.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Gall

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: Load images as multiplane cameras
« Reply #2 on: August 04, 2016, 10:18:36 AM »
Thanks for the update. I'd be really interested by this feature if you manage to add it.

wyatt.mike@gmail.com

  • Newbie
  • *
  • Posts: 1
    • View Profile
Import multi-spectral images
« Reply #3 on: August 10, 2016, 07:52:32 PM »
Our camera has 4 sensors with R, G, B, and IR filters. We take the images from each sensor and make a multipage tiff out of them. When we load them into PhotoScan with "Workflow > Add Images", we're given the option to import them as multispectral cameras.

Is there any way to do this from from the Python API?

william

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
chunk.addPhotos() for micasense
« Reply #4 on: September 21, 2016, 12:25:42 AM »
In the user interface, there is a way to add multispectral micasense photos: search for 'To create a chunk from MicaSense data' in http://www.agisoft.com/pdf/photoscan-pro_1_2_en.pdf.

In particular, the option "Create multispectral cameras from files as bands" is used.

But there is no mention of that option in the python API for chunk.addPhotos() (see http://www.agisoft.com/pdf/photoscan_python_api_1_2_5.pdf).

Is there any support for a command-line version of that option?

Thanks!

pski7525

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Load images as multiplane cameras
« Reply #5 on: October 06, 2016, 02:03:05 AM »
Quote
We'll try to implement the missing functionality of Python API in one of the upcoming updates.

This is great to hear as this would significantly improve our workflow. Do you have any estimate on when this might be added Alexey (since it's been about 3 months)?
« Last Edit: October 06, 2016, 09:35:06 PM by pski7525 »

pski7525

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Load images as multiplane cameras
« Reply #6 on: October 07, 2016, 10:13:57 PM »
A work around I came up with is I created a reference project with the GUI by adding a multispectral image (thus loading the sensor and bands into the chunk). Then from there, I added Cameras to the chunk, specifying their sensor as the sensor of the chunk and setting the planes, here's my camera loading in action (using a camera that outputs a Red Edge and NIR as separate geotiffs):
Code: [Select]
import os
import PhotoScan as ps

# Assuming all the images are in a single folder and an image for each band
ps.app.document.open(<PATH TO REFERENCE PROJECT>)
chunk = ps.app.document.chunks[0]
sensor = ps.app.document.chunks[0].sensors[0]
bands = ["NIR", "REG"]
for subdir, dirs, files in os.walk(<YOUR PATH TO IMAGES>):
    for file in files:
        if bands[0] not in file:
            continue
        path = op.join(subdir, file)   
        cam = chunk.addCamera()
        cam.label = file
        cam.open(path)
        cam.sensor = sensor
        # This assumes your images are of the same name, just the band is specified in the file name
        for i in range(len(bands)):
            cam.planes[i].open(path.replace(bands[0], bands[i]))
« Last Edit: October 07, 2016, 10:17:22 PM by pski7525 »

feiko.lai

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: chunk.addPhotos() for micasense
« Reply #7 on: October 18, 2016, 06:38:35 PM »
+1 for this feature!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15090
    • View Profile
Re: Load images as multiplane cameras
« Reply #8 on: October 18, 2016, 06:43:27 PM »
Quote
We'll try to implement the missing functionality of Python API in one of the upcoming updates.

This is great to hear as this would significantly improve our workflow. Do you have any estimate on when this might be added Alexey (since it's been about 3 months)?

Hello pski7525,

We hope to implement this functionality to Python API for the version 1.3 final release.
Best regards,
Alexey Pasumansky,
Agisoft LLC

feiko.lai

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Load images as multiplane cameras
« Reply #9 on: October 20, 2016, 07:44:07 AM »
+1 for this feature

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15090
    • View Profile
Re: Load images as multiplane cameras
« Reply #10 on: January 19, 2017, 12:02:51 PM »
Hello,

In the version 1.3 (build 3620) it's already possible to create multichannel chunks using the following approach:

Code: [Select]
list1 = [[rgb[0], nir[0]], [rgb[1], nir[1]], [rgb[2], nir[2]], [rgb[3], nir[3]], [rgb[4], nir[4]]]
chunk.addPhotos(list1, PhotoScan.MultiplaneLayout)
Here the elements in list1 contain the paths to the image files.

In case you are working with Parrot Sequoia or MicaSense RedEdge cameras you can pass the single list to  addPhotos() function and they will be automatically sorted to the multichannel cameras layout.
Best regards,
Alexey Pasumansky,
Agisoft LLC