Skip to content

Support floating-point images in opencv2matplotlib - #298

Open
Aschenbath wants to merge 1 commit into
PyImageSearch:masterfrom
Aschenbath:fix/float-image-channels-244
Open

Aschenbath wants to merge 1 commit into
PyImageSearch:masterfrom
Aschenbath:fix/float-image-channels-244

Conversation

@Aschenbath

Copy link
Copy Markdown

opencv2matplotlib() fails on float64 BGR images because cv2.cvtColor does not accept that depth. Reorder BGR/BGRA color channels with NumPy while preserving the dtype and pixel values. The result is an independent contiguous RGB array; grayscale and invalid-channel inputs continue through OpenCV's existing conversion.

Fixes #244.

Validation: python -m unittest discover -s tests -v passes all four tests, including a ten-case matrix of uint8/uint16/float16/float32/float64 and BGR/BGRA inputs, noncontiguous arrays, grayscale inputs, and unsupported channels. Five cases fail on the original implementation. Tested with Python 3.12, NumPy 2.5.5 and OpenCV 5.1.0 on Windows. git diff --check passes.

Developed with assistance from OpenAI Codex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

let opencv2matplotlib work with float images as well

1 participant