Hi Andras!
I’ve been able to solve it (I believe). Once I was able to access the coordinate and scalar values performing a mercator projection was easy. All points were interpolated creating a 2D texture. With this 2D texture we can do all sorts of cool things like using it as a CNN input, or using it in external rendering software
Thanks a lot for the support Andras!
In the figure above 10% of the data was used to show the effect of interpolation.
For anyone in the future wanting to project FreeSurfer scalar data to a 2D img, this is how I did it:
import numpy as np
from scipy.interpolate import griddata
from PIL import Image
resolution = 1024
# Get coordinate and scalar values
model_node = getNode('vtkMRMLModelNode4')
scalars = arrayFromModelPointData(model_node, 'thickness')
coordinates = arrayFromModelPoints(model_node)
# Convert cartesian to polar coordinates
coordinates = np.subtract(coordinates, np.mean(coordinates, axis=0))
r = np.sqrt(np.sum(np.square(coordinates), axis=1))
xc, yc, zp = [coordinates[:, ax] for ax in range(3)]
xp = np.arctan2(yc, xc)
yp = np.arcsin(zp / r)
# Define interpolation grid
xi = np.linspace(-np.pi, np.pi, resolution)
yi = np.linspace(-0.5 * np.pi, 0.5 * np.pi, resolution)
xi, yi = np.meshgrid(xi, yi)
# interpolate
zi = griddata((xp, yp), scalars, (xi, yi), method='linear')
zi = np.nan_to_num(zi)
# Save array as image
im = Image.fromarray(zi)
im.convert('RGB').save("filename.jpeg")
Tags: Freesurfer, Fastsurfer, cortical vertex data, cortical thickness Freesurfer scalar overlay, texture mapping, 2D projection, mercator projection, flattening