Skip to content

AxisError when processing BMP grayscale images with shape (H, W) #361

@arsalanmstn

Description

@arsalanmstn

Hi, I ran into an issue when processing grayscale (monochrome) BMP images of the second deployment of Spartacus in Trondheim fjord.

In ImagePrep class of the pyopia.instrument.silcam module, the "im_minimum" is computed using:
data['im_minimum'] = np.min(image, axis=2)
but this assumes that all images have a channel dimension (axis=2), which is true for RGB images with shape (H, W, 1 or 3). However, this raises the following error for grayscale images with shape (H, W):
"AxisError: axis 2 is out of bounds for array of dimension 2"

data['im_minimum'] is computed unconditionally in ImagePrep and cannot be disabled via user preferences, so processing monochrome images breaks at this step if they don't have channel dimension. The following correction can easily solve the problem:
data['im_minimum'] = image if image.ndim==2 else np.min(image, axis=2)

** Another approach is to comment out the imageprep step in the config file, but the user must set segment_source= "im_corrected" or segment_source="imraw". This can be confusing for users.......

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions