suyashkumar/dicom

Converting DICOM to Image results into "blacked" image

Opened this issue · 4 comments

Hey all,

so I am new to this amazing library and using it in my research to analyze MRT pictures automatically.

I tried the following code which was also given at godoc

dataset, _ := dicom.ParseFile(dataPath, nil)
pixelDataElement, _ := dataset.FindElementByTag(tag.PixelData)
pixelDataInfo := dicom.MustGetPixelDataInfo(pixelDataElement.Value)
for i, fr := range pixelDataInfo.Frames {
	img, _ := fr.GetImage() // The Go image.Image for this frame
	f, _ := os.Create(fmt.Sprintf("upload_convert/image_%d.jpg", i))
	_ = jpeg.Encode(f, img, &jpeg.Options{Quality: 100})
	_ = f.Close()
}

where dataPath is the path showing to the DICOM file. I tried from the test file folder testdata/4.dcm and it resulted into a completely black image.

Is this behavior normal? Did I used it wrongly?

Please let me know. Thank you very much

System: MacOS 14.2.1 (23C71)
Go Version: 1.21.1
IDE: IntelliJ IDEA 2023.3.3

This is normal for now, because we do not apply any automatic intensity scaling yet (see README) see #2. If you go into an editor or programmatically adjust the window width and center you'll most likely see the data is indeed there. For now we write out the exact Pixel values in the dicom without scaling for safety. Since you're on a mac, in Preview you can go to Tools->Adjust Color and see if the data is there.

I will look back into automatic intensity scaling soon!

Hey I created a PR for having the scaling as well :) #304

Hey I created a PR for having the scaling as well :) #304

hi, i use your code,but is not work ,The image is white,can you help me? thanks

ok,I have solved my problem myself,lol