frame

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: MIT Imports: 7 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedSamplesPerPixel = errors.New("unsupported samples per pixel")
View Source
var ErrorFrameTypeNotPresent = errors.New("the frame type you requested is not present in this CommonFrame")

ErrorFrameTypeNotPresent is returned when the user asked to Get an underlying GetNativeFrame or GetEncapsulatedFrame that is not contained in that particular CommonFrame.

Functions

This section is empty.

Types

type CommonFrame

type CommonFrame interface {
	// GetImage gets this frame as an image.Image. Beware that the underlying frame may perform
	// some default rendering and conversions. Operate on the raw NativeFrame or EncapsulatedFrame
	// if you need to do some custom rendering work or want the Data from the dicom.
	GetImage() (image.Image, error)
	// IsEncapsulated indicates if the underlying Frame is an EncapsulatedFrame.
	IsEncapsulated() bool
	// GetNativeFrame attempts to get the underlying NativeFrame (or returns an error)
	GetNativeFrame() (INativeFrame, error)
	// GetEncapsulatedFrame attempts to get the underlying EncapsulatedFrame (or returns an error)
	GetEncapsulatedFrame() (*EncapsulatedFrame, error)
}

CommonFrame represents a harmonized DICOM Frame with a consistent interface (harmonized across Native and Encapsulated frames), however users still have the ability to fetch underlying Native or Encapsulated frame constructs.

type EncapsulatedFrame

type EncapsulatedFrame struct {
	// Data is a collection of bytes representing a JPEG encoded image frame
	Data []byte
}

EncapsulatedFrame represents an encapsulated image frame

func (*EncapsulatedFrame) Equals added in v1.0.7

func (e *EncapsulatedFrame) Equals(target *EncapsulatedFrame) bool

Equals returns true if this frame equals the provided target frame, otherwise false.

func (*EncapsulatedFrame) GetEncapsulatedFrame

func (e *EncapsulatedFrame) GetEncapsulatedFrame() (*EncapsulatedFrame, error)

GetEncapsulatedFrame returns an EncapsulatedFrame from this frame.

func (*EncapsulatedFrame) GetImage

func (e *EncapsulatedFrame) GetImage() (image.Image, error)

GetImage returns a Go image.Image from the underlying frame.

func (*EncapsulatedFrame) GetNativeFrame

func (e *EncapsulatedFrame) GetNativeFrame() (INativeFrame, error)

GetNativeFrame returns ErrorFrameTypeNotPresent, because this struct does not hold a NativeFrame.

func (*EncapsulatedFrame) IsEncapsulated

func (e *EncapsulatedFrame) IsEncapsulated() bool

IsEncapsulated indicates if the frame is encapsulated or not.

type Frame

type Frame struct {
	// Encapsulated indicates whether the underlying frame is encapsulated or
	// not.
	Encapsulated bool
	// EncapsulatedData holds the encapsulated Data for this frame if
	// Encapsulated is set to true.
	EncapsulatedData EncapsulatedFrame
	// NativeData holds the native Data for this frame if Encapsulated is set
	// to false.
	NativeData INativeFrame
}

Frame wraps a single encapsulated or native image frame TODO: deprecate this old intermediate representation in favor of CommonFrame once happy and solid with API.

func (*Frame) Equals added in v1.0.7

func (f *Frame) Equals(target *Frame) bool

Equals returns true if this frame equals the provided target frame, otherwise false.

func (*Frame) GetEncapsulatedFrame

func (f *Frame) GetEncapsulatedFrame() (*EncapsulatedFrame, error)

GetEncapsulatedFrame returns an EncapsulatedFrame from this frame. If the underlying frame is not an EncapsulatedFrame, ErrorFrameTypeNotPresent will be returned.

func (*Frame) GetImage

func (f *Frame) GetImage() (image.Image, error)

GetImage returns a Go image.Image from the underlying frame, regardless of the frame type.

func (*Frame) GetNativeFrame

func (f *Frame) GetNativeFrame() (INativeFrame, error)

GetNativeFrame returns a NativeFrame from this frame. If the underlying frame is not a NativeFrame, ErrorFrameTypeNotPresent will be returned.

func (*Frame) IsEncapsulated

func (f *Frame) IsEncapsulated() bool

IsEncapsulated indicates if the frame is encapsulated or not.

type INativeFrame added in v1.1.0

type INativeFrame interface {
	// Rows returns the number of rows in this frame (which is the max y
	// dimension).
	Rows() int
	// Cols returns the number of columns in this frame (which is the max x
	// dimension).
	Cols() int
	// SamplesPerPixel returns the number of samples per pixel in this frame.
	SamplesPerPixel() int
	// BitsPerSample returns the bits per sample in this frame.
	BitsPerSample() int
	// GetPixel returns the samples (as a slice) for the pixel at (x, y).
	// The coordinate system of the image starts with (0, 0) in the upper left
	// corner of the image, with X increasing to the right, and Y increasing
	// down:
	//
	//  0 -------▶ X
	//  |
	//  |
	//  ▼
	//  Y
	GetPixel(x, y int) ([]int, error)
	// RawDataSlice will return the underlying data slice, which will be of type
	// []I. Based on BitsPerSample, you can anticipate what type of slice you'll
	// get, and type assert as needed:
	//  BitsPerSample    Slice
	//  8                []uint8
	//  16               []uint16
	//  32               []uint32
	RawDataSlice() any
	// Equals returns true if this INativeFrame exactly equals the provided
	// INativeFrame. This checks every pixel value, so may be expensive.
	// In the future we may compute a one time hash during construction to make
	// this less expensive in the future if called multiple time.
	Equals(frame INativeFrame) bool
	CommonFrame
}

INativeFrame is an interface representation of NativeFrame[I]'s capabilities, and offers a way to use a NativeFrame _without_ requiring propagation of type parameters. This allows for some more ergonomic signatures, though NativeFrame[I] can be used directly as well for those who prefer it.

type NativeFrame

type NativeFrame[I constraints.Integer] struct {
	// RawData is a slice of pixel values. For each pixel, each sample for the
	// pixel is unrolled per pixel. For example, consider 2 pixels that have 3
	// samples per Pixel: [[1,2,3], [4,5,6]]. This would be unrolled like
	// [1,2,3,4,5,6]. The pixels themselves are arranged in row order, so the
	// first row of pixels would be unrolled in order, followed by the next row,
	// and so on in this flattened array.
	// A flattened slice is used instead of a nested 2D slice because there is
	// significant overhead to creating nested slices in Go discussed here:
	// https://github.com/suyashkumar/dicom/issues/161#issuecomment-2143627792.
	RawData                 []I
	InternalSamplesPerPixel int
	InternalRows            int
	InternalCols            int
	InternalBitsPerSample   int
}

NativeFrame represents a native image frame

func NewNativeFrame added in v1.1.0

func NewNativeFrame[I constraints.Integer](bitsPerSample, rows, cols, pixelsPerFrame, samplesPerPixel int) *NativeFrame[I]

NewNativeFrame creates a new NativeFrame[I] given the input parameters. It initializes the NativeFrame's internal RawData slice based on pixelsPerFrame and samplesPerPixel.

func (*NativeFrame[I]) BitsPerSample

func (n *NativeFrame[I]) BitsPerSample() int

BitsPerSample returns the bits per sample.

func (*NativeFrame[I]) Cols

func (n *NativeFrame[I]) Cols() int

Cols returns the number of columns in this frame (which is the max x dimension).

func (*NativeFrame[I]) Equals added in v1.0.7

func (n *NativeFrame[I]) Equals(target INativeFrame) bool

Equals returns true if this frame equals the provided target frame, otherwise false. This may be expensive.

func (*NativeFrame[I]) GetEncapsulatedFrame

func (n *NativeFrame[I]) GetEncapsulatedFrame() (*EncapsulatedFrame, error)

GetEncapsulatedFrame returns ErrorFrameTypeNotPresent, because this struct does not hold encapsulated frame Data.

func (*NativeFrame[I]) GetImage

func (n *NativeFrame[I]) GetImage() (image.Image, error)

GetImage returns an image.Image representation the frame, using default processing. This default processing is basic at the moment, and does not autoscale pixel values or use window width or level info.

func (*NativeFrame[I]) GetNativeFrame

func (n *NativeFrame[I]) GetNativeFrame() (INativeFrame, error)

GetNativeFrame returns a NativeFrame from this frame. If the underlying frame is not a NativeFrame, ErrorFrameTypeNotPresent will be returned.

func (*NativeFrame[I]) GetPixel added in v1.1.0

func (n *NativeFrame[I]) GetPixel(x, y int) ([]int, error)

GetPixel returns the samples (as a slice) for the pixel at (x, y). The coordinate system of the image starts with (0, 0) in the upper left corner of the image, with X increasing to the right, and Y increasing down:

0 -------▶ X
|
|
▼
Y

func (*NativeFrame[I]) GetSample added in v1.1.0

func (n *NativeFrame[I]) GetSample(x, y, sampleIdx int) int

GetSample returns a specific sample inside a pixel at (x, y).

func (*NativeFrame[I]) IsEncapsulated

func (n *NativeFrame[I]) IsEncapsulated() bool

IsEncapsulated indicates if the frame is encapsulated or not.

func (*NativeFrame[I]) RawDataSlice added in v1.1.0

func (n *NativeFrame[I]) RawDataSlice() any

RawDataSlice will return the underlying data slice, which will be of type []I. Based on BitsPerSample, you can anticipate what type of slice you'll get, and type assert as needed:

BitsPerSample    Slice
8                []uint8
16               []uint16
32               []uint32

func (*NativeFrame[I]) Rows

func (n *NativeFrame[I]) Rows() int

Rows returns the number of rows in this frame (which is the max y dimension).

func (*NativeFrame[I]) SamplesPerPixel added in v1.1.0

func (n *NativeFrame[I]) SamplesPerPixel() int

SamplesPerPixel returns the samples per pixel.

Jump to

Keyboard shortcuts

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