Giter Club home page Giter Club logo

Comments (2)

itp-atakan avatar itp-atakan commented on May 24, 2024

You are getting this error because the dicom file which you are trying to parse has no preamble (128 bytes zeros) and magic bytes ('D', 'I', 'C', 'M'). If you'd like to have detailed information about the dicom format and file structure please have a look at (https://dicom.nema.org/dicom/2013/output/chtml/part10/chapter_7.html).

Regarding the problem, you can try to insert the preamble and magic at the beginning of your file and then parse it.
You can apply the following snippet, but it's important to note that this is not the best solution. You may need to consider better solution in different cases.

package main

import (
	"bytes"
	"fmt"
	"log"
	"os"

	"github.com/suyashkumar/dicom"
)

func main() {
	dcmMagic := make([]byte, 128)
	dcmMagic = append(dcmMagic, []byte{'D', 'I', 'C', 'M'}...)
	buf, _ := os.ReadFile("test-dicom.dcm")
	rd := bytes.NewReader(append(dcmMagic, buf...))
	ds, err := dicom.Parse(rd, rd.Size(), nil)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(ds)
}

from dicom.

suyashkumar avatar suyashkumar commented on May 24, 2024

Thanks for helping out the community @itp-atakan! Sounds like maybe this isn't an issue? Note that we have a compatability mode that tries to read the dataset without the magic word:

dicom/read.go

Line 149 in 9612756

// parse a Dataset (and do not parse metadata in the usual way).

from dicom.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.