Forum

Author Topic: Process four band images  (Read 249 times)

MurrayW

  • Newbie
  • *
  • Posts: 10
    • View Profile
Process four band images
« on: November 30, 2018, 10:23:32 AM »
Hi everyone,

i have some four band tiffs RGBI, and I want to produce four band orthomosaic and point clouds with RGBI colours.  Is this possible in PhotoScan? 

Is the process different to the RGB process?

cheerio

MurrayW

jrp

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Process four band images
« Reply #1 on: November 30, 2018, 03:22:17 PM »
No answers from me, but I'd be really interested in the results.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 9269
    • View Profile
Re: Process four band images
« Reply #2 on: November 30, 2018, 03:49:26 PM »
Hello Murray,

Can you provide any example of the image from this dataset?

When you are adding the images to PhotoScan workspace, are you able to see all four bands switching between them via Set Primary Channel option in the Workspace context menu applied to the chunk?
Best regards,
Alexey Pasumansky,
AgiSoft LLC

aggieair

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
Re: Process four band images
« Reply #3 on: November 30, 2018, 11:57:01 PM »
We often work with TIFs that have 6 bands and also more than one camera with multiple bands.  The point cloud would only represent the first three bands I believe ??, but the ortho will have all the bands.

MurrayW

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Process four band images
« Reply #4 on: December 03, 2018, 06:51:07 AM »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 9269
    • View Profile
Re: Process four band images
« Reply #5 on: December 03, 2018, 09:33:20 PM »
Hello Murray,

Looks like you need to remove "alpha" mark from the fourth channel in order to have it interpreted as four-channel file.
Best regards,
Alexey Pasumansky,
AgiSoft LLC

MurrayW

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Process four band images
« Reply #6 on: December 04, 2018, 12:26:43 AM »
Hi Alexey,

Can you tell me how to remove alpha mark ? Actually, I am not certain that there is an alpha mark.

ArcMAP does not show an alpha channel. Band 4 can be displayed - see attached screen grabs.  Also, I exported to 4 band tiff from ArcMAP and Photoscan can now see four bands.

Band 4 comes from a different camera, with simultaneous exposure.  But, overlap is not 100%, so band 4 has zeros on two sides. Perhaps this is why Photoscan sees Alpha channel?

Maybe TIFF means: "Thousands of Incompatible File Formats" .....   :-/

« Last Edit: December 04, 2018, 02:33:07 AM by MurrayW »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 9269
    • View Profile
Re: Process four band images
« Reply #7 on: December 05, 2018, 07:48:18 PM »
Hello Murray,

I think ImageMagick or similar application should allow to remove the alpha mark from the image EXIF. If you check the EXIF tags using, for example, Exiftool utility, you'll see that the fourth "extra" sample is marked as Unassociated Alpha. And also if I open the image in QGIS and switch the representation to singleband display, the fourth band is also marked as alpha.

Here's also a sample script for PhotoScan Pro that should do the following: read images from defined folder and re-save them without alpha to another directory (also user-defined) and then add re-saved images to the new chunk in the document:
Code: [Select]
import PhotoScan
import os, glob
from PySide2 import QtWidgets

path_in = PhotoScan.app.getExistingDirectory("Specify the path for input TIFFs:")
path_out = PhotoScan.app.getExistingDirectory("Specify the path for output TIFFs:")

app = QtWidgets.QApplication.instance()
print("script started...")
app.processEvents()

image_list = [photo for photo in glob.iglob(path_in + "\\*.*", recursive = False) if (os.path.isfile(photo) and os.path.splitext(photo)[1][1:].lower() in ["tif"])]
input_photos = list()
for file in image_list:
image = PhotoScan.Image()
image = image.open(file, datatype="F16", channels = "RGB ")
export_path = path_out + "//_" + os.path.basename(file)
image.save(export_path)
input_photos.append(export_path)
print("Written image ", export_path)
app.processEvents()

chunk = PhotoScan.app.document.addChunk()
chunk.label = "Re-saved TIFFs"
chunk.addPhotos(input_photos)
doc.chunk = chunk
print("script finished")
However, it may work quite slowly, if you have hundreds of images, so you can check it on the smaller sub-set (like 10-20 images).

Best regards,
Alexey Pasumansky,
AgiSoft LLC

MurrayW

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Process four band images
« Reply #8 on: December 06, 2018, 01:14:31 AM »
Thanks Alexey

I searched for ImageMagick commands to write a tiff without the alpha band, but I did not find a solution.

I did use ImageMagick to write to .png format and in that case the alpha channel is in a separate file and can be deleted.   When reading the ImageMagick commentary on file formats, they do not recommend tiff, because of so many tags and different interpretations.

I will use png to test processing.

cheers
Murray

MurrayW

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Process four band images
« Reply #9 on: December 06, 2018, 03:54:46 AM »
Hi Alexey,

If I start project with 3 band tiff for align cameras, GCP and optimize cameras, can Photoscan then substitute four band 4 band (png or tiff) in place of 3 band tiff?

I want to use RGB for locating GCP.  The GCP are painted "X"on ground in white paint and dGPS +/- 2.5 cm. GCP is very visible on RGB, but is difficult to see on single band gray scale.

Once optimisaton/triangulation has achieved desired accuracy, I can use "Change Paths" to subsitute four band imagery. Will dense point cloud, and orthomosaic, have four bands?

cheers
Murray


MurrayW

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Process four band images
« Reply #10 on: December 06, 2018, 01:07:17 PM »
Hi again Alexey

I ran your script and it worked very well.  Processng speed was quick - much faster than ImageMagick.

Thanks.

MurrayW

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Process four band images
« Reply #11 on: December 07, 2018, 01:17:17 AM »
Hi Alexey,

I replied before checking the output images....

The output is 32 bit floating point, whereas the input was 16 bit unsigned integer. 16 bit is required.  So no success yet.

There is also an error message ! name 'doc' is not defined
« Last Edit: December 07, 2018, 01:19:28 AM by MurrayW »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 9269
    • View Profile
Re: Process four band images
« Reply #12 on: December 07, 2018, 03:30:34 PM »
Hello Murray,

I have changed the data type to U16 and corrected "doc" error in the code below (although that latter error shouldn't affect anything):
Code: [Select]
import PhotoScan
import os, glob
from PySide2 import QtWidgets

path_in = PhotoScan.app.getExistingDirectory("Specify the path for input TIFFs:")
path_out = PhotoScan.app.getExistingDirectory("Specify the path for output TIFFs:")

app = QtWidgets.QApplication.instance()
print("script started...")
app.processEvents()

image_list = [photo for photo in glob.iglob(path_in + "\\*.*", recursive = False) if (os.path.isfile(photo) and os.path.splitext(photo)[1][1:].lower() in ["tif"])]
input_photos = list()
for file in image_list:
image = PhotoScan.Image()
image = image.open(file, datatype="U16", channels = "RGB ")
export_path = path_out + "//_" + os.path.basename(file)
image.save(export_path)
input_photos.append(export_path)
print("Written image ", export_path)
app.processEvents()

chunk = PhotoScan.app.document.addChunk()
chunk.label = "Re-saved TIFFs"
chunk.addPhotos(input_photos)
PhotoScan.app.document.chunk = chunk
print("script finished")
Best regards,
Alexey Pasumansky,
AgiSoft LLC

MurrayW

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Process four band images
« Reply #13 on: Today at 03:18:45 AM »
Thanks Alexey.  That script works well.

Also, I have been learning about ImageMagick.

Here is some advice from experienced people:

"ImageMagick cannot write 4 channels to an RGB image using -combine. The fourth channel would be the alpha channel and it is added by -compose copy_opacity -composite. You can combine 4 channels as CMYK, if you want, but not RGB.

ImageMagick (6) does not write to multi-channel TIFF files right now as far as I know. It will write to multipage TIFF files by simply,

convert image1.tif image2.tif image3.tif image4.tif result.tif

See also https://imagemagick.org/script/command- ... php#define for -define tiff:alpha=associated|unassociated|unspecified for alpha specification"