Hello,

 

There was a bug in the sbtiv utility that was causing that “Namespace” error you were seeing.

Patched versions of the files are available here: https://ftp.nmr.mgh.harvard.edu/pub/dist/lcnpublic/dist/sbtiv_patch/

To apply the patch, download the tarball, unpack it, and then copy the sbtiv.py script to /Applications/freesurfer/8.1.0/python/packages/samseg/cli/sbtiv.py, to replace the buggy file.

 

You are correct that the value in sbtiv.stats is the same as the intracranial volume reported in samseg.stats, and that it is the sbTIV value. I believe that sbtiv.stats should be automatically generated when running the samseg pipeline, so you probably don’t need to run this util.

 

You can use the sbtiv util, along with a specified list of measurements that appear in samseg.stats to specify  which measures it sums to give the total intracranial volume reported in the output file.

 

Best,

Jackson

 

From: Chelsea Hennessy <chelseahennessy@outlook.com>
Date: Wednesday, November 12, 2025 at 11:39
PM
To: freesurfer@nmr.mgh.harvard.edu <freesurfer@nmr.mgh.harvard.edu>
Subject: [Freesurfer] sbTIV SAMSEG error

        External Email - Use Caution        

Hello, 

 

I am trying to run sbTIV following on my SAMSEG output through Freesurfer, but am running into issues. 

 

My SAMSEG code:

#!/bin/bash

# script to run SAMSEG on all participants

 

# define directories

DATA_DIR=“XYZ"

OUTPUT_BASE_DIR=“XYZ"

LOG_DIR=“XYZ"

 

# create directories if they don't exist

mkdir -p "${OUTPUT_BASE_DIR}"

mkdir -p "${LOG_DIR}"

 

# log file

LOG_FILE="${OUTPUT_BASE_DIR}/samseg_log.txt"

echo "SAMSEG processing started: $(date)" > "${LOG_FILE}"

 

# loop through all participant directories

for SUB_DIR in "${DATA_DIR}"/sub-*/; do

# extract participant ID from directory name

SUB_ID=$(basename "${SUB_DIR}")

# define directory paths

T1_FILE="${SUB_DIR}ses-01/anat/${SUB_ID}_ses-01_T1w.nii.gz"

OUTPUT_DIR="${OUTPUT_BASE_DIR}/${SUB_ID}"

INDIVIDUAL_LOG="${LOG_DIR}/${SUB_ID}_samseg_log.txt"

# check if T1w image file exists

if [ -f "${T1_FILE}" ]; then

echo "Processing ${SUB_ID}..." | tee -a "${LOG_FILE}"

echo "Input: ${T1_FILE}" | tee -a "${LOG_FILE}"

echo "Output: ${OUTPUT_DIR}" | tee -a "${LOG_FILE}"

# run SAMSEG

run_samseg --input "${T1_FILE}" --output "${OUTPUT_DIR}" --threads 8 2>&1 | tee "${INDIVIDUAL_LOG}"

# check if analysis completed successfully

if [ $? -eq 0 ]; then

echo "SUCCESS: ${SUB_ID} completed at $(date)" | tee -a "${LOG_FILE}"

else

echo "ERROR: ${SUB_ID} failed at $(date)" | tee -a "${LOG_FILE}"

fi

echo "-----------------------------------" | tee -a "${LOG_FILE}"

else

echo "WARNING: T1 file not found for ${SUB_ID}" | tee -a "${LOG_FILE}"

echo "Expected: ${T1_FILE}" | tee -a "${LOG_FILE}"

echo "-----------------------------------" | tee -a "${LOG_FILE}"

fi

done

 

echo "SAMSEG analysis completed: $(date)" | tee -a "${LOG_FILE}"

echo "Log file saved to: ${LOG_FILE}"

 

When trying to run sbTIV for one participant as an example:

sbtiv <path>/samseg.stats -o <path>/sbtiv.stats

 

Error:

Traceback (most recent call last):

  File "/Applications/freesurfer/8.1.0/python/scripts/sbtiv", line 8, in <module>

    sys.exit(main())

  File "/Applications/freesurfer/8.1.0/python/packages/samseg/cli/sbtiv.py", line 23, in main

    with open(args.input) as fid:

AttributeError: 'Namespace' object has no attribute 'input'

 

 

Am I correct in understanding that the value provided in the sbtiv.stats is the sbTIV value? Even when it is the same as the intra-cranial measure from the samseg.stats file?

 

I have very limited coding/neuroimaging analysis knowledge, so any help you can provide here is greatly appreciated!

 

Cheers,

Chelsea