Forum

Author Topic: Multispectral Cameras from Files as Bands  (Read 4372 times)

johnlionas

  • Newbie
  • *
  • Posts: 5
    • View Profile
Multispectral Cameras from Files as Bands
« on: May 07, 2018, 03:51:39 PM »
I need to process a set of photos. The set includes photos (.tif format) from consecutive spots of a geographic area and from 4 different bands. I can easily perform the desired processing using GUI and I wish to perform the exact same steps with python commands. The processing involves loading the photos with the option “Create multispectral cameras from files as bands” selected, then photos alignment and finally the creation of a dense cloud, a mesh and an orthomosaic.

I try to reproduce these steps using python commands, but it seems that I fail in the very first step of loading the photos. I execute the command chunk.addPhotos(images, PhotoScan.MultiplaneLayout) with the argument images being a list. Every element of this list corresponds to the images from all the different bands taken at a specific point. Specifically it is another list with every element being a string representing the complete path of the image. Running this command is usually successful but it does not seem to produce the same result with the load using gui. The problem appears after executing the alignment step with the command:

chunk.matchPhotos(PhotoScan.LowAccuracy, generic_preselection=True,  reference_preselection = True, filter_mask=False, keypoint_limit=40000, tiepoint_limit=4000) 

After running this command, the dense cloud option is not available as it is the case when I do the processing using GUI. The only noticeable difference when I am loading photos using the python function is that several errors occur in the console with the message “Error: Null sensor”. Am I doing something wrong?

selimerguden

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Multispectral Cameras from Files as Bands
« Reply #1 on: May 08, 2018, 05:33:08 PM »
Hey John,

What multi-spectral camera are you using? Is Parrot Sequoia, Micasense RedEdge or something else?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14104
    • View Profile
Re: Multispectral Cameras from Files as Bands
« Reply #2 on: May 08, 2018, 05:41:53 PM »
Hello johnlionas,

Like mentioned above, if you are adding images from Parrot Sequoia or MicaSense RedEdge cameras using a single list for all bands, PhotoScan would create multiplane (multispectral) layout automatically.

But if you are using some other sources, you can follow this approach (the example assumes that there are two cameras - images from which are grouped into separate lists:
Code: [Select]

rgb = ["/images/rgb/image1.jpg", "/images/rgb/image2.jpg", "/images/rgb/image2.jpg", "/images/rgb/image3.jpg"]
nir = ["/images/nir/image1.jpg", "/images/nir/image2.jpg", "/images/nir/image2.jpg", "/images/nir/image3.jpg"]

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)

So the list that should be used in addPhotos() function is actually a nested list, where each top list element represent the single camera position, and the nested list inside - represent the list of bands corresponding to this camera location.
And it is necessary to use MultiplaneLayout option.
Best regards,
Alexey Pasumansky,
Agisoft LLC

johnlionas

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Multispectral Cameras from Files as Bands
« Reply #3 on: May 09, 2018, 11:00:04 AM »
Hello

The camera can be either Parrot Sequoia or MicaSense RedEdge. The photos are from 4 different bands: Red Edge (RED), Near Infrared (NIR), RED and GRE (Green). I use regular expression to separate the images belonging in each band. The code I am running is the following:

-------------------------------------
import PhotoScan
import os
import re

photosDir = #complete folder path that contains ll images
doc = PhotoScan.app.document
chunk = doc.addChunk()
photos = os.listdir(photosDir)

regex = re.compile(".*GRE\.TIF")
grephotos = list(filter(regex.match, photos))
regex = re.compile(".*NIR\.TIF")
nirphotos = list(filter(regex.match, photos))
regex = re.compile(".*RED\.TIF")
redphotos = list(filter(regex.match, photos))
regex = re.compile(".*REG\.TIF")
regphotos = list(filter(regex.match, photos))

images = list()
for i in range(0,len(grephotos)):
    images.append([photosDir+grephotos, photosDir+nirphotos, photosDir+redphotos, photosDir+regphotos])

chunk.addPhotos(images, PhotoScan.MultiplaneLayout)
chunk.matchPhotos(PhotoScan.LowAccuracy, generic_preselection=True, reference_preselection = True, filter_mask=False, keypoint_limit=40000, tiepoint_limit=4000)
chunk.buildDenseCloud()
--------------------------------------------------------------------

The last command is not executed and I can see from the GUI that it is not available. However when I run all the processing using GUI, I can load all the photos without having to separate them in bands, select the option “Create multispectral cameras from files as bands” and run all other processing wih no problem.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14104
    • View Profile
Re: Multispectral Cameras from Files as Bands
« Reply #4 on: May 09, 2018, 11:26:44 AM »
Hello johnlionas,

If you pass the complete list of all band images (for Sequoia and RedEdge cameras) to addPhotos function - it would automatically generate multispectral camera layout.
Best regards,
Alexey Pasumansky,
Agisoft LLC

johnlionas

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Multispectral Cameras from Files as Bands
« Reply #5 on: May 10, 2018, 11:10:45 AM »
I did run the following pice of code:

---------------------------------------------------
import PhotoScan
import os

photosDir = #full folder path
doc = PhotoScan.app.document
chunk = doc.addChunk()
photos = os.listdir(photosDir)

images = list()
for i in range(0,len(photos)):
    images.append(photosDir+photos)

chunk.addPhotos(images, PhotoScan.MultiplaneLayout)
chunk.matchPhotos(PhotoScan.LowAccuracy, generic_preselection=True, reference_preselection = True, filter_mask=False, keypoint_limit=40000, tiepoint_limit=4000)
chunk.buildDenseCloud()
----------------------------------------------------

All the images are inserted in the addPhotos function using a one dimensional list. However buildDenseCloud function pops the error: "Null depth maps". When I perform the processing using GUI, it runs fine.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14104
    • View Profile
Re: Multispectral Cameras from Files as Bands
« Reply #6 on: May 10, 2018, 01:16:13 PM »
Hello johnlionas,

In the version 1.4 the dense cloud generation task has been split into two parts - depth maps generation and dense cloud generation:

Code: [Select]
chunk.buildDepthMaps(quality = PhotoScan.LowQuality, filter = PhotoScan.AggressiveFiltering)
chunk.buildDenseCloud(point_colors = True)
Best regards,
Alexey Pasumansky,
Agisoft LLC

johnlionas

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Multispectral Cameras from Files as Bands
« Reply #7 on: May 13, 2018, 08:36:59 AM »
Still another error pops up when I run the command:

chunk.buildDepthMaps(quality = PhotoScan.LowQuality, filter = PhotoScan.AggressiveFiltering)

The error message is: "Error: Empty region"

I can not find out why. As I mentioned earlier the whole process executed using the GUI runs fine.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14104
    • View Profile
Re: Multispectral Cameras from Files as Bands
« Reply #8 on: May 13, 2018, 02:01:26 PM »
Hello johnlionas,

I haven't noticed it earlier, but it appears that you have only matched images, but haven't aligned them.
You should use chunk.alignCameras() function after chunk.matchPhotos() line and before building the depth maps.
Best regards,
Alexey Pasumansky,
Agisoft LLC

qt2

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Multispectral Cameras from Files as Bands
« Reply #9 on: April 22, 2019, 10:20:16 PM »
I have the same error "Error: Empty region" at the line chunk.buildDepthMaps. Does anyone know why and how to work around it?

Here is my code:

#align photos
chunk.matchPhotos(accuracy = accuracy, preselection = preselection,
   filter_mask = False, keypoint_limit = keypoints, tiepoint_limit = tiepoints)
chunk.alignCameras()

#building dense cloud
chunk.buildDepthMaps(quality=Metashape.MediumQuality, filter=Metashape.MildFiltering)
chunk.buildDenseCloud(point_colors=True)

Thanks.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14104
    • View Profile
Re: Multispectral Cameras from Files as Bands
« Reply #10 on: April 23, 2019, 01:23:02 PM »
Hello qt2,

Does it help, if you add line chunk.reserRegion() before building the depth maps?

Also have you checked the alignment in this project visually - is it correct, are there properly aligned cameras?
Best regards,
Alexey Pasumansky,
Agisoft LLC