Averaging PET projection data

39 views
Skip to first unread message

Rommy Elyan

unread,
May 20, 2024, 11:17:12 AM5/20/24
to Clinica
Does anyone know how to average the PET surface projection data after running the pet surface processing pipeline?

The data for each subject is in this format:

trc-18FAV45_pet_space-fsaverage_suvr-cerebellumPons_pvc-iy_hemi-lh_fwhm-5_projection.mgh

I tried getting an average through the statistics-surface pipeline but there was an np.array error.

ninon....@gmail.com

unread,
May 24, 2024, 12:41:00 PM5/24/24
to Clinica
Hello Elyan,

You could check in the code how the regional averages are obtained (or average the regional averages if this corresponds to what you aim to obtain).

Best,
Ninon

Rom E

unread,
Dec 18, 2024, 1:51:05 PM12/18/24
to Clinica
Hi Ninon,

I kinda figured it out a while ago. I ended up using nibabel and numpy in python to average the surfaces across subjects. Hopefully this function helps someone out later. 
After using this function, I used SurfStat to project the averaged files onto a fsaverage surface

import nibabel as nib
import numpy as np
def average_mgh_files(input_files, output_file):
    # Read the first file to initialize the sum and get the affine
    first_img = nib.load(input_files[0])
    sum_data = first_img.get_fdata().astype(np.float32)  # Ensure data is float32
    affine = first_img.affine

    # Iterate over the rest of the files and accumulate the sum
    for file in input_files[1:]:
        img = nib.load(file)
        sum_data += img.get_fdata().astype(np.float32)  # Ensure data is float32

    # Calculate the average
    avg_data = sum_data / len(input_files)

    # Convert the average data to a recognized data type, here using float32
    avg_data = avg_data.astype(np.float32)

    # Save the result to a new .mgh file
    avg_img = nib.MGHImage(avg_data, affine)
    nib.save(avg_img, output_file)
rh_input_files = ['ses-1_trc-18FAV45_pet_space-fsaverage_suvr-cerebellumPons_pvc-iy_hemi-rh_fwhm-5_projection.mgh', ...]
# include list of right hemisphere files for every subject, then do the same for left hemisphere
average_mgh_files(rh_input_files, 'rh_average.mgh')

Reply all
Reply to author
Forward
0 new messages