Loading Two Segmentation Images Simultaneously

276 views
Skip to first unread message

Sara

unread,
Oct 4, 2023, 12:55:11 PM10/4/23
to itksnap-users
Hello,

Context
I semi-automatically segment cysts using this program. The samples that generate my lesion masks are stored for the rest of my team + future team working with this data. 

Obviously sometimes, I can't generate a mask entirely with sampling, and must manually clean up a mask after it's been generated. This means the mask generated by the samples and mask edited by me have slight differences. I'd like to easily record these differences, if possible.

Question(s)
First question: Within ITK-SNAP, is there any way to compare the voxel position (x,y,z) of each 'painted' voxel in a mask? This would be useful to compare slight differences between a sample-generated mask and a manually 'cleaned' mask not readily visible just by scrolling. I see there is a stat for total voxels in a segmentation, but this is all. 

Screenshot 2023-10-04 at 12.51.11 PM.png
Second question: If above answer is 'no', is there a way to load two segmentation images on top of one another to compare-contrast coverage discrepancies visually, by e.g. loading both layered at different colors + opacities.

Let me know if I can be more clear. 
Thank you for your help.

Rolf Heckemann

unread,
Oct 9, 2023, 4:16:36 AM10/9/23
to itksnap-users
Hi Sara

Re. your second question: one way to compare a pair of binary masks visually is to merge them into a single segmentation image. Using c3d, you could do it like this:

c3d mask-A.nii.gz -scale 2 mask-B.nii.gz -add -o sum.nii.gz

In sum.nii.gz, overlapping mask portions will have voxel values of 3, those that are foreground only in A will have values 2, and those that are foreground only in B will have values 1. To visualize it, open it as a segmentation and load a label description file with the following content:

    0     0    0    0        0  0  0    "Clear Label"
    1   255    0    0        1  1  1    "B \ A"
    2   255  255    0        1  1  1    "A \ B"
    3     0  255    0        1  1  1    "A ∩ B"

Now you can see overlap (intersection) in green, A-only as yellow, and B-only as red.

Re. your first question: to retrieve the coordinates of all discrepancies individually, the following approach works in principle (although there may be more elegant ways):

c3d sum.nii.gz -split -oo l%01d.nii.gz # Isolate the discrepancy types into separate files
c3d l1.nii.gz -comp l1-comp.nii.gz # Looking at B \ A, number the discrepancies as disconnected components
c3d l1-comp.nii.gz -split -oo l1-d%01d.nii.gz # Split the disconnected components into individual files
c3d l1-d1.nii.gz -centroid # Extract the coordinates of discrepancy #1
c3d l1-d2.nii.gz -centroid # Extract the coordinates of discrepancy #2 -- repeat this for l1-d*.nii.gz
# Repeat this procedure for l2.nii.gz

Hope this helps!

Rolf
Reply all
Reply to author
Forward
0 new messages