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

Default to None if voilut is not present #536

Merged
merged 2 commits into from
Jul 28, 2024
Merged

Conversation

dougyau
Copy link
Contributor

@dougyau dougyau commented Jul 9, 2024

This is a similar fix as applied on #514

@Enet4 Enet4 added A-lib Area: library C-pixeldata Crate: dicom-pixeldata labels Jul 10, 2024
@Enet4 Enet4 self-requested a review July 10, 2024 08:13
Copy link
Owner

@Enet4 Enet4 left a comment

Choose a reason for hiding this comment

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

Thank you for looking into this. Can you provide a sample file that tripped this line? voi_lut_function should not error when the attribute is missing entirely, but rather when it has an invalid value. I suspect that this was caused by VOI LUT Function being present in the data set, but with an empty value.

At this time I would rather seek to increase the resilience of voi_lut_function against empty values (treating them as they were not present at all) than change places where the function is called.

Here is a test function that you can add to attribute::tests:

    #[test]
    fn get_voi_lut_function() {
        use super::voi_lut_function;

        let mut obj = FileDicomObject::new_empty_with_meta(
            FileMetaTableBuilder::new()
                .transfer_syntax(uids::EXPLICIT_VR_LITTLE_ENDIAN)
                .media_storage_sop_class_uid(uids::ENHANCED_MR_IMAGE_STORAGE)
                .media_storage_sop_instance_uid("2.25.145929179730251416957282651365760465911")
                .build()
                .unwrap(),
        );

        // Returns None if not present
        assert_eq!(voi_lut_function(&obj).unwrap(), None);

        obj.put(DataElement::new(
            tags::VOILUT_FUNCTION,
            VR::CS,
            PrimitiveValue::Empty,
        ));
        // Returns None if empty
        assert_eq!(voi_lut_function(&obj).unwrap(), None);

        obj.put(DataElement::new(tags::VOILUT_FUNCTION, VR::CS, "LINEAR"));

        // Returns the value
        assert_eq!(
            voi_lut_function(&obj).unwrap(),
            Some(vec!["LINEAR".to_string()])
        );

        obj.remove_element(tags::VOILUT_FUNCTION);

        // per-frame functional groups
        obj.put(DataElement::new(
            tags::PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE,
            VR::SQ,
            DataSetSequence::from(vec![InMemDicomObject::from_element_iter([
                DataElement::new(tags::VOILUT_FUNCTION, VR::CS, "LINEAR_EXACT"),
            ])]),
        ));

        assert_eq!(
            voi_lut_function(&obj).unwrap(),
            Some(vec!["LINEAR_EXACT".to_string()])
        );
    }

@dougyau
Copy link
Contributor Author

dougyau commented Jul 18, 2024

According to the standard it says the VOI LUT function is optional, and when not present it should default to LINEAR (well, actually the window center and window width should be calculated as LINEAR).

What do think of how I updated the PR. It should default to LINEAR in case the tag is not present.

@Enet4
Copy link
Owner

Enet4 commented Jul 21, 2024

What do think of how I updated the PR. It should default to LINEAR in case the tag is not present.

Yeah, we could go in that direction for this function here. In that case we never return Ok(None), so this function could return a Result<Vec<String>> instead of a Result<Option<Vec<String>>>. This is safe to do now because the function is not part of the public API.

Copy link
Owner

@Enet4 Enet4 left a comment

Choose a reason for hiding this comment

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

I will approve this and defer optimizations to other pull requests. Thanks again! 👍

@Enet4 Enet4 merged commit 45c9ccd into Enet4:master Jul 28, 2024
4 checks passed
@dougyau dougyau deleted the voilut branch September 16, 2024 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lib Area: library C-pixeldata Crate: dicom-pixeldata
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants