Forum

Author Topic: Python function on how to change master band in multispectral image mosaic.  (Read 4311 times)

ppant

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
In photoscan when we do multispectral mosiac by default master band is set to band 1, for example, In micasense rededge camera data defult master band will be blue. I want to change that to red-edge as it is the middle band in five cameras. This can be easily done is gui. But I am not able to figure is it possible with python script too.


Thanks
ppant

jguan

  • Newbie
  • *
  • Posts: 5
    • View Profile
Hi,

I met the same problem when I want to change the master channel with script Python.

After reading the Python API Reference, I think they change the name of the index Chunk.master_channel by Chunk.primary_channel if you use the version Photoscan 1.4.0+.

 And the index type int for default is -1 indicated in the API Reference.

But I failed to change the master channel by setting the value of Chunk.primary_channel.

Waiting for the reponse of support team Agisoft.

Thanks.

ppant

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Jguan
I also perform the same as you mention but could not choose the master band as preferred.

Thanks

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Hello,

Master Band in the multispectral camera approach has different meaning from Primary channel, so changing the primary channel wouldn't have any effect on the Master Band.

To switch the Master Band I can suggest the following solution:
Code: [Select]
chunk = PhotoScan.app.document.chunk
new_master = chunk.sensors[3]

for s in chunk.sensors:
    s.master = None
for s in chunk.sensors:
    s.master = new_master
Best regards,
Alexey Pasumansky,
Agisoft LLC

ppant

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Alexey
When I tried to change the master band via python script and run the script I am getting zero resolution error in Dense cloud point generation.
When I comment the reset master band section. Code is running fine.
He is a piece
Code: [Select]
PhotoScan.app.settings.setValue('main/depth_filtering_limit', 80)
doc = PhotoScan.app.document
chunk = doc.addChunk()
chunk.addPhotos(input_image_files_list, PhotoScan.MultiplaneLayout)
doc.save(save_psx_filename)
#new_master = chunk.sensors[3]
#for s in chunk.sensors:
#    s.master = None
#for s in chunk.sensors:
#   s.master = new_master

chunk.matchPhotos(accuracy=PhotoScan.HighAccuracy, preselection=PhotoScan.ReferencePreselection,
                          generic_preselection=True, reference_preselection=True, keypoint_limit=80000,
                          tiepoint_limit=5000)
chunk.alignCameras(adaptive_fitting=False)
        chunk.buildDepthMaps(quality=point_cloud_quality, filter=PhotoScan.AggressiveFiltering, reuse_depth=True)
        chunk.buildDenseCloud(point_colors=True, max_neighbors=71)


ppant

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
I got this error window

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Hello ppant,

Is the behavior the same, if you move line doc.save(save_psx_filename) before creating the new chunk?
Best regards,
Alexey Pasumansky,
Agisoft LLC

ppant

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Alexey
I am able to move forward on dense cloud point (zero resolution) by defining the primary channel after master band rest as you defined after new_mater
but ran into another issue when building the orthomosaic I am getting empty camera list error.
It is not affecting the re
 
Code: [Select]
chunk = doc.addChunk()
chunk.addPhotos(input_image_files_list, PhotoScan.MultiplaneLayout)
doc.save(save_psx_filename)
new_master = chunk.sensors[3]
for s in chunk.sensors:
    s.master = None
for s in chunk.sensors:
   s.master = new_master

chunk.primary_channel = 3

chunk.matchPhotos(accuracy=PhotoScan.HighAccuracy, preselection=PhotoScan.ReferencePreselection,
                          generic_preselection=True, reference_preselection=True, keypoint_limit=80000,
                          tiepoint_limit=5000)
chunk.alignCameras(adaptive_fitting=False)
chunk.buildDepthMaps(quality=point_cloud_quality, filter=PhotoScan.AggressiveFiltering, reuse_depth=True)
chunk.buildDenseCloud(point_colors=True, max_neighbors=71)

doc.save()
chunk.buildDem(source=PhotoScan.DenseCloudData, interpolation=PhotoScan.EnabledInterpolation)
doc.save()
chunk.buildOrthomosaic(surface=PhotoScan.ElevationData, blending=PhotoScan.MosaicBlending)
doc.save()


ppant

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Furthermore to previous not building orthomosaic. When I run a script from GUI it works. but when run a script via command line it fails to set the camera.

selected 0 cameras
chunk.buildOrthomosaic(surface=PhotoScan.ElevationData, blending=PhotoScan.MosaicBlending)
RuntimeError: Empty camera list

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Hello ppant,

I'm currently not being able to reproduce the issue. But still assume that the reason of the problem on your side is doc.save() operation.

When you are using path argument for it - then it works like the Save As operation, so the project is saved and re-opened. It means that the chunk variable is no longer associated to the new (automatically re-assigned) document. That's why I suggest to use doc.save(save_psx_filename) line before creating a new chunk (then just use doc.save() without any arguments).

Can you please check that?
Best regards,
Alexey Pasumansky,
Agisoft LLC

ppant

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Alexey
I did that also doc.save (save_psx_filename) . But it fails with empty camera list for missense red-edge sensor when creating orthomosaic.

Code: [Select]
new_master = chunk.sensors[3]
for s in chunk.sensors:
     s.master = None
for s in chunk.sensors:
      s.master = new_master
chunk.primary_channel = 3

Thanks

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Hello ppant,

I think that the following code should fix the problem.

Code: [Select]
new_master = chunk.sensors[3]
for s in chunk.sensors:
     s.master = None
     s.fixed_rotation = False
for s in chunk.sensors:
      s.master = new_master
new_master.fixed_rotation = True

It was related to preserved "fit rotation" setting for all bands, despite the master band has been changed. So the images from the new master where not aligned  and lead to "empty camera list" error.
Best regards,
Alexey Pasumansky,
Agisoft LLC

ppant

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Alexey
This update works
Code: [Select]
new_master.fixed_rotation = Truefor Micasense rededge but it fails for Sequoia parrot saying zero resolution error in Dense cloud point generation.

Thanks

ppant

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Still getting empty list error with this change too.

Thanks

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Hello ppant,

I've checked the lines on RedEdge and Sequoia projects and it worked properly (including the orthomosaic generation).

Can you provide the log and report from the Sequoia project? Also please check in the Camera Calibration dialog if for all slave bands have "fit rotation" flag set and master band doesn't.

Zero resolution usually means that there are not sufficient tie points inside the bounding box to estimate the overlapping image pairs.
Best regards,
Alexey Pasumansky,
Agisoft LLC