Error processing stacked tiff output from MicaSense imageprocessing

Running WebODM on Windows 10 with Docker, using Microsoft Edge and Firefox.

Continuing the discussion about processing MicaSense imagery here and here. Especially pierotofy’s comment.

Attempted workflow:
Raw imagery > MicaSense imageprocessing > band stack tif > WebODM > orthomosaic

Output test images from MicaSense imageprocessing are here.

Using the Default processing mode yields the error:

[INFO]    Initializing ODM - Wed Mar 31 18:04:05  2021
[INFO]    ==============
[INFO]    build_overviews: False
[INFO]    camera_lens: auto
[INFO]    cameras: {}
[INFO]    crop: 3
[INFO]    debug: False
[INFO]    dem_decimation: 1
[INFO]    dem_euclidean_map: False
[INFO]    dem_gapfill_steps: 3
[INFO]    dem_resolution: 5
[INFO]    depthmap_resolution: 640
[INFO]    dsm: True
[INFO]    dtm: False
[INFO]    end_with: odm_report
[INFO]    fast_orthophoto: False
[INFO]    feature_quality: high
[INFO]    feature_type: sift
[INFO]    force_gps: False
[INFO]    gcp: None
[INFO]    geo: None
[INFO]    gps_accuracy: 10
[INFO]    ignore_gsd: False
[INFO]    matcher_distance: 0
[INFO]    matcher_neighbors: 8
[INFO]    matcher_type: flann
[INFO]    max_concurrency: 32
[INFO]    merge: all
[INFO]    mesh_octree_depth: 11
[INFO]    mesh_size: 200000
[INFO]    min_num_features: 8000
[INFO]    name: 5d2eac27-1d89-43b9-9f08-ca38cbc1dde6
[INFO]    optimize_disk_space: False
[INFO]    orthophoto_compression: DEFLATE
[INFO]    orthophoto_cutline: False
[INFO]    orthophoto_no_tiled: False
[INFO]    orthophoto_png: False
[INFO]    orthophoto_resolution: 5
[INFO]    pc_classify: False
[INFO]    pc_csv: False
[INFO]    pc_ept: False
[INFO]    pc_filter: 2.5
[INFO]    pc_las: False
[INFO]    pc_quality: medium
[INFO]    pc_rectify: False
[INFO]    pc_sample: 0
[INFO]    pc_tile: False
[INFO]    primary_band: auto
[INFO]    project_path: /var/www/data
[INFO]    radiometric_calibration: none
[INFO]    rerun: None
[INFO]    rerun_all: False
[INFO]    rerun_from: None
[INFO]    resize_to: 2048
[INFO]    skip_3dmodel: False
[INFO]    skip_band_alignment: False
[INFO]    skip_report: False
[INFO]    sm_cluster: None
[INFO]    smrf_scalar: 1.25
[INFO]    smrf_slope: 0.15
[INFO]    smrf_threshold: 0.5
[INFO]    smrf_window: 18.0
[INFO]    split: 999999
[INFO]    split_image_groups: None
[INFO]    split_overlap: 150
[INFO]    texturing_data_term: gmi
[INFO]    texturing_outlier_removal_type: gauss_clamping
[INFO]    texturing_skip_global_seam_leveling: False
[INFO]    texturing_skip_local_seam_leveling: False
[INFO]    texturing_tone_mapping: none
[INFO]    tiles: False
[INFO]    time: False
[INFO]    use_3dmesh: False
[INFO]    use_exif: False
[INFO]    use_fixed_camera_params: False
[INFO]    use_hybrid_bundle_adjustment: False
[INFO]    verbose: False
[INFO]    ==============
[INFO]    Running dataset stage
[INFO]    Loading dataset from: /var/www/data/5d2eac27-1d89-43b9-9f08-ca38cbc1dde6/images
[INFO]    Loading 123 images
[WARNING] Cannot read /var/www/data/5d2eac27-1d89-43b9-9f08-ca38cbc1dde6/images/PH4Rh4OMhUC0J8to3r0J.tif with PIL, fallback to cv2: cannot identify image file '/var/www/data/5d2eac27-1d89-43b9-9f08-ca38cbc1dde6/images/PH4Rh4OMhUC0J8to3r0J.tif'
imread_('/var/www/data/5d2eac27-1d89-43b9-9f08-ca38cbc1dde6/images/PH4Rh4OMhUC0J8to3r0J.tif'): can't read header: OpenCV(4.5.0) /code/SuperBuild/src/opencv/modules/imgcodecs/src/grfmt_tiff.cpp:148: error: (-215:Assertion failed) channels <= 4 in function 'normalizeChannelsNumber'
Traceback (most recent call last):
File "/code/opendm/get_image_size.py", line 13, in get_image_size
with Image.open(file_path) as img:
File "/usr/local/lib/python3.8/dist-packages/PIL/Image.py", line 2943, in open
raise UnidentifiedImageError(
PIL.UnidentifiedImageError: cannot identify image file '/var/www/data/5d2eac27-1d89-43b9-9f08-ca38cbc1dde6/images/PH4Rh4OMhUC0J8to3r0J.tif'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/code/run.py", line 68, in <module>
app.execute()
File "/code/stages/odm_app.py", line 81, in execute
self.first_stage.run()
File "/code/opendm/types.py", line 319, in run
self.process(self.args, outputs)
File "/code/stages/dataset.py", line 109, in process
p = types.ODM_Photo(f)
File "/code/opendm/photo.py", line 80, in __init__
self.parse_exif_values(path_file)
File "/code/opendm/photo.py", line 260, in parse_exif_values
self.width, self.height = get_image_size.get_image_size(_path_file)
File "/code/opendm/get_image_size.py", line 19, in get_image_size
width = img.shape[1]
AttributeError: 'NoneType' object has no attribute 'shape'

It looks like ODM is having a difficult time opening the band stack tifs output from MicaSense imageprocessing. The same occurs when I skip-band-alignment.

Here’s some relevant MicaSense code where the tifs are written (with GDAL):

driver = GetDriverByName('GTiff')

out_raster = driver.Create(outfile_name, cols, rows, bands, GDT_UInt16,
                                   options=['INTERLEAVE=BAND', 'COMPRESS=DEFLATE', f'PHOTOMETRIC={photometric}'])

Any guesses?

1 Like

Hmm, it looks like one of the libraries we use isn’t properly handling the multi-band TIFFs when they’re more than 4 bands.

Your dataset is 5 bands.

EDIT:
Don’t think it is PIL, looks like that can handle N-number of bands properly (as it should be able to):
https://pillow.readthedocs.io/en/stable/handbook/concepts.html?highlight=band#concepts

As a place holder, here are some links with similar issues.

(Still open since 2016!)

Here’s a snippet using PIL, cv2, rasterio, and GDAL. rasterio and GDAL succeed. Not really sure what’s going on here because this is a common use case.

# PIL Fail
im = Image.open(img_one)
im.load()

# OpenCV Fail
im = cv2.imread(img_one)

# rasterio Success
with rasterio.open(img_one) as f:
    print(f.count)

# GDAL Success
im = gdal.Open(img_one).ReadAsArray()
print(im)

Still looking into this…

Edit: Based on the open issue above, it’s looking like PIL cannot handle images with more bands than 4 (RGBA), even though it can handle a diverse range of bit-depths.

1 Like

Looks like regardless of the initial issue, ODM does not currently support multi band 16bit TIFFs.

As far as I can tell, currently MicaSense’ imageprocessing library cannot be used to preprocess the imagery.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.