-
-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathread.go
More file actions
29 lines (27 loc) · 1.16 KB
/
read.go
File metadata and controls
29 lines (27 loc) · 1.16 KB
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
// Package inplace contains code for handling UnprocessedValueData
package inplace
// ReadUnprocessedValueData read the value of Dicom image directly
// from the byte array of PixelData.UnprocessedValueData with given frame ID.
// This ease the memory usage of reading DICOM image.
func ReadUnprocessedValueData(info *PixelDataMetadata, unprocessedValueData []byte, frameIndex int) ([][]int, error) {
pixelsPerFrame := info.Rows * info.Cols
bytesAllocated := info.BitsAllocated / 8
offset := frameIndex * pixelsPerFrame * info.SamplesPerPixel * bytesAllocated
samplesPerPixel := info.SamplesPerPixel
re := make([][]int, pixelsPerFrame)
for i := 0; i < pixelsPerFrame; i++ {
re[i] = make([]int, samplesPerPixel)
for j := 0; j < samplesPerPixel; j++ {
pointOffset := offset + i*info.SamplesPerPixel*bytesAllocated + j*bytesAllocated
switch bytesAllocated {
case 1:
re[i][j] = int(unprocessedValueData[pointOffset])
case 2:
re[i][j] = int(info.Bo.Uint16(unprocessedValueData[pointOffset : pointOffset+bytesAllocated]))
case 4:
re[i][j] = int(info.Bo.Uint32(unprocessedValueData[pointOffset : pointOffset+bytesAllocated]))
}
}
}
return re, nil
}