question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Non integer labels in Colin27 2008 version

See original GitHub issue

🐛Bug

Class labels in Colin27 dataset, version 2008, are not integer values.

To reproduce

from torchio.datasets import Colin27
colin = Colin27(2008)
label_values = colin['cls']['data'].unique()
print(label_values)

>>> tensor([ 0.0000,  0.9882,  2.0235,  3.0118,  4.0000,  4.9882,  6.0235,  7.0118,
         8.9882, 10.0235, 11.0118, 12.0000])

Expected behavior

Label encoding map should only contain integer values.

TorchIO version

0.17.7

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
fepegarcommented, Jul 9, 2020

I removed the slope from the file

In [7]: with open('colin27_cls_tal_hires.nii', 'rb+') as f:
   ...:     f.seek(116)  # address of intercept, which I know is 0
   ...:     data = f.read(4)  # stored in float32 so 4 bytes
   ...:     f.seek(112)  # address of slope
   ...:     f.write(data)  # actually this should have been 1, but it looks like nibabel uses a 1 if it finds a 0
   ...:

and the values are now

In [14]: np.unique(lm)
Out[14]:
array([  0,  21,  43,  64,  85, 106, 128, 149, 191, 213, 234, 255],
      dtype=int16)

Indeed to get 12 from 255 you need to multiply by 12/255 = 0.047058823529411764, which is the intercept stored in the header. However, 234 * 0.047058823529411764 = 11.0118. It looks like, for some reason, someone decided to store the labels from 0 to 255 for some reason, and adding a slope. Maybe this worked with the software they use at the MNI because the labels are rounded after reading.

I think the best for now is just rounding the values ourselves when reading the CLS image.

1reaction
fepegarcommented, Jul 9, 2020

Thanks for reporting, @GFabien. This is weird, and I don’t think there’s much we can do about this. I tried reading the image with ITK and results are the same. I checked the intercept and slope values in the NIfTI header and I found nothing interesting:

scl_slope       : nan
scl_inter       : nan

I’ve been googling with no success. I think that the only solution for now is to round the data in the Colin27 class of the torchio.datasets.mni.colin module.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Colin 27 2008 | McConnell Brain Imaging Centre
Colin 27 Average Brain, Stereotaxic Registration Model, high-resolution version 2008. Overview. The anatomical phantom is derived from T1, T2, PD-weighted ...
Read more >
Voxel label data warped to fit the Colin27 MRI average: the 3D...
Each region was assigned an integer label (totaling 105 regions). ... structures from the voxel label atlas was completed using a modified version...
Read more >
torchio.transforms.preprocessing.label.remove_labels
Args: labels: A sequence of label integers that will be removed. background_label: integer ... Colin27(2008) label_map = colin.cls colin.remove_image('t2') ...
Read more >
The SRI24 multichannel atlas of normal adult human brain ...
This article describes the SRI24 atlas, a new standard reference system of normal human brain anatomy, that was created using template-free ...
Read more >
The Brain Atlas Concordance Problem: Quantitative ... - PLOS
Currently, however, no widely accepted standards exist for partitioning the cortex and subcortical structures, or for assigning labels to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found