miykael / atlasreader

Python interface for generating coordinate tables and region labels from statistical MRI images
BSD 3-Clause "New" or "Revised" License
90 stars 31 forks source link

Using mask as input image? #113

Closed landge closed 4 years ago

landge commented 4 years ago

Hi,

I was wondering if it´s somehow possible to supply a mask as an input image? We have stroke-lesion masks and would like to get the location-labels back! Could that be done with atlasreader?

Thanks!

miykael commented 4 years ago

Hello,

Yes, that shouldn't be an issue. However, atlasreader will try to find the peak in your masks, which might cause the output figures to be wrongly centred and the peak tables will most certainly be useless. But the cluster tables should provide you the information that you're interested in, location and extent of the lesions.

Cheers, Michael

landge commented 4 years ago

Oh, great. When I try to run create_output with a mask I get the following error:

lib/python3.8/site-packages/nilearn/plotting/displays.py:780: UserWarning: empty mask get_mask_bounds(new_img_like(img, not_mask, affine))

But I can´t even where this function call comes from, as I can´t find it in atlasreader.py. Do you have any ideas where this error comes from?

Thanks, Till

landge commented 4 years ago

I just realized that create_output() returns None and writes the results directly to files. The csv-output seems to be correct, but the plots don´t contain any masks. So it seems that the masks that are created from the supplied input-mask (input file in my case) are empty!

miykael commented 4 years ago

The error was coming from the plotting function from nilearn, which atlasreader is heavily based on. Interesting, also about the fact that your supplied input-masks are empty. I think the input is masked according to the MNI template brain, i.e. if your data would still be in the subject space then atlasreader might not be able to find any overlap in voxel location and therefore set everything to zero.

landge commented 4 years ago

Two small changes that apparently solved the issue:

Somewhere in atlasreader pandas DataFrame.get_values() is used, which is deprecated since pandas version 0.25.0. So I downgraded to 0.25 (which requires python <= 3.7).

I didn´t test if this change alone resolved the issue but instead continued to replace the 1s in the mask with random integer values >=1. Thought this might affect the calculation of the cluster masks..... Maybe it`s easier to apply the mask to the DWI-image and use the result as an input.

After these changes, the masks were correctly plotted. It needs a little more testing to see if both changes were necessary.

miykael commented 4 years ago

Thank you for the input. I finally came around and updated atlasreader with respect to the new DataFrame.values setup in Pandas 1.0 (as well as to the newer version of nibabel).

And good to know, that the workaround with the random integer numbers >=1 seemed to have worked!