forked from suyashkumar/dicom
/
native.go
36 lines (30 loc) · 1.03 KB
/
native.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package frame
import (
"image"
"image/color"
)
// NativeFrame represents a native image frame
type NativeFrame struct {
// Data is a slice of pixels, where each pixel can have multiple values
Data [][]int
Rows int
Cols int
BitsPerSample int
}
func (n *NativeFrame) IsEncapsulated() bool { return false }
func (n *NativeFrame) GetNativeFrame() (*NativeFrame, error) {
return n, nil
}
func (n *NativeFrame) GetEncapsulatedFrame() (*EncapsulatedFrame, error) {
return nil, ErrorFrameTypeNotPresent
}
// 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 (n *NativeFrame) GetImage() (image.Image, error) {
i := image.NewGray16(image.Rect(0, 0, n.Cols, n.Rows))
for j := 0; j < len(n.Data); j++ {
i.SetGray16(j%n.Cols, j/n.Rows, color.Gray16{Y: uint16(n.Data[j][0])}) // for now, assume we're not overflowing uint16, assume gray image
}
return i, nil
}