Skip to content

Commit

Permalink
[Rewritten Prototype]: Update draft sanity check program (#74)
Browse files Browse the repository at this point in the history
Minor updates to the sanity check program, major updates/cleanup to come before launch.

In particular this updates the program to write out multiple encapsulated frames if they exist.
  • Loading branch information
suyashkumar committed Nov 2, 2020
1 parent 2d5912a commit 201c884
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions cmd/dicomtest/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Really basic sanity check program
package main

import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
Expand All @@ -21,29 +23,40 @@ func main() {
if len(*filepath) > 0 {
log.Println("start")
f, err := os.Open(*filepath)
defer f.Close()
if err != nil {
log.Println("err")
return
}
info, err := f.Stat()
if err != nil {
log.Println("err reading", err)
return
}
p, err := dicom.NewParser(f, info.Size())
if err != nil {
log.Println("err creating parser", err)
return
}
ds, err := p.Parse()
if err != nil {
log.Println("err parsing", err)
return
}
log.Println(len(ds.Elements))

for _, elem := range ds.Elements {
if elem.Tag != tag.PixelData {
log.Println(elem.Tag)
log.Println(elem.ValueLength)
log.Println(elem.Value)
} else {
imageInfo := elem.Value.GetValue().(dicom.PixelDataInfo)
err := ioutil.WriteFile("image_00.jpg", imageInfo.Frames[0].EncapsulatedData.Data, 0644)
if err != nil {
log.Println(err)
for i, frame := range imageInfo.Frames {
err := ioutil.WriteFile(fmt.Sprintf("image_%d.jpg", i), frame.EncapsulatedData.Data,
0644)
if err != nil {
log.Println(err)
}
}
}
}
Expand Down

0 comments on commit 201c884

Please sign in to comment.