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

Converting DICOM to Image results into "blacked" image #301

Open
sjbokhari opened this issue Feb 5, 2024 · 7 comments
Open

Converting DICOM to Image results into "blacked" image #301

sjbokhari opened this issue Feb 5, 2024 · 7 comments

Comments

@sjbokhari
Copy link

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

@suyashkumar
Copy link
Owner

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!

@sjbokhari
Copy link
Author

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

@42maojin
Copy link

42maojin commented May 8, 2024

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

@42maojin
Copy link

ok,I have solved my problem myself,lol

@CccTAu
Copy link

CccTAu commented Oct 28, 2024

ok,I have solved my problem myself,lol

hi,can you tell me how to slove it. i have the same problem now

@42maojin
Copy link

ok,I have solved my problem myself,lol

hi,can you tell me how to slove it. i have the same problem now

I changed the value of the underlying image of the dicom file by changing

@CccTAu
Copy link

CccTAu commented Nov 6, 2024

Hey,Do you use window width and window center to change the pix value of image?

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

4 participants