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

Open Beginner friendly
#361 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
60/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
numpy, python
Domain
backend

Research direction

Open pyopia/instrument/silcam.py and find the ImagePrep class where data['im_minimum'] is computed with np.min(image, axis=2). Add a check for 2-dimensional images so grayscale (H, W) input is passed through without the axis reduction. Reproduce with a monochrome BMP, then verify RGB processing still works with the existing pipeline tests.

Written by the indexing model from the issue text.

Description

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.......

Dominant language
Jupyter Notebook
Stars
19
Forks
7
Avg merge
10d 11h
Merged PRs (30d)
1

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SINTEF/pyopia

All issues in SINTEF/pyopia

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.