godicom

package module
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 23 Imported by: 0

README

godicom

godicom is a Go package for working with DICOM files. It lets you read, modify and write DICOM datasets with an idiomatic Go API.

godicom is a general-purpose DICOM framework concerned with reading and writing DICOM datasets, pixel data, and the DICOM JSON Model. It does not handle DICOM networking. For DIMSE and DICOMweb (WADO-RS / QIDO-RS / STOW-RS), use gonetdicom, which builds on godicom.

CI Coverage Go Version GoDoc

Installation

go get github.com/godicom-dev/godicom@latest

Clone with the optional reference submodule (test fixtures):

git clone --recurse-submodules https://github.com/godicom-dev/godicom.git

Quick start

package main

import (
	"fmt"
	"log"

	"github.com/godicom-dev/godicom"
	"github.com/godicom-dev/godicom/tag"
	"github.com/godicom-dev/godicom/uid"
)

func main() {
	ds, err := godicom.ReadFile("ct.dcm", nil)
	if err != nil {
		log.Fatal(err)
	}

	name, _ := ds.GetString(tag.PatientName)
	id, _ := ds.GetString(tag.PatientID)
	fmt.Println(name, id)

	ds.Set(godicom.NewDataElement(tag.PatientID, godicom.VRLO, "12345678"))
	ds.Set(godicom.NewDataElement(tag.SOPInstanceUID, godicom.VRUI, string(uid.MustGenerateUID())))
	if err := ds.SaveAs("ct_updated.dcm", nil); err != nil {
		log.Fatal(err)
	}
}

File I/O: ReadFile / Read / ReadBytes / WriteFile / FileDataset.SaveAs.

Read accepts any io.Reader. Prefer *os.File / seekable sources — the parser walks tags without ReadAll, so StopBeforePixels, DeferSize, and SpecificTags can skip large values without buffering them. Deferred values reload by reopening the file path.

Elements are accessed with typed getters and constants from the tag package (GetString, GetInt, GetFloat, GetBytes, GetSequence, …), not dynamic attribute names.

Pixel Data

Compressed and uncompressed Pixel Data can be read as raw bytes or decoded frames:

import "github.com/godicom-dev/godicom/pixels"

ds, err := godicom.ReadFile("mr_j2k.dcm", nil)
if err != nil {
	log.Fatal(err)
}

// All frames concatenated (native layout)
raw, err := ds.PixelBytes(pixels.WithRaw(true))

// Or one frame at a time
frames, err := ds.PixelFrames(pixels.WithRaw(true), pixels.WithFrameIndex(0))

With WithRaw(false) (the default), decoded frames are normalized for display (for example YBR→RGB and planar configuration). Modality / VOI LUT helpers are available separately and are not applied automatically by PixelBytes:

samples, err := ds.PixelSamples(pixels.WithRaw(true))
hu, err := ds.ApplyModalityLUT(samples)
win, err := ds.ApplyVOILUT(hu, 0, true)
Decompressing Pixel Data
Format Package
JPEG / JPEG-LS golibjpeg
JPEG 2000 / HTJ2K goopenjpeg
RLE Lossless gorle

These are pulled in automatically as module dependencies. Native (uncompressed) and Deflated transfer syntaxes need no extra plugins.

Compressing Pixel Data
import "github.com/godicom-dev/godicom/uid"

err := ds.CompressPixelData(string(uid.RLELossless))
err = ds.CompressPixelData(string(uid.JPEG2000Lossless))
err = ds.CompressPixelData(string(uid.JPEG2000)) // lossy JPEG 2000

Supported encode paths today: native, RLE Lossless, Deflated, and JPEG 2000 (lossless / lossy). JPEG and JPEG-LS encode are not available yet (upstream decoders only).

Dataset bytes (no File Meta)

Encode or decode a dataset without a Part 10 preamble — useful for DIMSE or multipart payloads:

data, err := ds.Encode(string(uid.ExplicitVRLittleEndian))
parsed, err := godicom.DecodeDataset(data)

Part 10 files in memory:

bytes, err := ds.EncodeFile(nil)
ds2, err := godicom.ReadBytes(bytes)

DICOM JSON Model

import "github.com/godicom-dev/godicom/dicomjson"

jsonData, err := dicomjson.MarshalDataset(ds.Dataset)
parsed, err := dicomjson.ParseDataset(jsonData)

arr, err := dicomjson.MarshalDatasets([]*godicom.Dataset{ds1, ds2})
dss, err := dicomjson.ParseDatasets(arr)

CLI

go install github.com/godicom-dev/godicom/cmd/godicom@latest

godicom show <file>            # print file meta + dataset
godicom read <file>            # alias for show
godicom readcopy <src> <dst>   # read, write, re-read

Transfer syntax support

Transfer Syntax Read Write
Explicit / Implicit VR Little Endian
Explicit VR Big Endian
Deflated Explicit VR Little Endian
RLE Lossless
JPEG Baseline / Extended / Lossless
JPEG-LS
JPEG 2000 / HTJ2K ✅ (JPEG 2000)

Documentation

License

MIT — see LICENSE.

Documentation

Overview

Package godicom provides DICOM file reading, writing, and data manipulation.

Usage:

ds, err := godicom.ReadFile("file.dcm", nil)
if err != nil { ... }

// 带选项:godicom.ReadFile("file.dcm", &godicom.ReadOptions{Force: true})
fmt.Println(ds)

ds.Set(godicom.NewElement(godicom.MustTag(0x00100010), godicom.VRPN, "Test^Patient"))
ds.SaveAs("output.dcm", nil)

Index

Constants

View Source
const (
	// DefaultElementFormat matches pydicom Dataset.default_element_format.
	DefaultElementFormat = "%(tag)s %(name)-35.35s %(VR)s: %(repval)s"
	// DefaultSequenceElementFormat matches pydicom Dataset.default_sequence_element_format.
	DefaultSequenceElementFormat = "%(tag)s %(name)-35.35s %(VR)s: %(repval)s"
)

Variables

View Source
var (
	BytesVR          = map[VR]bool{VROB: true, VROD: true, VROF: true, VROL: true, VROV: true, VROW: true, VRUN: true}
	FloatVR          = map[VR]bool{VRDS: true, VRFD: true, VRFL: true}
	IntVR            = map[VR]bool{VRAT: true, VRIS: true, VRSL: true, VRSS: true, VRSV: true, VRUL: true, VRUS: true, VRUV: true}
	ListVR           = map[VR]bool{VRSQ: true}
	DefaultCharsetVR = map[VR]bool{VRAE: true, VRAS: true, VRCS: true, VRDA: true, VRDS: true, VRDT: true, VRIS: true, VRTM: true, VRUI: true, VRUR: true}
	CustomCharsetVR  = map[VR]bool{VRLO: true, VRLT: true, VRPN: true, VRSH: true, VRST: true, VRUC: true, VRUT: true}
	StrVR            = func() map[VR]bool {
		m := make(map[VR]bool)
		for k, v := range DefaultCharsetVR {
			m[k] = v
		}
		for k, v := range CustomCharsetVR {
			m[k] = v
		}
		return m
	}()
	AllowBackslash = func() map[VR]bool {
		m := make(map[VR]bool)
		for k, v := range BytesVR {
			m[k] = v
		}
		m[VRLT] = true
		m[VRST] = true
		m[VRUT] = true
		return m
	}()
)

VR classification sets

View Source
var AmbiguousVRs = map[VR]bool{
	VRUsSS: true, VRObOw: true, VRUsOw: true, VRUsSsOw: true,
}

AmbiguousVRs are VRs that require context to resolve before explicit writing.

View Source
var BufferableVRs = func() map[VR]bool {
	m := make(map[VR]bool)
	for vr := range BytesVR {
		if vr != VRUN {
			m[vr] = true
		}
	}
	return m
}()

BufferableVRs are VRs that support buffered values.

View Source
var DefaultCharacterSet = "ISO_IR 6"
View Source
var DicomDictionaryGo = map[Tag]DictEntry{}/* 5189 elements not displayed */

ExplicitVRLength16 lists VRs that use 2-byte length fields for Explicit VR (Table 7.1-2, Part 5).

View Source
var ExplicitVRLength32 = func() map[VR]bool {
	m := make(map[VR]bool)
	for vr := range StandardVRs {
		if !ExplicitVRLength16[vr] {
			m[vr] = true
		}
	}
	return m
}()

ExplicitVRLength32 lists VRs that use 4-byte length fields for Explicit VR.

View Source
var KnownUIDs = uid.Known

KnownUIDs maps UID strings to their info.

View Source
var PrivateDictionaries = map[string]map[string]PrivateDictEntry{}/* 449 elements not displayed */

PrivateDictionaries maps private creator names to tag pattern entries.

View Source
var RepeatersDictionaryGo = map[string]DictEntry{
	"002031xx": {VR: "CS", VM: "1-n", Name: "Source Image IDs", Retired: true, Keyword: "SourceImageIDs"},
	"002804x0": {VR: "US", VM: "1", Name: "Rows For Nth Order Coefficients", Retired: true, Keyword: "RowsForNthOrderCoefficients"},
	"002804x1": {VR: "US", VM: "1", Name: "Columns For Nth Order Coefficients", Retired: true, Keyword: "ColumnsForNthOrderCoefficients"},
	"002804x2": {VR: "LO", VM: "1-n", Name: "Coefficient Coding", Retired: true, Keyword: "CoefficientCoding"},
	"002804x3": {VR: "AT", VM: "1-n", Name: "Coefficient Coding Pointers", Retired: true, Keyword: "CoefficientCodingPointers"},
	"002808x0": {VR: "CS", VM: "1-n", Name: "Code Label", Retired: true, Keyword: "CodeLabel"},
	"002808x2": {VR: "US", VM: "1", Name: "Number of Tables", Retired: true, Keyword: "NumberOfTables"},
	"002808x3": {VR: "AT", VM: "1-n", Name: "Code Table Location", Retired: true, Keyword: "CodeTableLocation"},
	"002808x4": {VR: "US", VM: "1", Name: "Bits For Code Word", Retired: true, Keyword: "BitsForCodeWord"},
	"002808x8": {VR: "AT", VM: "1-n", Name: "Image Data Location", Retired: true, Keyword: "ImageDataLocation"},
	"1000xxx0": {VR: "US", VM: "3", Name: "Escape Triplet", Retired: true, Keyword: "EscapeTriplet"},
	"1000xxx1": {VR: "US", VM: "3", Name: "Run Length Triplet", Retired: true, Keyword: "RunLengthTriplet"},
	"1000xxx2": {VR: "US", VM: "1", Name: "Huffman Table Size", Retired: true, Keyword: "HuffmanTableSize"},
	"1000xxx3": {VR: "US", VM: "3", Name: "Huffman Table Triplet", Retired: true, Keyword: "HuffmanTableTriplet"},
	"1000xxx4": {VR: "US", VM: "1", Name: "Shift Table Size", Retired: true, Keyword: "ShiftTableSize"},
	"1000xxx5": {VR: "US", VM: "3", Name: "Shift Table Triplet", Retired: true, Keyword: "ShiftTableTriplet"},
	"1010xxxx": {VR: "US", VM: "1-n", Name: "Zonal Map", Retired: true, Keyword: "ZonalMap"},
	"50xx0005": {VR: "US", VM: "1", Name: "Curve Dimensions", Retired: true, Keyword: "CurveDimensions"},
	"50xx0010": {VR: "US", VM: "1", Name: "Number of Points", Retired: true, Keyword: "NumberOfPoints"},
	"50xx0020": {VR: "CS", VM: "1", Name: "Type of Data", Retired: true, Keyword: "TypeOfData"},
	"50xx0022": {VR: "LO", VM: "1", Name: "Curve Description", Retired: true, Keyword: "CurveDescription"},
	"50xx0030": {VR: "SH", VM: "1-n", Name: "Axis Units", Retired: true, Keyword: "AxisUnits"},
	"50xx0040": {VR: "SH", VM: "1-n", Name: "Axis Labels", Retired: true, Keyword: "AxisLabels"},
	"50xx0103": {VR: "US", VM: "1", Name: "Data Value Representation", Retired: true, Keyword: "DataValueRepresentation"},
	"50xx0104": {VR: "US", VM: "1-n", Name: "Minimum Coordinate Value", Retired: true, Keyword: "MinimumCoordinateValue"},
	"50xx0105": {VR: "US", VM: "1-n", Name: "Maximum Coordinate Value", Retired: true, Keyword: "MaximumCoordinateValue"},
	"50xx0106": {VR: "SH", VM: "1-n", Name: "Curve Range", Retired: true, Keyword: "CurveRange"},
	"50xx0110": {VR: "US", VM: "1-n", Name: "Curve Data Descriptor", Retired: true, Keyword: "CurveDataDescriptor"},
	"50xx0112": {VR: "US", VM: "1-n", Name: "Coordinate Start Value", Retired: true, Keyword: "CoordinateStartValue"},
	"50xx0114": {VR: "US", VM: "1-n", Name: "Coordinate Step Value", Retired: true, Keyword: "CoordinateStepValue"},
	"50xx1001": {VR: "CS", VM: "1", Name: "Curve Activation Layer", Retired: true, Keyword: "CurveActivationLayer"},
	"50xx2000": {VR: "US", VM: "1", Name: "Audio Type", Retired: true, Keyword: "AudioType"},
	"50xx2002": {VR: "US", VM: "1", Name: "Audio Sample Format", Retired: true, Keyword: "AudioSampleFormat"},
	"50xx2004": {VR: "US", VM: "1", Name: "Number of Channels", Retired: true, Keyword: "NumberOfChannels"},
	"50xx2006": {VR: "UL", VM: "1", Name: "Number of Samples", Retired: true, Keyword: "NumberOfSamples"},
	"50xx2008": {VR: "UL", VM: "1", Name: "Sample Rate", Retired: true, Keyword: "SampleRate"},
	"50xx200A": {VR: "UL", VM: "1", Name: "Total Time", Retired: true, Keyword: "TotalTime"},
	"50xx200C": {VR: "OB or OW", VM: "1", Name: "Audio Sample Data", Retired: true, Keyword: "AudioSampleData"},
	"50xx200E": {VR: "LT", VM: "1", Name: "Audio Comments", Retired: true, Keyword: "AudioComments"},
	"50xx2500": {VR: "LO", VM: "1", Name: "Curve Label", Retired: true, Keyword: "CurveLabel"},
	"50xx2600": {VR: "SQ", VM: "1", Name: "Curve Referenced Overlay Sequence", Retired: true, Keyword: "CurveReferencedOverlaySequence"},
	"50xx2610": {VR: "US", VM: "1", Name: "Curve Referenced Overlay Group", Retired: true, Keyword: "CurveReferencedOverlayGroup"},
	"50xx3000": {VR: "OB or OW", VM: "1", Name: "Curve Data", Retired: true, Keyword: "CurveData"},
	"60xx0010": {VR: "US", VM: "1", Name: "Overlay Rows", Retired: false, Keyword: "OverlayRows"},
	"60xx0011": {VR: "US", VM: "1", Name: "Overlay Columns", Retired: false, Keyword: "OverlayColumns"},
	"60xx0012": {VR: "US", VM: "1", Name: "Overlay Planes", Retired: true, Keyword: "OverlayPlanes"},
	"60xx0015": {VR: "IS", VM: "1", Name: "Number of Frames in Overlay", Retired: false, Keyword: "NumberOfFramesInOverlay"},
	"60xx0022": {VR: "LO", VM: "1", Name: "Overlay Description", Retired: false, Keyword: "OverlayDescription"},
	"60xx0040": {VR: "CS", VM: "1", Name: "Overlay Type", Retired: false, Keyword: "OverlayType"},
	"60xx0045": {VR: "LO", VM: "1", Name: "Overlay Subtype", Retired: false, Keyword: "OverlaySubtype"},
	"60xx0050": {VR: "SS", VM: "2", Name: "Overlay Origin", Retired: false, Keyword: "OverlayOrigin"},
	"60xx0051": {VR: "US", VM: "1", Name: "Image Frame Origin", Retired: false, Keyword: "ImageFrameOrigin"},
	"60xx0052": {VR: "US", VM: "1", Name: "Overlay Plane Origin", Retired: true, Keyword: "OverlayPlaneOrigin"},
	"60xx0060": {VR: "CS", VM: "1", Name: "Overlay Compression Code", Retired: true, Keyword: "OverlayCompressionCode"},
	"60xx0061": {VR: "SH", VM: "1", Name: "Overlay Compression Originator", Retired: true, Keyword: "OverlayCompressionOriginator"},
	"60xx0062": {VR: "SH", VM: "1", Name: "Overlay Compression Label", Retired: true, Keyword: "OverlayCompressionLabel"},
	"60xx0063": {VR: "CS", VM: "1", Name: "Overlay Compression Description", Retired: true, Keyword: "OverlayCompressionDescription"},
	"60xx0066": {VR: "AT", VM: "1-n", Name: "Overlay Compression Step Pointers", Retired: true, Keyword: "OverlayCompressionStepPointers"},
	"60xx0068": {VR: "US", VM: "1", Name: "Overlay Repeat Interval", Retired: true, Keyword: "OverlayRepeatInterval"},
	"60xx0069": {VR: "US", VM: "1", Name: "Overlay Bits Grouped", Retired: true, Keyword: "OverlayBitsGrouped"},
	"60xx0100": {VR: "US", VM: "1", Name: "Overlay Bits Allocated", Retired: false, Keyword: "OverlayBitsAllocated"},
	"60xx0102": {VR: "US", VM: "1", Name: "Overlay Bit Position", Retired: false, Keyword: "OverlayBitPosition"},
	"60xx0110": {VR: "CS", VM: "1", Name: "Overlay Format", Retired: true, Keyword: "OverlayFormat"},
	"60xx0200": {VR: "US", VM: "1", Name: "Overlay Location", Retired: true, Keyword: "OverlayLocation"},
	"60xx0800": {VR: "CS", VM: "1-n", Name: "Overlay Code Label", Retired: true, Keyword: "OverlayCodeLabel"},
	"60xx0802": {VR: "US", VM: "1", Name: "Overlay Number of Tables", Retired: true, Keyword: "OverlayNumberOfTables"},
	"60xx0803": {VR: "AT", VM: "1-n", Name: "Overlay Code Table Location", Retired: true, Keyword: "OverlayCodeTableLocation"},
	"60xx0804": {VR: "US", VM: "1", Name: "Overlay Bits For Code Word", Retired: true, Keyword: "OverlayBitsForCodeWord"},
	"60xx1001": {VR: "CS", VM: "1", Name: "Overlay Activation Layer", Retired: false, Keyword: "OverlayActivationLayer"},
	"60xx1100": {VR: "US", VM: "1", Name: "Overlay Descriptor - Gray", Retired: true, Keyword: "OverlayDescriptorGray"},
	"60xx1101": {VR: "US", VM: "1", Name: "Overlay Descriptor - Red", Retired: true, Keyword: "OverlayDescriptorRed"},
	"60xx1102": {VR: "US", VM: "1", Name: "Overlay Descriptor - Green", Retired: true, Keyword: "OverlayDescriptorGreen"},
	"60xx1103": {VR: "US", VM: "1", Name: "Overlay Descriptor - Blue", Retired: true, Keyword: "OverlayDescriptorBlue"},
	"60xx1200": {VR: "US", VM: "1-n", Name: "Overlays - Gray", Retired: true, Keyword: "OverlaysGray"},
	"60xx1201": {VR: "US", VM: "1-n", Name: "Overlays - Red", Retired: true, Keyword: "OverlaysRed"},
	"60xx1202": {VR: "US", VM: "1-n", Name: "Overlays - Green", Retired: true, Keyword: "OverlaysGreen"},
	"60xx1203": {VR: "US", VM: "1-n", Name: "Overlays - Blue", Retired: true, Keyword: "OverlaysBlue"},
	"60xx1301": {VR: "IS", VM: "1", Name: "ROI Area", Retired: false, Keyword: "ROIArea"},
	"60xx1302": {VR: "DS", VM: "1", Name: "ROI Mean", Retired: false, Keyword: "ROIMean"},
	"60xx1303": {VR: "DS", VM: "1", Name: "ROI Standard Deviation", Retired: false, Keyword: "ROIStandardDeviation"},
	"60xx1500": {VR: "LO", VM: "1", Name: "Overlay Label", Retired: false, Keyword: "OverlayLabel"},
	"60xx3000": {VR: "OB or OW", VM: "1", Name: "Overlay Data", Retired: false, Keyword: "OverlayData"},
	"60xx4000": {VR: "LT", VM: "1", Name: "Overlay Comments", Retired: true, Keyword: "OverlayComments"},
	"7Fxx0010": {VR: "OB or OW", VM: "1", Name: "Variable Pixel Data", Retired: true, Keyword: "VariablePixelData"},
	"7Fxx0011": {VR: "US", VM: "1", Name: "Variable Next Data Group", Retired: true, Keyword: "VariableNextDataGroup"},
	"7Fxx0020": {VR: "OW", VM: "1", Name: "Variable Coefficients SDVN", Retired: true, Keyword: "VariableCoefficientsSDVN"},
	"7Fxx0030": {VR: "OW", VM: "1", Name: "Variable Coefficients SDHN", Retired: true, Keyword: "VariableCoefficientsSDHN"},
	"7Fxx0040": {VR: "OW", VM: "1", Name: "Variable Coefficients SDDN", Retired: true, Keyword: "VariableCoefficientsSDDN"},
}

RepeatersDictionaryGo maps mask patterns to entries

StandardVRs contains all standard VRs.

View Source
var UIDDictionary = uid.Dictionary

UIDDictionary maps UID values to their metadata.

Functions

func AddPrivateDictEntry

func AddPrivateDictEntry(creator string, tag Tag, vr VR, name string, vm ...string) error

AddPrivateDictEntry adds or updates a runtime private dictionary entry.

func BufferEquality

func BufferEquality(a, b interface{}) bool

BufferEquality checks if two buffers are equal.

func BufferLength

func BufferLength(buf interface{}) (int64, error)

BufferLength returns the length of a buffer.

func CheckBuffer

func CheckBuffer(buf interface{}) error

CheckBuffer validates a buffer for bulk data VRs.

func ConvertCharacterSets added in v0.5.0

func ConvertCharacterSets(values []string) []string

ConvertCharacterSets normalizes DICOM Specific Character Set values for decoding.

func CorrectAmbiguousVR

func CorrectAmbiguousVR(ds *Dataset, isLittleEndian bool, ancestors []*Dataset) error

CorrectAmbiguousVR walks ds correcting ambiguous VR elements when possible. Mirrors pydicom.filewriter.correct_ambiguous_vr.

func CorrectAmbiguousVRPreservingRaw added in v0.6.0

func CorrectAmbiguousVRPreservingRaw(ds *Dataset, isLittleEndian bool, ancestors []*Dataset) error

CorrectAmbiguousVRPreservingRaw corrects ambiguous VR elements that are not stored as raw bytes. Used before implicit writes with in-memory values while keeping raw element roundtrips intact.

func DecodeBytes

func DecodeBytes(b []byte, encodings []string) string

DecodeBytes decodes using the first matching encoding (legacy helper).

func DecodeBytesWithDelimiters added in v0.5.0

func DecodeBytesWithDelimiters(b []byte, encodings []string, delimiters map[byte]bool) string

DecodeBytesWithDelimiters decodes a DICOM text byte string with ISO-2022 code extensions.

func DecodeString

func DecodeString(b []byte, encodingName string) (string, error)

func EncodeBytesWithCharsets added in v0.5.0

func EncodeBytesWithCharsets(s string, encodings []string) []byte

EncodeBytesWithCharsets encodes a Unicode string for DICOM text VRs.

func EncodeDataset added in v0.21.0

func EncodeDataset(ds *Dataset, transferSyntaxUID string) ([]byte, error)

EncodeDataset encodes ds as a DICOM dataset only (no preamble / File Meta), using transferSyntaxUID for VR, endianness, and Deflated compression when applicable. Suitable for DIMSE C-STORE / C-FIND payloads.

func EncodeDatasetEncoding added in v0.21.0

func EncodeDatasetEncoding(ds *Dataset, isImplicitVR, isLittleEndian bool) ([]byte, error)

EncodeDatasetEncoding encodes ds with explicit VR/endian flags (no preamble / File Meta). Matches pynetdicom.dsutils.encode / pydicom write_dataset.

func EncodeFile added in v0.23.0

func EncodeFile(fd *FileDataset, opts *WriteOptions) ([]byte, error)

EncodeFile encodes fd as a Part 10 DICOM file (preamble + DICM + File Meta + dataset).

func EncodePersonNameWithCharsets added in v0.5.0

func EncodePersonNameWithCharsets(pn PersonName, encodings []string) []byte

EncodePersonNameWithCharsets encodes a PersonName for writing.

func EncodeString

func EncodeString(s string, encodingName string) ([]byte, error)

func FormatNumberAsDS added in v0.15.0

func FormatNumberAsDS(val float64) (string, error)

FormatNumberAsDS formats a float as a DICOM Decimal String (≤16 chars). Mirrors pydicom.valuerep.format_number_as_ds.

func ISInRange added in v0.15.0

func ISInRange(v int64) bool

ISInRange reports whether v fits the DICOM IS value range [-2^31, 2^31).

func IsAmbiguousVR

func IsAmbiguousVR(vr VR) bool

IsAmbiguousVR reports whether vr is an ambiguous VR from the DICOM dictionary.

func IsBinaryVR

func IsBinaryVR(vr VR) bool

IsBinaryVR returns true if the VR is a binary (bytes-like) VR.

func IsFloatVR

func IsFloatVR(vr VR) bool

IsFloatVR returns true if the VR is a floating-point VR.

func IsIntVR

func IsIntVR(vr VR) bool

IsIntVR returns true if the VR is an integer VR.

func IsRepeaterTag

func IsRepeaterTag(tag Tag) bool

IsRepeaterTag returns true if the tag matches a repeater pattern.

func IsStringVR

func IsStringVR(vr VR) bool

IsStringVR returns true if the VR is a string-like VR.

func IsValidDS added in v0.15.0

func IsValidDS(s string) bool

IsValidDS reports whether s is a valid DICOM Decimal String (VR=DS). Mirrors pydicom.valuerep.is_valid_ds.

func IsValidIS added in v0.15.0

func IsValidIS(s string) bool

IsValidIS reports whether s is a valid DICOM Integer String (VR=IS) by length and character set (not numeric range).

func ParseCharacterSets added in v0.5.0

func ParseCharacterSets(value interface{}) []string

ParseCharacterSets splits a Specific Character Set value into DICOM encoding names.

func PrivateDictionaryDescription

func PrivateDictionaryDescription(tag Tag, creator string) (string, error)

PrivateDictionaryDescription returns the name for a private element.

func PrivateDictionaryVM

func PrivateDictionaryVM(tag Tag, creator string) (string, error)

PrivateDictionaryVM returns the VM for a private element.

func ResetExtraPrivateDictionaries

func ResetExtraPrivateDictionaries()

ResetExtraPrivateDictionaries clears runtime private dictionary additions. Intended for tests.

func ValidateFileMeta

func ValidateFileMeta(fileMeta *FileMetaDataset, enforceStandard bool) error

ValidateFileMeta validates File Meta Information elements. Mirrors pydicom.dataset.validate_file_meta.

func ValidateUID

func ValidateUID(s string) error

ValidateUID checks if the UID string conforms to DICOM rules.

func Write added in v0.23.0

func Write(w io.Writer, fd *FileDataset, opts *WriteOptions) error

Write encodes fd as a Part 10 DICOM file to w.

func WriteDataset added in v0.21.0

func WriteDataset(w io.Writer, ds *Dataset, transferSyntaxUID string) error

WriteDataset encodes ds with transferSyntaxUID and writes the result to w.

func WriteFile

func WriteFile(filename string, ds *Dataset, opts *WriteOptions) error

WriteFile writes a Dataset to a DICOM file.

Types

type BytesLengthError

type BytesLengthError struct {
	Expected int
	Actual   int
	VR       VR
}

BytesLengthError is returned when a value has an unexpected byte length.

func (*BytesLengthError) Error

func (e *BytesLengthError) Error() string

type DA added in v0.4.0

type DA struct {
	Time     time.Time
	Original string
}

DA holds a DICOM Date (VR=DA) value.

func ParseDA added in v0.4.0

func ParseDA(s string) (DA, error)

ParseDA parses a DICOM DA string.

func (DA) Equal added in v0.15.0

func (d DA) Equal(other DA) bool

func (DA) IsZero added in v0.4.0

func (d DA) IsZero() bool

func (DA) String added in v0.4.0

func (d DA) String() string

type DS added in v0.4.0

type DS struct {
	Value    float64
	Original string
}

DS holds a DICOM Decimal String (VR=DS) value.

func DSFromFloat added in v0.15.0

func DSFromFloat(val float64) (DS, error)

DSFromFloat builds a DS whose Original is a valid DICOM decimal string.

func ParseDS added in v0.4.0

func ParseDS(s string) (DS, error)

ParseDS parses a DICOM DS string.

func (DS) Equal added in v0.15.0

func (d DS) Equal(other DS) bool

func (DS) IsZero added in v0.4.0

func (d DS) IsZero() bool

func (DS) String added in v0.4.0

func (d DS) String() string

type DT added in v0.4.0

type DT struct {
	Time     time.Time
	Original string
}

DT holds a DICOM DateTime (VR=DT) value.

func ParseDT added in v0.4.0

func ParseDT(s string) (DT, error)

ParseDT parses a DICOM DT string.

func (DT) Equal added in v0.15.0

func (d DT) Equal(other DT) bool

func (DT) IsZero added in v0.4.0

func (d DT) IsZero() bool

func (DT) String added in v0.4.0

func (d DT) String() string

type DataElement

type DataElement = Element

DataElement is an alias for Element.

func NewDataElement

func NewDataElement(tag Tag, vr VR, value interface{}) *DataElement

NewDataElement creates a DICOM data element.

type Dataset

type Dataset struct {
	IsUndefinedLengthSequenceItem bool
	// contains filtered or unexported fields
}

Dataset represents a DICOM Dataset - a collection of DataElements keyed by Tag.

func DecodeDataset added in v0.22.0

func DecodeDataset(data []byte, transferSyntaxUID string) (*Dataset, error)

DecodeDataset decodes a DICOM dataset (no preamble / File Meta) using transferSyntaxUID. Suitable for DIMSE Identifiers and C-STORE datasets.

func DecodeDatasetEncoding added in v0.22.0

func DecodeDatasetEncoding(data []byte, isImplicitVR, isLittleEndian bool) (*Dataset, error)

DecodeDatasetEncoding decodes a DICOM dataset with explicit VR/endian flags.

func NewDataset

func NewDataset() *Dataset

func (*Dataset) BytesValue

func (d *Dataset) BytesValue(tag Tag) ([]byte, bool)

func (*Dataset) Clear added in v0.14.0

func (d *Dataset) Clear()

Clear removes all elements from the dataset. Mirrors pydicom Dataset.clear.

func (*Dataset) Clone

func (d *Dataset) Clone() *Dataset

Clone returns a deep copy of the dataset, including sequence items.

func (*Dataset) Delete

func (d *Dataset) Delete(tag Tag)

func (*Dataset) ElementByKeyword added in v0.14.0

func (d *Dataset) ElementByKeyword(keyword string) (*DataElement, bool)

ElementByKeyword returns the element for a DICOM keyword, if present. Mirrors pydicom Dataset.data_element.

func (*Dataset) Elements

func (d *Dataset) Elements() map[Tag]*DataElement

func (*Dataset) Encode added in v0.21.0

func (d *Dataset) Encode(transferSyntaxUID string) ([]byte, error)

Encode returns the dataset bytes (no preamble / File Meta) for transferSyntaxUID.

func (*Dataset) EncodeEncoding added in v0.21.0

func (d *Dataset) EncodeEncoding(isImplicitVR, isLittleEndian bool) ([]byte, error)

EncodeEncoding returns the dataset bytes using explicit VR/endian flags.

func (*Dataset) Equal added in v0.14.0

func (d *Dataset) Equal(other *Dataset) bool

Equal reports whether d and other contain the same tags, VRs, and values. Mirrors pydicom Dataset.__eq__ for Dataset values.

func (*Dataset) FloatValue

func (d *Dataset) FloatValue(tag Tag) (float64, bool)

func (*Dataset) FormattedLines added in v0.16.0

func (d *Dataset) FormattedLines(opts *FormatLinesOptions) []string

FormattedLines returns formatted lines for every element, recursing into sequences. Mirrors pydicom Dataset.formatted_lines.

func (*Dataset) Get

func (d *Dataset) Get(tag Tag) (*DataElement, bool)

func (*Dataset) GetBytes

func (d *Dataset) GetBytes(tag Tag) ([]byte, bool)

func (*Dataset) GetDA added in v0.4.0

func (d *Dataset) GetDA(tag Tag) (DA, bool)

func (*Dataset) GetDS added in v0.4.0

func (d *Dataset) GetDS(tag Tag) (DS, bool)

func (*Dataset) GetDT added in v0.4.0

func (d *Dataset) GetDT(tag Tag) (DT, bool)

func (*Dataset) GetDataElement

func (d *Dataset) GetDataElement(tag Tag) *DataElement

func (*Dataset) GetFloat

func (d *Dataset) GetFloat(tag Tag) (float64, bool)

func (*Dataset) GetFloats added in v0.18.0

func (d *Dataset) GetFloats(tag Tag) ([]float64, bool)

GetFloats returns all floating values for a DS/FD/FL multi-valued element.

func (*Dataset) GetIS added in v0.4.0

func (d *Dataset) GetIS(tag Tag) (IS, bool)

func (*Dataset) GetInt

func (d *Dataset) GetInt(tag Tag) (int, bool)

func (*Dataset) GetPN added in v0.5.0

func (d *Dataset) GetPN(tag Tag) (PersonName, bool)

func (*Dataset) GetSequence

func (d *Dataset) GetSequence(tag Tag) (*Sequence, bool)

func (*Dataset) GetString

func (d *Dataset) GetString(tag Tag) (string, bool)

func (*Dataset) GetTM added in v0.4.0

func (d *Dataset) GetTM(tag Tag) (TM, bool)

func (*Dataset) GroupDataset added in v0.14.0

func (d *Dataset) GroupDataset(group int) *Dataset

GroupDataset returns a new dataset containing only elements of the given group. Mirrors pydicom Dataset.group_dataset.

func (*Dataset) Has

func (d *Dataset) Has(tag Tag) bool

func (*Dataset) IntValue

func (d *Dataset) IntValue(tag Tag) (int, bool)

func (*Dataset) IsOriginalEncoding added in v0.14.0

func (d *Dataset) IsOriginalEncoding() bool

IsOriginalEncoding reports whether the current write encoding and SpecificCharacterSet match those captured when the dataset was read. Mirrors pydicom Dataset.is_original_encoding.

func (*Dataset) Iter

func (d *Dataset) Iter() []*DataElement

Iter returns all elements sorted by tag.

func (*Dataset) IterAll added in v0.14.0

func (d *Dataset) IterAll() []*DataElement

IterAll returns all elements in tag order, recursing into sequences. Mirrors pydicom Dataset.iterall.

func (*Dataset) Len

func (d *Dataset) Len() int

func (*Dataset) LoadDeferred

func (d *Dataset) LoadDeferred(tag Tag) error

LoadDeferred reads a deferred element's value from the source file/buffer. Mirrors pydicom deferred read triggered by Dataset.__getitem__.

func (*Dataset) Pop added in v0.14.0

func (d *Dataset) Pop(tag Tag) (*DataElement, bool)

Pop removes and returns the element for tag. Mirrors pydicom Dataset.pop for tag keys.

func (*Dataset) PrivateBlock

func (d *Dataset) PrivateBlock(group int, creator string) *PrivateBlock

func (*Dataset) RemovePrivateTags added in v0.14.0

func (d *Dataset) RemovePrivateTags()

RemovePrivateTags deletes all private elements, including nested sequences. Mirrors pydicom Dataset.remove_private_tags.

func (*Dataset) SaveAs

func (d *Dataset) SaveAs(filename string, opts *WriteOptions) error

func (*Dataset) SequenceValue

func (d *Dataset) SequenceValue(tag Tag) (*Sequence, bool)

func (*Dataset) Set

func (d *Dataset) Set(element *DataElement)

func (*Dataset) SetOriginalEncoding added in v0.14.0

func (d *Dataset) SetOriginalEncoding(isImplicit, isLittleEndian bool, charsets []string)

SetOriginalEncoding records the encoding used when the dataset was decoded. Mirrors pydicom Dataset.set_original_encoding.

func (*Dataset) SetWriteEncoding added in v0.14.0

func (d *Dataset) SetWriteEncoding(isImplicit, isLittleEndian bool)

SetWriteEncoding sets the VR/endianness that would be used for writing. Used with IsOriginalEncoding; nil write encoding means "same as original".

func (*Dataset) SortedTags

func (d *Dataset) SortedTags() []Tag

SortedTags returns all tags in ascending order.

func (*Dataset) String

func (d *Dataset) String() string

func (*Dataset) StringValue

func (d *Dataset) StringValue(tag Tag) (string, bool)

func (*Dataset) Top added in v0.16.0

func (d *Dataset) Top() string

Top returns a string representation of only top-level elements. Mirrors pydicom Dataset.top.

func (*Dataset) Update added in v0.14.0

func (d *Dataset) Update(other *Dataset)

Update copies elements from other into d (overwriting matching tags). Mirrors pydicom Dataset.update for Dataset sources.

func (*Dataset) Walk

func (d *Dataset) Walk(fn WalkFunc, recursive bool)

Walk visits each element in tag order, optionally recursing into sequences. Mirrors pydicom Dataset.walk.

type DicomBytesIO deprecated

type DicomBytesIO = dicomBytesIO

DicomBytesIO wraps an in-memory DICOM byte reader.

Deprecated: this type is internal and will be removed.

func NewDicomBytesIO deprecated

func NewDicomBytesIO(data []byte) *DicomBytesIO

NewDicomBytesIO creates an in-memory DICOM byte reader.

Deprecated: this constructor is internal and will be removed.

type DicomIO deprecated

type DicomIO = dicomIO

DicomIO reads and writes DICOM primitive values.

Deprecated: this type is internal and will be removed.

func NewDicomReader deprecated

func NewDicomReader(r io.ReadSeeker) *DicomIO

NewDicomReader creates a DICOM reader.

Deprecated: this constructor is internal and will be removed.

func NewDicomWriter deprecated

func NewDicomWriter(w io.Writer) *DicomIO

NewDicomWriter creates a DICOM writer.

Deprecated: this constructor is internal and will be removed.

type DictEntry

type DictEntry struct {
	VR      string
	VM      string
	Name    string
	Retired bool
	Keyword string
}

type Element

type Element struct {
	Tag            Tag
	VR             VR
	Value          interface{}
	RawValue       []byte // original value bytes from read; written verbatim when set
	ValueTell      int64  // value offset in source; used for deferred reads
	ValueLength    uint32 // byte length when deferred
	Deferred       bool   // value not yet loaded from source
	IsImplicitVR   bool   // encoding at read time; for deferred load
	IsLittleEndian bool

	FileTell          int64
	IsUndefinedLength bool
	PrivateCreator    string
	// contains filtered or unexported fields
}

Element holds a single DICOM data element.

func NewElement

func NewElement(tag Tag, vr VR, value interface{}) *Element

func (*Element) Equal

func (e *Element) Equal(other *Element) bool

func (*Element) IsEmpty

func (e *Element) IsEmpty() bool

func (*Element) IsPrivate

func (e *Element) IsPrivate() bool

func (*Element) IsRaw added in v0.6.0

func (e *Element) IsRaw() bool

func (*Element) Keyword

func (e *Element) Keyword() string

func (*Element) Name

func (e *Element) Name() string

func (*Element) ReprValue

func (e *Element) ReprValue() string

func (*Element) String

func (e *Element) String() string

func (*Element) VM

func (e *Element) VM() int

type EncodingInfo

type EncodingInfo struct {
	IsImplicitVR   bool
	IsLittleEndian bool
}

EncodingInfo describes the DICOM encoding used when reading/writing.

type FileDataset

type FileDataset struct {
	*Dataset
	Filename  string
	Preamble  []byte
	FileMeta  *FileMetaDataset
	Timestamp string // file modification time as Unix seconds (deferred read checks)
}

FileDataset extends Dataset with file-specific info.

func Read added in v0.24.0

func Read(r io.Reader, opts *ReadOptions) (*FileDataset, error)

Read parses a DICOM Part 10 dataset from r.

Prefer a seekable source (*os.File, io.ReadSeeker, io.ReaderAt): the parser walks tags without io.ReadAll, so StopBeforePixels / DeferSize / SpecificTags can skip large values without buffering them. Deferred elements are reloaded later by reopening the path when r is an *os.File (see ReadFile).

Non-seekable readers fall back to buffering the stream (then ReadBytes).

func ReadBytes added in v0.23.0

func ReadBytes(data []byte, opts *ReadOptions) (*FileDataset, error)

ReadBytes parses a Part 10 DICOM file from data (preamble optional when Force).

func ReadFile

func ReadFile(filename string, opts *ReadOptions) (*FileDataset, error)

ReadFile reads a DICOM file from filename.

func (*FileDataset) ApplyModalityLUT added in v0.18.0

func (fd *FileDataset) ApplyModalityLUT(arr []float64) ([]float64, error)

ApplyModalityLUT applies Modality LUT Sequence or Rescale Slope/Intercept. Mirrors pydicom.pixels.processing.apply_modality_lut.

func (*FileDataset) ApplyPresentationLUTShape added in v0.18.0

func (fd *FileDataset) ApplyPresentationLUTShape(arr []float64) ([]float64, error)

ApplyPresentationLUTShape applies (2050,0020) Presentation LUT Shape when present.

func (*FileDataset) ApplyVOILUT added in v0.18.0

func (fd *FileDataset) ApplyVOILUT(arr []float64, index int, preferLUT bool) ([]float64, error)

ApplyVOILUT applies VOI LUT Sequence or Window Center/Width. preferLUT matches pydicom apply_voi_lut(prefer_lut=...).

func (*FileDataset) CompressPixelData added in v0.19.0

func (fd *FileDataset) CompressPixelData(transferSyntaxUID string, opts ...pixels.EncodeOption) error

CompressPixelData re-encodes current Pixel Data to transferSyntaxUID and updates PixelData + FileMeta.TransferSyntaxUID.

Supported targets: uncompressed (native), RLE Lossless, Deflated Image Frame Compression, JPEG 2000 Lossless, JPEG 2000. JPEG / JPEG-LS encode is not available (golibjpeg upstream has no encoder).

Source frames are decoded with Raw=true (no photometric post-process).

func (*FileDataset) EncodeFile added in v0.23.0

func (fd *FileDataset) EncodeFile(opts *WriteOptions) ([]byte, error)

EncodeFile returns Part 10 DICOM file bytes for fd.

func (*FileDataset) PixelBytes

func (fd *FileDataset) PixelBytes(opts ...pixels.DecodeOption) ([]byte, error)

PixelBytes returns decoded pixel data as a contiguous byte buffer. For multi-frame images, frames are concatenated in order.

func (*FileDataset) PixelFrames

func (fd *FileDataset) PixelFrames(opts ...pixels.DecodeOption) ([][]byte, error)

PixelFrames returns decoded pixel data, one slice per frame.

func (*FileDataset) PixelSamples added in v0.18.0

func (fd *FileDataset) PixelSamples(opts ...pixels.DecodeOption) ([]float64, error)

PixelSamples returns decoded pixel samples as float64 (one per sample). Decoding options match PixelBytes; photometric YBR→RGB still applies when Raw=false.

func (*FileDataset) SaveAs

func (fd *FileDataset) SaveAs(filename string, opts *WriteOptions) error

func (*FileDataset) SetEncodedPixelData added in v0.19.0

func (fd *FileDataset) SetEncodedPixelData(encoded *pixels.EncodedPixelData) error

SetEncodedPixelData writes encoded Pixel Data and updates transfer syntax metadata.

func (*FileDataset) TransferSyntaxUID

func (fd *FileDataset) TransferSyntaxUID() (string, bool)

TransferSyntaxUID returns the file meta transfer syntax UID string.

func (*FileDataset) Write added in v0.23.0

func (fd *FileDataset) Write(w io.Writer, opts *WriteOptions) error

Write encodes fd as a Part 10 DICOM file to w.

type FileMetaDataset

type FileMetaDataset struct {
	*Dataset
}

FileMetaDataset holds DICOM File Meta Information (group 0x0002).

func NewFileMetaDataset

func NewFileMetaDataset() *FileMetaDataset

type FormatLinesOptions added in v0.16.0

type FormatLinesOptions struct {
	ElementFormat         string
	SequenceElementFormat string
}

FormatLinesOptions controls Dataset.FormattedLines output.

type IS added in v0.4.0

type IS struct {
	Value    int64
	Original string
}

IS holds a DICOM Integer String (VR=IS) value.

func ParseIS added in v0.4.0

func ParseIS(s string) (IS, error)

ParseIS parses a DICOM IS string.

func (IS) Equal added in v0.15.0

func (i IS) Equal(other IS) bool

func (IS) IsZero added in v0.4.0

func (i IS) IsZero() bool

func (IS) String added in v0.4.0

func (i IS) String() string

type InvalidDICOMError

type InvalidDICOMError struct {
	Message string
}

InvalidDICOMError is returned when data is not valid DICOM.

func (*InvalidDICOMError) Error

func (e *InvalidDICOMError) Error() string

type MultiValue

type MultiValue[T any] struct {
	// contains filtered or unexported fields
}

MultiValue holds a DICOM multi-valued element. All items must be of the same type.

func NewMultiValue

func NewMultiValue[T any](items []T) *MultiValue[T]

func (*MultiValue[T]) Append

func (mv *MultiValue[T]) Append(v T)

func (*MultiValue[T]) Get

func (mv *MultiValue[T]) Get(i int) T

func (*MultiValue[T]) IsEmpty

func (mv *MultiValue[T]) IsEmpty() bool

func (*MultiValue[T]) Len

func (mv *MultiValue[T]) Len() int

func (*MultiValue[T]) Set

func (mv *MultiValue[T]) Set(i int, v T)

func (*MultiValue[T]) Values

func (mv *MultiValue[T]) Values() []T

type PersonName

type PersonName struct {
	Alphabetic  string
	Ideographic string
	Phonetic    string
	Original    string
}

PersonName holds a DICOM Person Name (VR=PN) value.

func FromNamedComponents added in v0.5.0

func FromNamedComponents(family, given, middle, prefix, suffix string) PersonName

FromNamedComponents builds a PersonName from alphabetic name parts.

func ParsePersonName

func ParsePersonName(s string) PersonName

ParsePersonName parses a decoded PN string into components.

func PersonNameFromParts added in v0.15.0

func PersonNameFromParts(p PersonNameParts) PersonName

PersonNameFromParts builds a PersonName from structured component parts.

func PersonNameFromVeterinary added in v0.15.0

func PersonNameFromVeterinary(responsibleParty, patientName string) PersonName

PersonNameFromVeterinary builds a veterinary PN (responsible party ^ patient name). Mirrors pydicom PersonName.from_named_components_veterinary.

func (PersonName) Components added in v0.5.0

func (pn PersonName) Components() []string

Components returns the alphabetic, ideographic, and phonetic groups.

func (PersonName) Equal added in v0.15.0

func (pn PersonName) Equal(other PersonName) bool

func (PersonName) FamilyCommaGiven added in v0.5.0

func (pn PersonName) FamilyCommaGiven() string

FamilyCommaGiven returns "Family, Given" for the alphabetic group.

func (PersonName) FamilyName added in v0.5.0

func (pn PersonName) FamilyName() string

FamilyName returns the first ^-delimited component of the alphabetic group.

func (PersonName) Formatted added in v0.5.0

func (pn PersonName) Formatted(format string) string

Formatted substitutes named components into a format string. Supported names: family_name, given_name, middle_name, name_prefix, name_suffix, ideographic, phonetic.

func (PersonName) GivenName added in v0.5.0

func (pn PersonName) GivenName() string

GivenName returns the second ^-delimited component of the alphabetic group.

func (PersonName) IsZero added in v0.5.0

func (pn PersonName) IsZero() bool

func (PersonName) MiddleName added in v0.5.0

func (pn PersonName) MiddleName() string

MiddleName returns the third ^-delimited component of the alphabetic group.

func (PersonName) NamePrefix added in v0.5.0

func (pn PersonName) NamePrefix() string

NamePrefix returns the fourth ^-delimited component of the alphabetic group.

func (PersonName) NameSuffix added in v0.5.0

func (pn PersonName) NameSuffix() string

NameSuffix returns the fifth ^-delimited component of the alphabetic group.

func (PersonName) String

func (pn PersonName) String() string

type PersonNameParts added in v0.15.0

type PersonNameParts struct {
	FamilyName string
	GivenName  string
	MiddleName string
	NamePrefix string
	NameSuffix string

	FamilyNameIdeographic string
	GivenNameIdeographic  string
	MiddleNameIdeographic string
	NamePrefixIdeographic string
	NameSuffixIdeographic string

	FamilyNamePhonetic string
	GivenNamePhonetic  string
	MiddleNamePhonetic string
	NamePrefixPhonetic string
	NameSuffixPhonetic string
}

PersonNameParts holds named PN components across alphabetic/ideographic/phonetic groups. Mirrors pydicom PersonName.from_named_components keyword arguments.

type PrivateBlock

type PrivateBlock struct {
	Group          int
	PrivateCreator string
	// contains filtered or unexported fields
}

PrivateBlock represents a private block in the dataset.

func (*PrivateBlock) Get

func (pb *PrivateBlock) Get(offset int) (*DataElement, bool)

func (*PrivateBlock) GetTag

func (pb *PrivateBlock) GetTag(offset int) Tag

func (*PrivateBlock) Set

func (pb *PrivateBlock) Set(offset int, vr VR, value interface{})

type PrivateDictEntry

type PrivateDictEntry struct {
	VR      string
	VM      string
	Name    string
	Retired bool
}

PrivateDictEntry holds metadata for a private DICOM element.

type RawDataElement

type RawDataElement struct {
	Tag            Tag
	VR             VR
	Length         uint32
	Value          []byte
	ValueTell      int64
	IsImplicitVR   bool
	IsLittleEndian bool
	IsRaw          bool
}

RawDataElement holds raw (undecoded) element data from a file.

type ReadOptions

type ReadOptions struct {
	DeferSize        uint32
	StopBeforePixels bool
	Force            bool
	SpecificTags     []Tag
}

type Sequence

type Sequence struct {
	IsUndefinedLength bool
	// contains filtered or unexported fields
}

Sequence holds a list of Dataset items (for VR SQ).

func NewSequence

func NewSequence(items []*Dataset) *Sequence

func (*Sequence) Append

func (s *Sequence) Append(ds *Dataset)

func (*Sequence) Get

func (s *Sequence) Get(i int) *Dataset

func (*Sequence) IsEmpty

func (s *Sequence) IsEmpty() bool

func (*Sequence) Items

func (s *Sequence) Items() []*Dataset

func (*Sequence) Len

func (s *Sequence) Len() int

type TM added in v0.4.0

type TM struct {
	Time     time.Time
	Original string
}

TM holds a DICOM Time (VR=TM) value.

func ParseTM added in v0.4.0

func ParseTM(s string) (TM, error)

ParseTM parses a DICOM TM string.

func (TM) Equal added in v0.15.0

func (t TM) Equal(other TM) bool

func (TM) IsZero added in v0.4.0

func (t TM) IsZero() bool

func (TM) String added in v0.4.0

func (t TM) String() string

type Tag

type Tag = tag.Tag

Tag represents a DICOM element (group, element) tag as a 32-bit integer.

const (
	ItemTag              Tag = tag.Item
	ItemDelimiterTag     Tag = tag.ItemDelimiter
	SequenceDelimiterTag Tag = tag.SequenceDelimiter
	TagPixelRep          Tag = tag.PixelRepresentation
	TagCharset           Tag = tag.SpecificCharacterSet
)

func MustTag

func MustTag(arg interface{}, arg2 ...int) Tag

MustTag is like ParseTag but panics on error.

func NewTag

func NewTag(group, element int) Tag

NewTag creates a tag from group and element numbers.

func ParseTag

func ParseTag(arg interface{}, arg2 ...int) (Tag, error)

ParseTag creates a Tag from various forms:

  • ParseTag(0x00100010)
  • ParseTag(0x0010, 0x0010)
  • ParseTag("PatientName")
  • ParseTag("00100010")

func TagFromKeyword

func TagFromKeyword(keyword string) (Tag, error)

TagFromKeyword returns the tag for a given keyword.

type TagError

type TagError struct {
	Tag Tag
	Err error
}

TagError wraps an error with tag context.

func (*TagError) Error

func (e *TagError) Error() string

func (*TagError) Unwrap

func (e *TagError) Unwrap() error

type UID

type UID = uid.UID

UID represents a DICOM Unique Identifier.

const (
	ImplicitVRLittleEndian         UID = uid.ImplicitVRLittleEndian
	ExplicitVRLittleEndian         UID = uid.ExplicitVRLittleEndian
	DeflatedExplicitVRLittleEndian UID = uid.DeflatedExplicitVRLittleEndian
	ExplicitVRBigEndian            UID = uid.ExplicitVRBigEndian
	JPEGBaseline                   UID = uid.JPEGBaseline
	JPEGExtended                   UID = uid.JPEGExtended
	JPEGLossless                   UID = uid.JPEGLossless
	JPEGLosslessSV1                UID = uid.JPEGLosslessSV1
	JPEGLSLossless                 UID = uid.JPEGLSLossless
	JPEGLSLossy                    UID = uid.JPEGLSLossy
	JPEG2000Lossless               UID = uid.JPEG2000Lossless
	JPEG2000                       UID = uid.JPEG2000
	RLELossless                    UID = uid.RLELossless
	NativePixels                   UID = uid.NativePixels
	VerificationSOPClass           UID = uid.VerificationSOPClass
	CTImageStorage                 UID = uid.CTImageStorage
	PYDICOMImplementationUID       UID = uid.PYDICOMImplementationUID
	GodicomImplementationUID       UID = uid.GodicomImplementationUID
)

func LookupUID

func LookupUID(keyword string) (UID, bool)

LookupUID returns the UID for a dictionary keyword.

type UIDInfo

type UIDInfo = uid.Info

UIDInfo holds metadata about a UID.

type VR

type VR string

VR represents a DICOM Value Representation.

const (
	VRAE VR = "AE"
	VRAS VR = "AS"
	VRAT VR = "AT"
	VRCS VR = "CS"
	VRDA VR = "DA"
	VRDS VR = "DS"
	VRDT VR = "DT"
	VRFD VR = "FD"
	VRFL VR = "FL"
	VRIS VR = "IS"
	VRLO VR = "LO"
	VRLT VR = "LT"
	VROB VR = "OB"
	VROD VR = "OD"
	VROF VR = "OF"
	VROL VR = "OL"
	VROW VR = "OW"
	VROV VR = "OV"
	VRPN VR = "PN"
	VRSH VR = "SH"
	VRSL VR = "SL"
	VRSQ VR = "SQ"
	VRSS VR = "SS"
	VRST VR = "ST"
	VRSV VR = "SV"
	VRTM VR = "TM"
	VRUC VR = "UC"
	VRUI VR = "UI"
	VRUL VR = "UL"
	VRUN VR = "UN"
	VRUR VR = "UR"
	VRUS VR = "US"
	VRUT VR = "UT"
	VRUV VR = "UV"

	// Ambiguous VRs from DICOM PS3.6 Tables 6-1, 7-1 and 8-1
	VRUsSS   VR = "US or SS"
	VRObOw   VR = "OB or OW"
	VRUsOw   VR = "US or OW"
	VRUsSsOw VR = "US or SS or OW"
)

func LookupVR

func LookupVR(tag Tag) VR

LookupVR returns the VR for a tag, with fallback for unknown tags.

func PrivateDictionaryVR

func PrivateDictionaryVR(tag Tag, creator string) (VR, error)

PrivateDictionaryVR returns the VR for a private element.

type WalkFunc

type WalkFunc func(ds *Dataset, elem *Element)

WalkFunc is called for each element in a Dataset during Walk.

type WriteOptions

type WriteOptions struct {
	ImplicitVR        *bool
	LittleEndian      *bool
	EnforceFileFormat bool
}

WriteOptions controls DICOM file writing behavior.

Directories

Path Synopsis
cmd
godicom command
testread command
Package dicomjson converts DICOM datasets to and from JSON.
Package dicomjson converts DICOM datasets to and from JSON.
Package encaps parses DICOM encapsulated (compressed) pixel data.
Package encaps parses DICOM encapsulated (compressed) pixel data.
Package pixels decodes DICOM native and encapsulated pixel data.
Package pixels decodes DICOM native and encapsulated pixel data.
Package tag provides DICOM tag constants and keyword lookup.
Package tag provides DICOM tag constants and keyword lookup.
Package uid provides DICOM UID constants and lookup.
Package uid provides DICOM UID constants and lookup.

Jump to

Keyboard shortcuts

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