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

dicom.Write fails on 'SmallestImagePixelValue' with VR of 'US' #190

Closed
bpeake-illuscio opened this issue Mar 23, 2021 · 2 comments
Closed

Comments

@bpeake-illuscio
Copy link
Contributor

Hello!

I've run into an issue when writing DICOMs which I have modified. In my source DICOM the SmallestImagePixelValue has a VR of 'US'. When I try to write it to a buffer, I get the following erro:

"ValueType does not match the specified type in the VR"

While debugging, I found an internal error with some more contex:

"ERROR dicomio.veryifyElement: VR mismatch for tag (0028,0106)[SmallestImagePixelValue]. Element.VR=US, but DICOM standard defines VR to be SS"

However, this is not correct, the DICOM spec defines the VR of 'SmallestImagePixelValue' as 'US or SS'.

Here is a basic reproduction of the issue:

package main

import (
	"bytes"
	"fmt"
	"github.com/suyashkumar/dicom"
	"github.com/suyashkumar/dicom/pkg/tag"
)

func MustNewValue(data interface{}) dicom.Value {
	value, err := dicom.NewValue(data)
	if err != nil {
		panic(fmt.Errorf("error writing value: %w", err))
	}

	return value
}

func main() {
	dataset := dicom.Dataset{
		Elements: []*dicom.Element{
			&dicom.Element{
				Tag:                    tag.SmallestImagePixelValue,
				ValueRepresentation:    tag.VRUInt16List,
				RawValueRepresentation: "US",
				ValueLength:            0,
				Value:                  MustNewValue([]int{1}),
			},
		},
	}

	buffer := new(bytes.Buffer)
	err := dicom.Write(buffer, dataset, dicom.DefaultMissingTransferSyntax())
	if err != nil {
		fmt.Println("ERROR:", err)
	}
}

I think I mentioned solving for this in #169 . For now I can disable write verification, but it would be nice to be able to turn it on.

@bpeake-illuscio bpeake-illuscio changed the title dicom.Write fails on SmallestImagePixelValue with VR of SS dicom.Write fails on SmallestImagePixelValue with VR of US Mar 23, 2021
@bpeake-illuscio bpeake-illuscio changed the title dicom.Write fails on SmallestImagePixelValue with VR of US dicom.Write fails on 'SmallestImagePixelValue' with VR of 'US' Mar 23, 2021
@CccTAu
Copy link

CccTAu commented Sep 27, 2024

hey,have you solved it?

suyashkumar added a commit that referenced this issue Sep 29, 2024
suyashkumar added a commit that referenced this issue Sep 29, 2024
@suyashkumar
Copy link
Owner

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

No branches or pull requests

3 participants