-
Notifications
You must be signed in to change notification settings - Fork 64
Fix code and improve unit tests to prevent fail-over to the default decoders when nvimgcodec is tested #573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,19 +1,126 @@ | ||||||
| import logging | ||||||
| import time | ||||||
| from pathlib import Path | ||||||
| from typing import Any | ||||||
| from typing import TYPE_CHECKING, Any, Iterator, cast | ||||||
|
|
||||||
| import numpy as np | ||||||
| import pytest | ||||||
| from pydicom import dcmread | ||||||
| from pydicom.data import get_testdata_files | ||||||
|
|
||||||
| from monai.deploy.operators.decoder_nvimgcodec import ( | ||||||
| SUPPORTED_DECODER_CLASSES, | ||||||
| SUPPORTED_TRANSFER_SYNTAXES, | ||||||
| _is_nvimgcodec_available, | ||||||
| register_as_decoder_plugin, | ||||||
| unregister_as_decoder_plugin, | ||||||
| ) | ||||||
|
|
||||||
| try: | ||||||
| from PIL import Image as PILImage | ||||||
| except Exception: # pragma: no cover - Pillow may be unavailable in some environments | ||||||
| PILImage = None # type: ignore[assignment] | ||||||
|
|
||||||
| if TYPE_CHECKING: | ||||||
| from PIL.Image import Image as PILImageType | ||||||
|
||||||
| from PIL.Image import Image as PILImageType | |
| pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
frame.ndim == 3 will always be false, right? Because arr.ndim is 3, you select a channel with arr[index], so you remove one dimension. So you can just set is_color to False.
One sanity check: can there be a multi channel image in pydicom with more that 4 channels? Because here you assumes that only if num channels is 3 or 4, then this is color image, and otherwise the first channel is the for frame indexing, and then there is width and height. But it could be as well width, height and many channels. Or such mutlichannel images are not allowed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to my comment above, frame.ndim == 3 will always be true, right? Due to how you extract frame. So you can just leave part with frame.shape check
Check failure on line 62 in tests/unit/test_decoder_nvimgcodec.py
SonarQubeCloud / SonarCloud Code Analysis
Refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed.
See more on https://sonarcloud.io/project/issues?id=Project-MONAI_monai-deploy-app-sdk&issues=AZsA3nU-G7NRopOVvMnZ&open=AZsA3nU-G7NRopOVvMnZ&pullRequest=573
Copilot
AI
Dec 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the grayscale path, arr_min and arr_max are computed twice from different arrays (lines 77-78 from arr, then lines 87-88 from arr_float). The first computation (lines 77-78) is used only for the integer dtype checks (lines 81-84) but is then discarded. This is inefficient and potentially confusing. Consider removing the first computation or restructuring the logic to avoid redundant calculations.
| arr_min = float(arr_float.min()) | |
| arr_max = float(arr_float.max()) |
Uh oh!
There was an error while loading. Please reload this page.