[Neuroimaging] Resetting gifti labeltable

Emma Robinson emma.robinson01 at gmail.com
Fri Jul 26 05:48:28 EDT 2019


Got it thanks.

As it turns out, that was almost what I had (without the fourth number -
alpha). But I had another issue, which is that I hadn't cast the data as
int32.

Cheers.

Emma

On Fri, 26 Jul 2019 at 09:42, Michiel Cottaar <michiel.cottaar at ndcn.ox.ac.uk>
wrote:

> Something like the following should work for that:
> color_map = {0: ('red', (1., 0., 0., 1.)), 1: ('green', (0., 1., 0., 1.)),
> 2: ('blue', (0., 0., 1., 1.))}
> This will make all the zeros in the GIFTI file to be plotted as red, all
> the ones as green, and all the two's as blue.
>
> So within the loop, the variable `value` should be the integer value that
> you use to mark the ROI in the array. The variable `text` should be the ROI
> label and `rgba` should be a sequence of four numbers (red, green, blue,
> and alpha). You can set the alpha to zero for any labels you don't want to
> plot.
>
> Good luck,
>
> Michiel
>
> On 26 Jul 2019, at 08:56, Emma Robinson <emma.robinson01 at gmail.com> wrote:
>
> Thanks!
>
> Could you possibly show me how you create your colour_map dictionary? What
> I've tried so far has not been working.
>
> Emma
>
>
>
> On Tue, 23 Jul 2019 at 13:50, Michiel Cottaar <
> michiel.cottaar at ndcn.ox.ac.uk> wrote:
>
>> Hi Emma,
>>
>> It's a bit awkward, but the way I do this is to create an empty
>> GiftiLabelTable and then append individual GiftiLabels to it. Note that the
>> constructor of the GiftiLabel only expects the integer index and the RGBA
>> colour, but you should also set a label (when serialising the
>> GiftiLabelTable expects all labels to have such a label).
>>
>> So my code looks like:
>>
>> labeltable = gifti.GiftiLabelTable()
>> for value, (text, rgba) in color_map.items():
>>     labeltable.labels.append(gifti.GiftiLabel(value, *rgba))
>>     labeltable.labels[-1].label = str(text)
>>
>> where color_map is a dictonary mapping from the indices to a tuple with
>> the label and the RGBA value.
>>
>> Cheers,
>>
>> Michiel
>>
>> On 23 Jul 2019, at 12:30, Emma Robinson <emma.robinson01 at gmail.com>
>> wrote:
>>
>> Hi
>>
>> I am trying to create a new gifti label file using an existing one as
>> template. How do I change the label table? I've create a new label
>> dictionary as variable 'labeldict' but I cannot create a  GiftiLabelTable
>> instance from this see:
>>
>> nibabel.gifti.GiftiLabelTable(labeldict)
>> Traceback (most recent call last):
>>
>>   File "<ipython-input-34-d948ed166e6e>", line 1, in <module>
>>     nibabel.gifti.GiftiLabelTable(labeldict)
>>
>> TypeError: __init__() takes 1 positional argument but 2 were given
>>
>> Could someone tell me how it is supposed to be done?
>>
>> Thanks
>>
>> Emma
>> _______________________________________________
>> Neuroimaging mailing list
>> Neuroimaging at python.org
>> https://mail.python.org/mailman/listinfo/neuroimaging
>>
>>
>> _______________________________________________
>> Neuroimaging mailing list
>> Neuroimaging at python.org
>> https://mail.python.org/mailman/listinfo/neuroimaging
>>
> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging
>
>
> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20190726/5f43fc1b/attachment.html>


More information about the Neuroimaging mailing list