suyashkumar / dicom

⚡High Performance DICOM Medical Image Parser in Go.
MIT License
933 stars 136 forks source link

De-identify DICOM tags #237

Closed vijaysubramanya closed 3 months ago

vijaysubramanya commented 2 years ago

I'm trying to update/de-identify some of the metadata tags (such as Patient ID). Is there a way to update the file directly without reading the file and writing back to the file? Currently, I'm reading the file into a variable, updating the elements, and writing back to a new file as below:

dataset, _ := dicom.ParseFile("dicom/1.dcm", nil)
    for _, elem := range dataset.Elements {
        s := reflect.TypeOf(elem.Value.GetValue()).Kind()
        if s == reflect.Slice {
            elem.Value, _ = dicom.NewValue([]string{"abc"})
        }
    }
    f, err := os.Open("test.dcm")
    err = dicom.Write(f, dataset)
    }
vijaysubramanya commented 2 years ago

@suyashkumar @jstutters

suyashkumar commented 2 years ago

Hi there! At the moment, I'm not sure of a great way to safely update the file "in place" if that's what you want.

Something I would like to do is update the element-by-element parsing API (e.g. the Next() API on the parser) be more memory efficient by only holding onto the Dataset elements it needs for future parsing, and otherwise just transiently emitting the Elements one at a time.

suyashkumar commented 3 months ago

Closing this, as I think the question was answered re: in-place editing.