-
Notifications
You must be signed in to change notification settings - Fork 37
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
_check_and_cast_pixel_array issue with non-contiguous numbering of segments #316
Comments
Hi @kavmar thanks for the question. This is deliberate. The definition of Segment Number in the DICOM standard states that
So this check enforces the standard. Arguably it is unfortunate that it has this limitation since other tools frequently do not, as you say. But that's how it is. So basically you have two choices:
Generally I would not rely on segment number to communicate the meaning of the segment when encoding things in DICOM, as this is very application specific. Better to rely on the standard terminologies used within the segmented property category and type and map to and from application-specific segment numbers when reading and writing the files, this will be much better for interoperability. Hope this helps |
P.s. I just remembered that the newly defined labelmap segmentations do not have this constraint! The next release of highdicom will include our implementation of this,and I'm hoping to get it out over the next couple of weeks. So you could just wait for that (it will also be a much more efficient representation of your mask but will not be widely supported by other tools yet) |
@kavmar I am a bit confused. Are you not hitting this error first: highdicom/src/highdicom/seg/sop.py Line 2395 in 2624b63
Maybe I have misunderstood the issue here... |
Hi Chris, in order for me to progress in my prototyping, I simply commented out the lines 2729 - 2733 and all worked fine. But indeed 2395 was not a blocker for me. Thanks for clarification from your earlier comments. Martin |
Well that is certainly concerning. If you tried to create a segmentation with non-consecutive segment numbers, it should have been caught by the test in line 2395 and this should have given you a more intuitive error message. I can't seem to recreate this problem (I always hit the check). If you are able to provide any details about how it came to be that you got past that check, I would certainly appreciate it. |
Happy to provide you more details. , but they do not look whether the respective numpy array with masks also fulfills the same requirement. So your code I assume should be on a safe side. I suppose we can close this issue |
Ah ok. Well I contributed that operator :) so I suppose I should probably go an fix it there... Feel free to tag me in any issue if you open one there |
Thanks a lot for looking into this. I created a Discussion in monai-deploy-app-sdk and tagged you: And similarly to this issue, which if, I am not mistaken, should need just two lines to fix :) : |
Hi,
I am using highdicom-0.23.1 (python-3.12) to create a DICOM SEG from a 3D numpy array where pixel values of individual labels are not contiguous, e.g. 0, 1, 10, 234, 556. This is not uncommon, e.g. FreeSurfer. Now the sop.py
highdicom/src/highdicom/seg/sop.py
Line 2729 in 2624b63
is complaining that there are missing SegmenetDescriptions, because number of classes is smaller than max value of the array 556 > 5
Wouldn't this be more accurate using len(np.unique(pixel_array))?
Thanks
The text was updated successfully, but these errors were encountered: