Introduce explicit image-format tracking through the pipeline to unify mono/bayer/color handling

Open
#402 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Quiet
Tech stack
numpy, python, testing-qa

Research direction

Start with instrument/common.py, silcam.py, process.py, and classify_torch.py to understand where image format is currently inferred from shape. Trace the loaders that should populate data['image_format'], then locate the existing tests for instrument loading and processing. Done means shared format-aware helpers replace the separate shape branches and tests cover mono8, Bayer, and synthetic 2D/UVP-like inputs end to end.

Written by the indexing model from the issue text.

Description

Supersedes/links #372 and #361, which both trace back to the same root cause.

Problem: nowhere in the pipeline is there a persistent, explicit tag for what kind of image is being processed. SilCamLoad knows the format at load time (dispatches on file extension: .silc→RGB8, .msilc→MONO8, .bsilc→BAYER_RG8, .bmp→inferred), but that information is discarded the instant load_image() returns — only the raw array and its incidental shape survive into data['imraw'].

Downstream, at least four separate places infer dimensionality from array shape instead of from an explicit type:

  • ImagePrep (silcam.py) — np.min(image, axis=2) has no dimension check, and raises an AxisError on 2D grayscale images (#361).
  • statextract (process.py) — if imc.ndim == 2: imc = np.stack([imc]*3, axis=2), with a logged warning. This duplicates the single channel three times to produce a 3-channel array, restoring the expected shape but not actual color information (#372).
  • classify_torch.py's _percentile_normalize — implements its own separate ndim/shape branch for the same case, independent of the above.
  • instrument/common.py's apply_circular_mask — also branches on len(image.shape)==3; this one works, but via the same shape-inference approach.

Holo and UVP don't currently hit this ambiguity, because their data is never variable in shape: holo always builds 3D reconstruction stacks reduced via fixed ops, and UVP vignettes are always 2D, so every UVP image already goes through statextract's 2D-handling branch as its normal path rather than as an edge case. SilCam is the only instrument that produces different shapes depending on sensor format while sharing one downstream pipeline across them.

There is currently no test coverage for mono8/bayer/2D image paths.

Proposed approach:

  1. Have each instrument's Load step set an explicit data['image_format'] tag (SilCam already knows this; holo/uvp would set a fixed value since they're always mono).
  2. Add shared, format-aware helpers to instrument/common.py (e.g. to_grayscale(image, image_format), ensure_three_channel(image, image_format)) to consolidate the separate implementations above into one tested path.
  3. Each instrument's steps use only the helpers relevant to it — e.g. SilCam's ImagePrep calls to_grayscale; statextract/the classifier call ensure_three_channel instead of two independent implementations.
  4. Add tests for .msilc, .bsilc, and synthetic 2D/UVP-like arrays end-to-end, since none exist today.

This also supports the separation Raymond raised on #372 — particle-dimension measurement and classifier-input normalization become distinct, independently testable concerns instead of one shared shape inference.

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 Computer Vision issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.