Format for LUTs used by labelconvert?

Hi,

I am working with neonatal data and I am doing my segmentation with the Draw-EM Segmentation Software.

The look-up table (LUT) in DrawEM is provided as a csv-file:

cat all_labels.csv
1	Hippocampus left
2	Hippocampus right
3	Amygdala left
4	Amygdala right
5	Anterior temporal lobe, medial part left GM
6	Anterior temporal lobe, medial part right GM
7	Anterior temporal lobe, lateral part left GM
8	Anterior temporal lobe, lateral part right GM
9	Gyri parahippocampalis et ambiens anterior part left GM
10	Gyri parahippocampalis et ambiens anterior part right GM
11	Superior temporal gyrus, middle part left GM
12	Superior temporal gyrus, middle part right GM
13	Medial and inferior temporal gyri anterior part left GM
14	Medial and inferior temporal gyri anterior part right GM
15	Lateral occipitotemporal gyrus, gyrus fusiformis anterior part left GM
16	Lateral occipitotemporal gyrus, gyrus fusiformis anterior part right GM
17	Cerebellum left
18	Cerebellum right
19	Brainstem, spans the midline
20	Insula right GM
21	Insula left GM
22	Occipital lobe right GM
23	Occipital lobe left GM
24	Gyri parahippocampalis et ambiens posterior part right GM
25	Gyri parahippocampalis et ambiens posterior part left GM
26	Lateral occipitotemporal gyrus, gyrus fusiformis posterior part right GM
27	Lateral occipitotemporal gyrus, gyrus fusiformis posterior part left GM
28	Medial and inferior temporal gyri posterior part right GM
29	Medial and inferior temporal gyri posterior part left GM
30	Superior temporal gyrus, posterior part right GM
31	Superior temporal gyrus, posterior part left GM
32	Cingulate gyrus, anterior part right GM
33	Cingulate gyrus, anterior part left GM
34	Cingulate gyrus, posterior part right GM
35	Cingulate gyrus, posterior part left GM
36	Frontal lobe right GM
37	Frontal lobe left GM
38	Parietal lobe right GM
39	Parietal lobe left GM
40	Caudate nucleus right
41	Caudate nucleus left
42	Thalamus right, high intensity part in T2
43	Thalamus left, high intensity part in T2
44	Subthalamic nucleus right
45	Subthalamic nucleus left 
46	Lentiform Nucleus right
47	Lentiform Nucleus left
48	Corpus Callosum
49	Lateral Ventricle left
50	Lateral Ventricle right
51	Anterior temporal lobe, medial part left WM
52	Anterior temporal lobe, medial part right WM
53	Anterior temporal lobe, lateral part left WM
54	Anterior temporal lobe, lateral part right WM
55	Gyri parahippocampalis et ambiens anterior part left WM
56	Gyri parahippocampalis et ambiens anterior part right WM
57	Superior temporal gyrus, middle part left WM
58	Superior temporal gyrus, middle part right WM
59	Medial and inferior temporal gyri anterior part left WM
60	Medial and inferior temporal gyri anterior part right WM
61	Lateral occipitotemporal gyrus, gyrus fusiformis anterior part left WM
62	Lateral occipitotemporal gyrus, gyrus fusiformis anterior part right WM
63	Insula right WM
64	Insula left WM
65	Occipital lobe right WM
66	Occipital lobe left WM
67	Gyri parahippocampalis et ambiens posterior part right WM
68	Gyri parahippocampalis et ambiens posterior part left WM
69	Lateral occipitotemporal gyrus, gyrus fusiformis posterior part right WM
70	Lateral occipitotemporal gyrus, gyrus fusiformis posterior part left WM
71	Medial and inferior temporal gyri posterior part right WM
72	Medial and inferior temporal gyri posterior part left WM
73	Superior temporal gyrus, posterior part right WM
74	Superior temporal gyrus, posterior part left WM
75	Cingulate gyrus, anterior part right WM
76	Cingulate gyrus, anterior part left WM
77	Cingulate gyrus, posterior part right WM
78	Cingulate gyrus, posterior part left WM
79	Frontal lobe right WM
80	Frontal lobe left WM
81	Parietal lobe right WM
82	Parietal lobe left WM
83	CSF
84	Extra-cranial background
85	Intra-cranial background
86	Thalamus right, low intensity part in T2
87	Thalamus left, low intensity part in T2

So, the {tab} as the delimiter between the first and second columns. But the descriptive text in the second column contains lots of {spaces}, and in some occasions {commas}.

I guess this is why labelconvert complains:
labelconvert: [ERROR] Inconsistent number of columns in LUT file "all_labels.csv"
I did a quick work-around by replacing the {spaces} with ‘-’, and then everything works (so {commas} were not a problem).

So my questions

What is the required format for the LUTs to work with labelconvert?

How is labelconvert reading the input LUT (integer from from column 1 and finding the description from column 2)?

Would it then be possible to generalise labelconvert to work with LUT formats like the one here?

Cheers,
Finn

Hi Finn,

You’re right in that it’s the spaces between words in the label descriptions that was causing the issue. The LUT file import is basically designed to handle whatever instances of such data I’ve come across so far; and they have all used spaces as the column delimiter, with underscores between words if necessary. So replacing those spaces with dashes or underscores will get you by for now.

It is probably possible to create some kind of generalised lookup table importer, that would try to ascertain any plausible formatting in which the label information may be provided; but that would take more of my time than I’m willing to commit to it. The more likely solution is that I add code tailored to detecting when a LUT file is provided specifically in this format, and then import it appropriately.

The set of currently-supported LUT file formats can be read from the source code here, where it examines the consistent (space-delimited) column structure of the data after a first pass through the file in order to automatically determine the file format. I could add this information to either the inline documentation of the labelconvert command, or somewhere in the online documentation, if it would be of use.

Cheers
Rob

Thanks Rob! Great, then I know how LUTs are handled by labelconvert.

Sorry, not so good at reading the source code (i.e. not a C++ programmer - otherwise I could have deciphered it myself), but when you point out the LUT formats in the source code, it is easy to understand. I will see if I can put it in LUT_ITKSNAP format from the beginning, as I will editing the segmentation in ITKSNAP. It would be more useful to have a colour LUT than what it is like now. Anyway, the work around is easy.

Cheers
Finn

Hi Finn,
I want to segment the T2w of neonates by using the Draw Em,and I installed the MIRTK software and Draw Em,could you please tell me which command should I use to run the segmentation?
cheers,
liang

Hi @liang,

I used the $DRAWEMDIR/pipelines/neonatal-pipeline-v1.1.sh when I processed my data. Simply check the script on how to make a call along the lines

$ bash $DRAWEMDIR/pipelines/neonatal-pipeline-v1.1.sh T2w.nii.gz 40

However, you might prefer to check out the dHCP structural pipeline?

Cheers
Finn