image parsing issue
krishpranav opened this issue · comments
hey @suyashkumar I am facing a issue:
- if I run the code:
package main
import (
"fmt"
"image/jpeg"
"os"
"github.com/suyashkumar/dicom"
"github.com/suyashkumar/dicom/pkg/tag"
)
func main() {
dataset, _ := dicom.ParseFile("dicom/test.dcm", nil)
pixelDataElement, _ := dataset.FindElementByTag(tag.PixelData)
pixelDataInfo := dicom.MustGetPixelDataInfo(pixelDataElement.Value)
for i, fr := range pixelDataInfo.Frames {
img, _ := fr.GetImage()
f, _ := os.Create(fmt.Sprintf("image_%d.jpg", i))
_ = jpeg.Encode(f, img, &jpeg.Options{Quality: 200})
_ = f.Close()
}
}
it is giving an output image as jpg but it is full dark
can you help me to fix this issue
Hi @krishpranav are you getting the EOF error reported earlier, or just an apparently dark image? The image appearing black may be working as intended, because we do not apply any pixel value auto scaling yet: https://github.com/suyashkumar/dicom/blob/87c7d7e41fca7227af3582174c5933fb91981eb7/README.md?plain=1#L57
Also, regarding the images you posted, by posting them I assume you have the license to post those and that they are de-identified (they appear to be, but that is for you to determine as the poster--if not, please delete those comments).
If you're not getting the EOF error, and it is not working-as-intended due to no auto scaling being applied, please open another issue instead of this one. Thanks!
I have saw you comment after going to (in Preview on mac, go to Tools->Adjust Color). what to do any ideas??
is there any updates???
Hi @krishpranav to answer your question:
I have saw you comment after going to (in Preview on mac, go to Tools->Adjust Color). what to do any ideas??
You can move the sliders around to change the scaling of the raw pixel values in the image. The values written out to the PNG by this library should be the same raw integer values inside the dicom. It can sometimes be important to preserve these values, because they can often times map to real world units (like HU). You can also programmatically apply whatever autoscaling you wish to the integer values retrieved from the DICOM (simply access the Data slice in the NativeFrame).
If things still seem off, we can try to debug further!
(resolving as this seems to have been addressed in the above comment)