### Run DICOM Readfile Example Source: https://github.com/thalesmms/dicom-go/blob/main/README.md Executes the readfile example from the examples directory, requiring an 'image.dcm' file. ```sh go run ./examples/readfile -- image.dcm ``` -------------------------------- ### Install dicom-go Source: https://github.com/thalesmms/dicom-go/blob/main/README.md Install the dicom-go library into your Go module. ```sh go get github.com/ThalesMMS/dicom-go ``` -------------------------------- ### Go API for Study Root C-FIND Query Source: https://github.com/thalesmms/dicom-go/blob/main/README.md Example Go code to establish a DICOM UL association and perform a Study Root C-FIND query. Requires context, association details, and query parameters. ```go package main import ( "context" "fmt" "time" "github.com/ThalesMMS/dicom-go/dictionary/std" "github.com/ThalesMMS/dicom-go/net/dimse" "github.com/ThalesMMS/dicom-go/net/ul" "github.com/ThalesMMS/dicom-go/object" "github.com/ThalesMMS/dicom-go/transfer" ) func main() { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() assoc, err := ul.Dial("127.0.0.1:11112", ul.DialOptions{ Context: ctx, CallingAETitle: "CLIENT_AE", CalledAETitle: "PACS_AE", Contexts: []ul.PresentationContext{ dimse.StudyRootFindPresentationContext(), }, }) if err != nil { panic(err) } defer assoc.Close() pc, err := dimse.AcceptedContextForSOPClass(assoc, dimse.StudyRootFindSOPClassUID) if err != nil { panic(err) } identifierElements, err := dimse.BuildStudyRootStudyFindKeys(map[string]string{ "PatientID": "12345", "StudyDate": "20240101", "StudyInstanceUID": "", // return key "PatientName": "", // return key (if supported by SCP) }) if err != nil { panic(err) } identifier := object.FromElements(identifierElements, std.Dictionary) identifierSyntax := transfer.ImplicitVRLittleEndian if pc.TransferSyntaxUID != "" { identifierSyntax = transfer.Syntax{UID: pc.TransferSyntaxUID} } results, errs := dimse.Find(ctx, assoc, pc.ID, dimse.CFindRequest{ AffectedSOPClassUID: dimse.StudyRootFindSOPClassUID, MessageID: 1, }, identifier, identifierSyntax) for r := range results { if r.Identifier != nil { fmt.Println(r.Identifier.Elements()) } } if err := <-errs; err != nil { panic(err) } _ = assoc.Release(ctx) } ``` -------------------------------- ### Define and Use Private DICOM Dictionary Source: https://github.com/thalesmms/dicom-go/blob/main/README.md Composes a private dictionary overlay to resolve custom DICOM tags, falling back to standard dictionary for unknown tags. This example defines a private tag with VR LO. ```go type privateDictionary struct { byTag map[core.Tag]dictionary.Entry } func (d privateDictionary) ByTag(tag core.Tag) (dictionary.Entry, bool) { entry, ok := d.byTag[tag] return entry, ok } func (d privateDictionary) ByKeyword(string) (dictionary.Entry, bool) { return dictionary.Entry{}, false } private := privateDictionary{byTag: map[core.Tag]dictionary.Entry{ core.NewTag(0x0011, 0x1001): {Tag: core.NewTag(0x0011, 0x1001), VR: core.VRLO}, }} dict := dictionary.Chain{private, std.Dictionary} file, err := object.OpenFileWithOptions("implicit.dcm", object.ReadFileOptions{ Dictionary: dict, }) ``` -------------------------------- ### Run JPEG-LS Adapter Prototype Source: https://github.com/thalesmms/dicom-go/blob/main/examples/codec-adapters/jpegls/README.md Execute the prototype tests for the JPEG-LS adapter. ```shell go test ./... ``` -------------------------------- ### Run Static Analysis Source: https://github.com/thalesmms/dicom-go/blob/main/CONTRIBUTING.md Perform static analysis using `make vet` to catch potential errors and ensure code quality. No issues should be reported before opening a pull request. ```sh go vet ./... ``` ```sh make vet ``` -------------------------------- ### Run Tests Source: https://github.com/thalesmms/dicom-go/blob/main/CONTRIBUTING.md Execute all project tests using `make test` to ensure code correctness. All tests must pass before submitting a pull request. ```sh go test ./... ``` ```sh make test ``` -------------------------------- ### Run Standardized Make Targets Source: https://github.com/thalesmms/dicom-go/blob/main/CONTRIBUTING.md Execute common development tasks like formatting, linting, testing, and building using `make` targets. `make check` is the default pre-PR workflow. ```sh make fmt make vet make test make build make check ``` -------------------------------- ### Check Formatting Source: https://github.com/thalesmms/dicom-go/blob/main/CONTRIBUTING.md Verify code formatting using `make fmt-check` to ensure consistency with project standards before submitting a pull request. Alternatively, `gofmt -w .` can be used directly. ```sh make fmt-check ``` ```sh gofmt -w . ``` -------------------------------- ### Configure File Reading with Inline Value Bytes Threshold Source: https://github.com/thalesmms/dicom-go/blob/main/README.md Configure file reading options to keep small values inline while skipping large buffers like Pixel Data. This is useful for streaming large values and deferred pixel data. ```go file, err := object.OpenFileWithOptions("image.dcm", object.ReadFileOptions{ // Keep small values inline, but skip large buffers like Pixel Data. InlineValueBytesThreshold: 1 << 20, // 1 MiB }) if err != nil { panic(err) } ``` -------------------------------- ### Open DICOM File (Default) Source: https://github.com/thalesmms/dicom-go/blob/main/README.md Opens a DICOM Part 10 file using the default reader. ```go file, err := dicom.OpenFile("image.dcm") if err != nil { panic(err) } ``` -------------------------------- ### Regenerate Standard Dictionary Source: https://github.com/thalesmms/dicom-go/blob/main/README.md Execute this command to regenerate the standard dictionary for the dicom-go library. ```sh go generate ./dictionary/std ``` -------------------------------- ### Stream Raw Pixel Data Bytes Source: https://github.com/thalesmms/dicom-go/blob/main/README.md Stream raw Pixel Data bytes for defined-length, native/uncompressed Pixel Data to an output file. This avoids materializing the entire Pixel Data into memory. ```go out, err := os.Create("pixeldata.bin") if err != nil { panic(err) } defer out.Close() n, err := file.Dataset.CopyValueTo(core.NewTag(0x7FE0, 0x0010), out) if err != nil { panic(err) } _ = n ``` -------------------------------- ### Open DICOM File with Limits Source: https://github.com/thalesmms/dicom-go/blob/main/README.md Opens a DICOM Part 10 file with specified limits on element and total bytes to prevent excessive memory usage. ```go limitedFile, err := object.OpenFileWithOptions("image.dcm", object.ReadFileOptions{ MaxElementBytes: 16 << 20, MaxTotalBytes: 128 << 20, }) if err != nil { panic(err) } _ = limitedFile ``` -------------------------------- ### DICOM Store SCP/SCU Operations Source: https://github.com/thalesmms/dicom-go/blob/main/README.md Set up a storescp to receive DICOM files or use storescu to send a DICOM file to a specified address and port. ```sh go run ./cmd/storescp -- -address 127.0.0.1:11112 -output ./received ``` ```sh go run ./cmd/storescu -- 127.0.0.1:11112 image.dcm ``` -------------------------------- ### DICOM Echo SCP/SCU Verification Source: https://github.com/thalesmms/dicom-go/blob/main/README.md Run echo SCP for verification on a specific port or echo SCU to connect to a host and port. ```sh go run ./cmd/echoscp -- -port 11112 -single ``` ```sh go run ./cmd/echoscu -- -host 127.0.0.1 -port 11112 ``` -------------------------------- ### DICOM Study Root C-MOVE Retrieve Source: https://github.com/thalesmms/dicom-go/blob/main/README.md Initiate a Study Root C-MOVE operation to a remote Query/Retrieve SCP. Requires remote host/port, AE titles, move destination AE title, and study UID. ```sh # Issue a Study Root C-MOVE to a remote QR SCP (e.g. Orthanc) go run ./cmd/dicom-go-retrieve -- \ -remote 127.0.0.1:4242 \ -calling-aet DICOMGO \ -called-aet ORTHANC \ -move-destination DICOMSTORE \ -study-uid 1.2.840.... ``` -------------------------------- ### Register Codecs and Extract Encapsulated Pixel Data Source: https://github.com/thalesmms/dicom-go/blob/main/README.md Register JPEG and RLE codecs to handle encapsulated transfer syntaxes. This allows for the extraction and decoding of pixel data from various compressed formats. ```go if err := jpegcodec.RegisterDefault(); err != nil { panic(err) } if err := rle.RegisterDefault(); err != nil { panic(err) } pixels, err := pixeldata.Extract(file.Dataset) if err != nil { panic(err) } frames, err := pixeldata.DecodeFrames(file.TransferSyntax.UID, pixels, file.Dataset) if err != nil { panic(err) } _ = frames ``` -------------------------------- ### Inspect DICOM Files with dcmdump Source: https://github.com/thalesmms/dicom-go/blob/main/README.md Use dcmdump to inspect DICOM files. Options include showing offsets and outputting in JSON format. ```sh go run ./cmd/dcmdump image.dcm ``` ```sh go run ./cmd/dcmdump -show-offsets image.dcm ``` ```sh go run ./cmd/dcmdump -json image.dcm ``` -------------------------------- ### Convert DICOM to JSON and Back Source: https://github.com/thalesmms/dicom-go/blob/main/README.md Marshals a DICOM dataset to a pretty-printed JSON format and then unmarshals it back, using a provided dictionary for resolution. ```go data, err := dicomjson.MarshalPretty(file.Dataset) if err != nil { panic(err) } obj, err := dicomjson.Unmarshal(data, std.Dictionary) if err != nil { panic(err) } _ = obj ``` -------------------------------- ### DICOM Study Root C-FIND SCU Query Source: https://github.com/thalesmms/dicom-go/blob/main/README.md Perform a Study Root C-FIND query to a PACS AE. Specify host, port, called/calling AE titles, level, and query keys. ```sh go run ./cmd/findscu -- -host 127.0.0.1 -port 11112 -called PACS_AE -calling CLIENT_AE -level study \ -k PatientID=12345 -k StudyDate=20240101 ``` -------------------------------- ### Read Patient Name from DICOM File Source: https://github.com/thalesmms/dicom-go/blob/main/README.md Opens a DICOM Part 10 file and extracts the Patient Name (0x0010, 0x0010). Requires the 'image.dcm' file to exist. ```go package main import ( "fmt" "github.com/ThalesMMS/dicom-go" "github.com/ThalesMMS/dicom-go/core" ) func main() { file, err := dicom.OpenFile("image.dcm") if err != nil { panic(err) } name, ok := file.GetString(core.NewTag(0x0010, 0x0010)) if ok { fmt.Println(name) } } ``` -------------------------------- ### Write DICOM File Source: https://github.com/thalesmms/dicom-go/blob/main/README.md Writes a modified or newly created DICOM object to a file. Ensure the output file is properly closed. ```go out, err := os.Create("out.dcm") if err != nil { panic(err) } defer out.Close() if err := object.WriteFile(out, file); err != nil { panic(err) } ``` -------------------------------- ### Extract Native Uncompressed Frames Source: https://github.com/thalesmms/dicom-go/blob/main/README.md Use this function to extract native uncompressed frames directly from a DICOM file's dataset. ```go frames, err := pixeldata.ExtractNativeFrames(file.Dataset) ``` -------------------------------- ### Validate DICOM SOP Class Attributes Source: https://github.com/thalesmms/dicom-go/blob/main/README.md Applies SOP Class-specific validation rules to a DICOM dataset, checking for the presence of required attributes like PatientID for CT Image Storage. ```go rule := object.RequiredAttributeRule{ SOPClassUID: "1.2.840.10008.5.1.4.1.1.2", // CT Image Storage Attributes: []object.RequiredAttribute{ {Tag: core.NewTag(0x0010, 0x0020), Keyword: "PatientID"}, }, } err := file.Dataset.ValidateSOPClass(object.ValidationOptions{ Hooks: []object.SOPClassValidationHook{rule}, }) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.