dcmjs-org / dcmjs

Javascript implementation of DICOM manipulation
https://dcmjs.netlify.com/
MIT License
287 stars 108 forks source link

fix(Segmentation): Support only one frame #395

Open jlopes90 opened 1 month ago

jlopes90 commented 1 month ago

Fix: https://github.com/cornerstonejs/cornerstone3D/issues/1059#issuecomment-2155718355

netlify[bot] commented 1 month ago

Deploy Preview for dcmjs2 ready!

Name Link
Latest commit c333cbd99ed2f1ad03010d972f58a09453a1e57e
Latest deploy log https://app.netlify.com/sites/dcmjs2/deploys/66639dd4c98f8b00081d7556
Deploy Preview https://deploy-preview-395--dcmjs2.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

pieper commented 1 month ago

Thanks for investigating this and providing the PR with a link to the cornerstone issue. While that link is helpful, please make your contribution here self-contained and describe in your commit message, and in code comments as needed, specifically, please clarify:

It would also be great to have a unit test that illustrates this. That is, a test that demonstrates a valid use-case that fails without this change but works with the change.

Also, see the guidelines for commit messages and correct your commit as indicated: https://github.com/dcmjs-org/dcmjs?tab=readme-ov-file#for-maintainers-and-contributors

I don't mean to be super-picky here, but this repo is used by a lot of people and subtle bugs can occur if we aren't careful. I want to be sure someone who sees your contribution in the future fully understands it.

jlopes90 commented 1 month ago

generateSegmentation supports two or more frames and does not support just one frame and gives an error.

When testing just one frame for example:

Cornerstone3D.Segmentation.generateSegmentation([cacheImage], labelmapData, metaData);

and shows the results of errors.

First Error

let distance1 = distanceDatasetPairs[1][0];

image image

So I created a new variable, distance1 is zero, for just one frame. But if NumberOfFrames was two or more get this distanceDatasetPairs[1][0].

// If the frame is one, it is zero
let distance1 = 0;

if (ds.NumberOfFrames > 1) {
    distance1 = distanceDatasetPairs[1][0];
}

Second Error

if (ds.NumberOfFrames === 1)
    ds.PerFrameFunctionalGroupsSequence = [
        ds.PerFrameFunctionalGroupsSequence
    ];

image image image

I removed this code and it works similar to two or more frames. But I don't know what it does, I have little knowledge of segmentation in dicom.

The result:

image

jlopes90 commented 3 weeks ago

There is another way without using this pull request or change.

How does just one frame work:

Cornerstone3D.Segmentation.generateSegmentation(
    [cacheImage, cacheImage],
    labelmapData,
    metaData
);

[cacheImage, cacheImage] both "cacheImage" are the same, just ignore it and it works only one frame.