Skip to content
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

fix(segmentation): should use segment number if provided #357

Closed
wants to merge 1 commit into from

Conversation

sedghi
Copy link
Collaborator

@sedghi sedghi commented Jul 18, 2023

When exporting segmentation if segment number is specified it the copy should use that instead of deriving it from the length similar to SegmentLabel and SegmentAlgorithm which is used to copy

@@ -1,69 +1,69 @@
{
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not my fault actually, the prettier config in the repo specifies 4 tabWidth

Comment on lines +408 to +410
SegmentNumber:
Segment.SegmentNumber ||
(SegmentSequence.length + 1).toString(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is okay with the standard?

https://dicom.innolitics.com/ciods/segmentation/segmentation-image/00620002/00620004

Section C.8.20.2.4
C.8.20.2.4 Segment Number
Segment Number (0062,0004) shall be unique within each Instance, start at a value of 1, and increase monotonically by 1.

Copy link
Collaborator Author

@sedghi sedghi Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmmmm, I encountered this when I was writing the segmentation export and my code was generating a fake segmentation with two segments of 2 and 5 and I saw they get mapped into different color when I re import them (since they were getting mapped to 1 and 2) but now that you sent that link maybe you are right. So does this mean there is no way to specifically export a segmentation object that number the segments arbitrary? interesting I guess

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no way to specifically export a segmentation object that specifically number the segments arbitrary?

Correct. But why this would be an issue? Segment number is just a pointer within the segmentation object to connect semantics of the segment and the color of the segment with the corresponding pixel data.

Copy link
Collaborator Author

@sedghi sedghi Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue I encountered initially was the color lut for segments (different colors before export VS after import), I think we have a bug in OHIF too ...

Something strange I saw in SEG export was this, not sure if there is an explanation for it

My metadata for dcmjs to export SEG using this rgb2DICOMLAB

const RecommendedDisplayCIELabValue = dcmjs.data.Colors.rgb2DICOMLAB(
        color.slice(0, 3)
    );

image

But later looking at the DICOM again uing the DICOM dump here

image

As you see the encoded results are different, so my parser with dicomlab2RGB returns a different color.

Am I missing an obvious thing here? is there any scaling happening ? (but I didn't see any other scale handling code anywhere before in dcmjs nor in OHIF)

Event inside the dcmjs it has correct value but it gets rewritten

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I was involved in writing that conversion function.

But in dcmqi we did spend a bit of time debugging it, and in the end the conversion was implemented in DCMTK. Maybe this can help debug OHIF conversion routines: https://github.com/DCMTK/dcmtk/blob/master/dcmiod/libsrc/cielabutil.cc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The display values are clearly out of range - from the spec:

Attributes such as Graphic Layer Recommended Display CIELab Value (0070,0401) consist of three unsigned short values:

An L value linearly scaled to 16 bits, such that 0x0000 corresponds to an L of 0.0, and 0xFFFF corresponds to an L of 100.0.

An a* then a b* value, each linearly scaled to 16 bits and offset to an unsigned range, such that 0x0000 corresponds to an a* or b* of -128.0, 0x8080 corresponds to an a* or b* of 0.0 and 0xFFFF corresponds to an a* or b* of 127.0

So, the actual values of L* a* and b* for unencoded are:
0...100, -128...127, -128...127
or the encoded values are:
0...65535
for PCS encoding. The provided values are completely outside the range, so something is converting things incorrectly before being passed into dcmjs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok silly mistake, apparently the RGB that rgb2DICOMLAB accepts is scaled to 0-1 RGB, my bad

@sedghi sedghi closed this Jul 18, 2023
@pieper
Copy link
Collaborator

pieper commented Jul 18, 2023

The dcmjs version is the dcmtk version converted to js. I might have made a mistake in the conversion but it worked for the tests I had tried.

https://github.com/dcmjs-org/dcmjs/blob/master/src/colors.js

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.

4 participants