Skip to content

Commit

Permalink
Merge pull request #20 from okieraised/dev
Browse files Browse the repository at this point in the history
Skip zero-filled RLE segments
  • Loading branch information
okieraised authored Apr 7, 2023
2 parents 227b324 + 12d8d63 commit 9891bab
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
38 changes: 38 additions & 0 deletions annotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,41 @@ func TestSegmentation_Annotation4(t *testing.T) {
assert.NoError(err)

}

func TestSegmentation_Annotation5(t *testing.T) {
assert := assert.New(t)

filePath := "/home/tripg/Downloads/annot_import/CT_Abdo.1680080052.TSK-7.seg.nii.gz"
rd, err := NewNiiReader(WithReadImageFile(filePath), WithReadRetainHeader(true))
assert.NoError(err)
err = rd.Parse()
assert.NoError(err)

voxels := rd.GetNiiData().GetVoxels()
voxels.FlipX()
voxels.FlipY()
voxels.FlipZ()
err = rd.GetNiiData().SetVoxelToRawVolume(voxels)
assert.NoError(err)

segments, err := rd.GetNiiData().GetVoxels().ImportAsRLE()
assert.NoError(err)

for _, segment := range segments {
fmt.Println(segment.EncodedSeg)
}

//voxels, err = rd.GetNiiData().GetVoxels().ExportSingleFromRLE(segments)
//assert.NoError(err)
//
//err = rd.GetNiiData().SetVoxelToRawVolume(voxels)
//assert.NoError(err)
//
//writer, err := NewNiiWriter("/home/tripg/Downloads/reexport.nii.gz",
// WithWriteNIfTIData(rd.GetNiiData()),
// WithWriteCompression(true),
//)
//err = writer.WriteToFile()
//assert.NoError(err)

}
5 changes: 5 additions & 0 deletions pkg/nifti/voxel.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ func (v *Voxels) ImportAsRLE() ([]SegmentRLE, error) {
return nil, err
}

// Skip zero-only segment since they do not contain any segmentation
if len(encoded) == 1 && encoded[0] == float64(v.dimX*v.dimY) {
continue
}

encodedSegment := SegmentRLE{
EncodedSeg: encoded,
DecodedSeg: sliceData,
Expand Down

0 comments on commit 9891bab

Please sign in to comment.