dicom

package module
v1.0.0-alpha.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2020 License: MIT Imports: 15 Imported by: 45

README

dicom

High Performance Golang DICOM Medical Image Parser

This is a (hard-ish) fork of work I did at gradienthealth which built on top of go-dicom--a golang DICOM image parsing library and command line tool. We have been working on this package with the goal of building a full-featured and high-performance dicom parser in Golang with new features and improvements. I will continue to add some (potentially API breaking) improvements on my repository fork here.

So far, improvements that have made on top of go-dicom include:

  • parsing and extracting multi-frame DICOM imagery (both encapsulated and native pixel data)
  • exposing a Parser golang interface to make mock-based testing easier for clients
  • Channel-based streaming of Frames to a client as they are parsed out of the dicom
  • Parsing performance improvements
  • General refactors to the go-dicom code (though there's more work to be done here) for maintainability an readability.

Usage

To use this in your golang project, import github.com/suyashkumar/dicom and then you can use dicom.Parser for your parsing needs:

p, err := dicom.NewParserFromFile("myfile.dcm", nil)
opts := dicom.ParseOptions{DropPixelData: true}

element := p.ParseNext(opts) // parse and return the next dicom element
// or
dataset, err := p.Parse(opts) // parse whole dicom

More details about the package can be found in the godoc

CLI Tool

A CLI tool that uses this package to parse imagery and metadata out of DICOMs is provided in the dicomutil package. All dicom tags present are printed to STDOUT by default.

Installation

You can download the prebuilt binaries from the releases tab, or use the following to download the binary at the command line using my getbin tool:

wget -qO- "https://getbin.io/suyashkumar/dicom" | tar xvz

(This attempts to infer your OS and 301 redirects wget to the latest github release asset for your system. Downloads come from GitHub releases).

Usage

dicomutil --extract-images-stream myfile.dcm

Note: for some dicoms (with native pixel data) no automatic intensity scaling is applied yet (this is coming). You can apply this in your image viewer if needed (in Preview on mac, go to Tools->Adjust Color).

Docker build

To build the tool for all platforms (Mac, Windows, Linux) from source using docker, execute the following in the cloned repo:

docker build . -t godicom
docker run -it -v $PWD/build:/go/src/github.com/suyashkumar/dicom/build godicom make release

You can then use the binaries that will show up in the build folder in your current working directory

Build manually

To build manually, ensure you have make, golang, and dep installed on your machine. Clone (or go get) this repo into your gopath then:

make

Acknowledgements

Documentation

Index

Constants

View Source
const (
	MagicWord = "DICM"
)

Variables

View Source
var (
	ErrorMagicWord              = errors.New("error, DICM magic word not found in correct location")
	ErrorMetaElementGroupLength = errors.New("MetaElementGroupLength tag not found where expected")
)
View Source
var ErrorElementNotFound = errors.New("element not found")
View Source
var ErrorOWRequiresEvenVL = errors.New("vr of OW requires even value length")
View Source
var ErrorUnsupportedVR = errors.New("unsupported VR")

Functions

func MustGetInt

func MustGetInt(v Value) int

func MustGetInts added in v1.0.0

func MustGetInts(v Value) []int

func MustGetString

func MustGetString(v Value) string

func MustGetStrings added in v1.0.0

func MustGetStrings(v Value) []string

Types

type BytesValue

type BytesValue struct {
	// contains filtered or unexported fields
}

BytesValue represents a value of []byte.

func (*BytesValue) GetValue

func (b *BytesValue) GetValue() interface{}

func (*BytesValue) String

func (b *BytesValue) String() string

func (*BytesValue) ValueType

func (b *BytesValue) ValueType() ValueType

type Dataset added in v1.0.0

type Dataset struct {
	Elements []*Element
}

func (*Dataset) FindElementByTag added in v1.0.0

func (d *Dataset) FindElementByTag(tag tag.Tag) (*Element, error)

FindElementByTag searches through the dataset and returns a pointer to the matching element. It DOES NOT search within Sequences as well.

type Element

type Element struct {
	Tag                    tag.Tag
	ValueRepresentation    tag.VRKind
	RawValueRepresentation string
	ValueLength            uint32
	Value                  Value
}

func (*Element) String

func (e *Element) String() string

type IntsValue

type IntsValue struct {
	// contains filtered or unexported fields
}

IntsValue represents a value of []int.

func (*IntsValue) GetValue

func (s *IntsValue) GetValue() interface{}

func (*IntsValue) String

func (s *IntsValue) String() string

func (*IntsValue) ValueType

func (s *IntsValue) ValueType() ValueType

type Parser

type Parser interface {
	// Parse DICOM data
	Parse() (Dataset, error)
}

func NewParser

func NewParser(in io.Reader, bytesToRead int64, frameChannel chan *frame.Frame) (Parser, error)

type PixelDataInfo

type PixelDataInfo struct {
	Frames         []frame.Frame // Frames
	IsEncapsulated bool
	Offsets        []uint32 // BasicOffsetTable
}

type PixelDataValue

type PixelDataValue struct {
	PixelDataInfo
}

PixelDataValue represents DICOM PixelData

func (*PixelDataValue) GetValue

func (e *PixelDataValue) GetValue() interface{}

func (*PixelDataValue) String

func (e *PixelDataValue) String() string

func (*PixelDataValue) ValueType

func (e *PixelDataValue) ValueType() ValueType

type RawElement

type RawElement struct {
	Tag                    tag.Tag
	ValueRepresentation    tag.VRKind
	RawValueRepresentation string
	ValueLength            uint32
	UndefinedLength        bool
	Value                  []byte
}

type SequenceItemValue added in v1.0.0

type SequenceItemValue struct {
	// contains filtered or unexported fields
}

func (*SequenceItemValue) GetValue added in v1.0.0

func (s *SequenceItemValue) GetValue() interface{}

func (*SequenceItemValue) String added in v1.0.0

func (s *SequenceItemValue) String() string

func (*SequenceItemValue) ValueType added in v1.0.0

func (s *SequenceItemValue) ValueType() ValueType

type SequencesValue

type SequencesValue struct {
	// contains filtered or unexported fields
}

SequencesValue represents a set of items in a DICOM sequence.

func (*SequencesValue) GetValue

func (s *SequencesValue) GetValue() interface{}

func (*SequencesValue) String

func (s *SequencesValue) String() string

func (*SequencesValue) ValueType

func (s *SequencesValue) ValueType() ValueType

type StringsValue

type StringsValue struct {
	// contains filtered or unexported fields
}

StringsValue represents a value of []string.

func (*StringsValue) GetValue

func (s *StringsValue) GetValue() interface{}

func (*StringsValue) String

func (s *StringsValue) String() string

func (*StringsValue) ValueType

func (s *StringsValue) ValueType() ValueType

type Value added in v1.0.0

type Value interface {
	ValueType() ValueType
	GetValue() interface{} // TODO: rename to Get to read cleaner
	String() string
	// contains filtered or unexported methods
}

type ValueType added in v1.0.0

type ValueType int
const (
	Strings ValueType = iota
	Bytes
	Ints
	PixelData
	SequenceItem
	Sequences
)

Possible ValueTypes

Directories

Path Synopsis
cmd
dicomutil command
Really basic sanity check program
Really basic sanity check program
legacy module
mocks
pkg/dicomio
Package mock_dicomio is a generated GoMock package.
Package mock_dicomio is a generated GoMock package.
pkg
tag
Package dicomtag enumerates element tags defined in the DICOM standard.
Package dicomtag enumerates element tags defined in the DICOM standard.
uid

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL