overlays
Overlay planes (groups 6000–601E) as structs: unpack the bit plane, merge planes back, and keep graphics and regions of interest next to them.
import "github.com/amrshadid/go-dicom/overlays" · pkg.go.dev
When to use it
When you need the mask of an overlay as a grid of booleans, or want to build
overlay data from one. The package does not read a data set: you copy Overlay
Rows, Columns, Type and Data from group 60xx into an OverlayGroup yourself,
as the example does.
Key types and functions
| Name | What it is for |
|---|---|
OverlayGroup | One overlay: group, rows, columns, type, bit position, data, label. |
NewOverlayManager, OverlayManager | Overlays by group number. |
OverlayManager.AddOverlay, OverlayManager.GetOverlay | Add one; look one up. |
OverlayManager.ExtractBitPlane | The packed bits as [row][column]bool. |
OverlayManager.MergeBitPlanes | Pack planes back into bytes. |
OverlayManager.GetOverlayBounds, OverlayManager.ValidateOverlay | The marked area; a consistency check. |
OverlayROI, GetROIArea, GetROIPerimeter | Regions of interest kept by group. |
OverlayGraphics, Point | Graphics kept by group. |
Example
// Copy the first overlay plane of a file into an OverlayManager and count
// the pixels it marks.
package main
import (
"encoding/binary"
"fmt"
"log"
"os"
"github.com/amrshadid/go-dicom/dataset"
"github.com/amrshadid/go-dicom/filebase"
"github.com/amrshadid/go-dicom/filereader"
"github.com/amrshadid/go-dicom/overlays"
"github.com/amrshadid/go-dicom/tag"
)
func us(ds *dataset.Dataset, t tag.Tag) int {
if e, ok := ds.Get(t); ok {
if b, ok := e.Bytes(); ok && len(b) >= 2 {
return int(binary.LittleEndian.Uint16(b))
}
}
return 0
}
func main() {
f, err := os.Open(os.Args[1])
if err != nil {
log.Fatal(err)
}
defer f.Close()
df, err := filereader.ReadDICOMFile(filebase.NewFileReader(f))
if err != nil {
log.Fatal(err)
}
ds := df.GetDataset()
// The package does not read data sets: the overlay's attributes are
// copied from group 6000 by hand.
group := &overlays.OverlayGroup{
GroupNumber: 0x6000,
OverlayRows: us(ds, tag.New(0x6000, 0x0010)),
OverlayColumns: us(ds, tag.New(0x6000, 0x0011)),
OverlayData: ds.GetValue(tag.New(0x6000, 0x3000)),
OverlayType: "G",
OverlayBitsAllocated: 1,
}
om := overlays.NewOverlayManager()
if err := om.AddOverlay(group); err != nil {
log.Fatal(err)
}
plane, err := om.ExtractBitPlane(0x6000, 0)
if err != nil {
log.Fatal(err)
}
marked := 0
for _, row := range plane {
for _, on := range row {
if on {
marked++
}
}
}
fmt.Printf("%dx%d overlay, %d pixels marked\n", group.OverlayColumns, group.OverlayRows, marked)
}On pydicom's examples_overlay.dcm it prints
484x300 overlay, 222 pixels marked, the same count pydicom gives.
Notes
- It works on the Overlay Data (60xx,3000) bytes you give it; it does not look in Pixel Data for overlays stored in its unused high bits.
dataset.RenderFramedoes not draw overlays.- How validate checks overlay groups against the IOD is in CONFORMANCE.md §8.7.
Note
This is a thin, standalone package: no other package in the module uses it.
See also
network
The DICOM upper layer protocol and DIMSE services: an SCU that associates and sends C-ECHO, C-STORE, C-FIND, C-MOVE, C-GET and the N- services, and an SCP that accepts associations and passes each request to a handler.
pixels
Native pixel bytes with the attributes that describe them, and reading single samples and simple statistics (minimum, maximum, mean, median) from them.