suyashkumar / dicom

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

The reason why the converted DICOM displays as blank after converting from RAW format might be attributed to the following factors: #309

Closed wangmingche closed 1 month ago

wangmingche commented 2 months ago

escription When converting a raw format file to DICOM using the provided program, the resulting output.dcm file appears as a blank/black image when viewed in a DICOM browser.

Environment Go version: 1.22.0 dicom library version: github.com/suyashkumar/dicom v1.0.7 Steps to Reproduce Prepare a raw format file. Use the provided program to convert the raw file to DICOM. View the resulting output.dcm file in a DICOM browser. Expected Behavior The converted DICOM image should display properly, showing the content of the original raw format file.

Actual Behavior The converted DICOM image appears as a blank/black image when viewed in a DICOM browser.

`

    rawFile := "./Fppic_00001615_2024y04m04d18h00m10s_SNAGA39V30E954.raw"
rawData, err := ioutil.ReadFile(rawFile)
if err != nil {
    fmt.Printf("Failed to read RAW file: %v\n", err)
    return
}
fmt.Printf("rawData:%d\n",len(rawData))

//PixelDataInfo
    pixelDataInfo := dicom.PixelDataInfo{
      IntentionallyUnprocessed: true,
      UnprocessedValueData:     rawData,
  }

// 设置 DICOM 元数据
elements := []*dicom.Element{
    dicom.MustNewElement(tag.SOPClassUID, []string{"1.2.840.10008.5.1.4.1.1.2"}),
    //GenerateUID
    dicom.MustNewElement(tag.SOPInstanceUID, []string{"1.2.840.113619.2.55.3.279721844.297.1204122294.826.1"}),
    dicom.MustNewElement(tag.PatientName, []string{"ceshiwang"}),
    dicom.MustNewElement(tag.PatientID, []string{"123456"}),
    //dicom.MustNewElement(tag.StudyInstanceUID, Uuid),
    //dicom.MustNewElement(tag.SeriesInstanceUID, Uuid),
    dicom.MustNewElement(tag.StudyID, []string{"4007"}),
    dicom.MustNewElement(tag.Modality, []string{"CR"}),
    dicom.MustNewElement(tag.Manufacturer, []string{"DATU MEDICAL"}),
    dicom.MustNewElement(tag.Rows, []int{512}),
    dicom.MustNewElement(tag.Columns, []int{512}),
    dicom.MustNewElement(tag.BitsAllocated, []int{16}),
    dicom.MustNewElement(tag.BitsStored, []int{16}),
    dicom.MustNewElement(tag.HighBit, []int{15}),
    dicom.MustNewElement(tag.PixelRepresentation, []int{0}),
    dicom.MustNewElement(tag.PixelData,pixelDataInfo),
}
dicomDataSet := dicom.Dataset{Elements: elements}

var buffer bytes.Buffer
if err := dicom.Write(&buffer, dicomDataSet,dicom.DefaultMissingTransferSyntax()); err != nil {
    fmt.Printf("Failed to write DICOM file: %v\n", err)
    return
}
// 保存 DICOM 文件
dicomFile := "output.dcm"
if err := ioutil.WriteFile(dicomFile, buffer.Bytes(), 0644); err != nil {
    fmt.Printf("Failed to save DICOM file: %v\n", err)
    return
}

fmt.Printf("DICOM file saved: %s\n", dicomFile)

`

suyashkumar commented 1 month ago

Hi there, it's because we don't have autoscaling, but you can apply scaling on your own if you'd like, more details https://github.com/suyashkumar/dicom/issues/301#issuecomment-1972489490