cosanlab / nltools

Python toolbox for analyzing imaging data
https://nltools.org
MIT License
122 stars 44 forks source link

Expand/collapse mask sometimes creates extra mask values #126

Open ejolly opened 7 years ago

ejolly commented 7 years ago

using collapse_mask() on the attached nifti file (which contains 16 mask images) adds more unique mask values than should exist (26, where there should be 16). Subsequently calling expand_mask() therefore expands out to a Brain_Data instance with shape[0] == 26 instead of 16.

Using the following file as fName: compiled_masks.nii.gz

Example code:

dat = Brain_Data(fName)
collapsed = collapse_mask(dat)
len(np.unique(collapse.data) # this is wrong, too many
expanded = expand_mask(collapsed)
expanded.shape()[0] # this is wrong, too many

The following doesn't seem to help either:

#Assure masks are binary
newMasks = dat.empty()
for ma in dat:
    newMasks = newMasks.append(ma.threshold(0,binarize=True))
collapsed = collapse_mask(newMasks)
expanded = expand_masks(collapsed)
expanded.shape()[0] #still wrong
ljchang commented 7 years ago

This is probably a consequence of overlapping masks. We could add an option to automatically remove overlapping areas, but not sure if this is a good idea. Maybe we should just note this in the documentation.