Skip to main content

Anatomical curvature processing for medical images.

Project description

curvanato

local curvature quantification for anatomical data

Installation & Testing

To install the package locally, navigate to the package root and run:

pip install .

Usage

import ants
import antspynet
import antspyt1w
import curvanato
import re
import os  # For checking file existence
import pandas as pd
import numpy as np
os.environ["ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS"] = "32"
# ANTPD data from open neuro
fn='.//bids/sub-RC4111/ses-1/anat/sub-RC4111_ses-1_T1w.nii.gz' # easy
fn='.//bids/sub-RC4103/ses-1/anat/sub-RC4103_ses-1_T1w.nii.gz'
fn='./bids//sub-RC4110/ses-2/anat/sub-RC4110_ses-2_T1w.nii.gz'
if os.path.exists(fn):
    t1=ants.image_read( fn )
    t1=ants.resample_image( t1, [0.5, 0.5, 0.5], use_voxels=False, interp_type=0 )
    hoafn = re.sub( ".nii.gz", "_hoa.nii.gz" , fn )
    if not os.path.exists(hoafn):
        hoa = antspynet.harvard_oxford_atlas_labeling(t1, verbose=True)['segmentation_image']
        ants.image_write( hoa, hoafn)
    hoa = ants.image_read( hoafn )
    citfn = re.sub( ".nii.gz", "_cit168.nii.gz" , fn )
    if not os.path.exists(citfn):
        t1b = antspynet.brain_extraction( t1, modality="t1threetissue" )['segmentation_image'].threshold_image(1,1)
        t1r = ants.rank_intensity( t1 * t1b )
        cit = antspyt1w.deep_cit168( t1r, verbose=True)['segmentation']
        ants.image_write( cit, citfn)
    cit = ants.image_read( citfn )

###################################################################################
###################################################################################
###################################################################################
###################################################################################
ctype='cit'
tcaudL=curvanato.load_labeled_caudate( option='hmt', binarize=False, label=[1,3,5] )
tcaudR=curvanato.load_labeled_caudate( option='hmt', binarize=False, label=[2,4,6] )
vlab=None
leftside=True
gr=0
subd=0
otherside=True
if otherside:
    ccfn = [
        re.sub( ".nii.gz", "_"+ctype+"Rkappa.nii.gz" , fn ), 
        re.sub( ".nii.gz", "_"+ctype+"R.nii.gz" , fn ),
        re.sub( ".nii.gz", "_"+ctype+"Rthk.nii.gz" , fn ),
        re.sub( ".nii.gz", "_"+ctype+"Rkappa.csv" , fn ),
        re.sub( ".nii.gz", "_"+ctype+"Rkappa.png" , fn ),
        re.sub( ".nii.gz", "_"+ctype+"Rthk.png" , fn ) ]
    pcaud=[3,4]
    plabs=[4]
    if ctype == 'cit':
        mytl=18
    xx = curvanato.t1w_caudcurv(  cit, target_label=mytl, ventricle_label=vlab, 
        prior_labels=pcaud, prior_target_label=plabs, subdivide=subd, grid=gr,
        priorparcellation=tcaudR,  plot=True,
        verbose=True )
    ants.plot( xx[0], xx[1], crop=True, axis=2, nslices=21, ncol=7, filename=ccfn[4] )
    ants.plot( xx[0], xx[2], crop=True, axis=2, nslices=21, ncol=7, filename=ccfn[5] )
    for j in range(3):
        ants.image_write( xx[j], ccfn[j] )
    xx[3].to_csv( ccfn[3] )

if leftside:
    mytl=2
    ccfn = [
        re.sub( ".nii.gz", "_"+ctype+"Lkappa.nii.gz" , fn ), 
        re.sub( ".nii.gz", "_"+ctype+"L.nii.gz" , fn ),
        re.sub( ".nii.gz", "_"+ctype+"Lthk.nii.gz" , fn ),
        re.sub( ".nii.gz", "_"+ctype+"Lkappa.csv" , fn ),
        re.sub( ".nii.gz", "_"+ctype+"Lkappa.png" , fn ),
        re.sub( ".nii.gz", "_"+ctype+"Lthk.png" , fn ) ]
    print("Begin " + fn + " caud kap")
    pcaud=[1,2]
    plabs=[2]
    xx = curvanato.t1w_caudcurv( cit, target_label=2, ventricle_label=vlab, 
        prior_labels=pcaud, prior_target_label=plabs, subdivide=subd, grid=gr,
        priorparcellation=tcaudL,  plot=True, searchrange=20,
        verbose=True )
    ants.plot( xx[0], xx[1], crop=True, axis=2, nslices=21, ncol=7, filename=ccfn[4] )
    ants.plot( xx[0], xx[1], crop=True, axis=2, nslices=21, ncol=7, filename=ccfn[5] )
    for j in range(3):
        ants.image_write( xx[j], ccfn[j] )
    xx[3].to_csv( ccfn[3] )

Example data

this package has been tested on ANTPD data from openneuro.

could also try data here which included repeated T1w acquisitions on same subjects but with different parameters. however, last time i tried this, the link was not working.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

curvanato-0.0.0.tar.gz (77.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

curvanato-0.0.0-py3-none-any.whl (69.5 kB view details)

Uploaded Python 3

File details

Details for the file curvanato-0.0.0.tar.gz.

File metadata

  • Download URL: curvanato-0.0.0.tar.gz
  • Upload date:
  • Size: 77.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for curvanato-0.0.0.tar.gz
Algorithm Hash digest
SHA256 c81ba48df71fcea7e4d8ecac7544bc9ab191b3d7a55c95f8c0f0a5ae30b4244f
MD5 7ec1f517d0aa86e0433d6502f7aa7d89
BLAKE2b-256 cbd051101c4a0132252c64d4641fd2fd24573878932c603eaf0b3f8de40d932c

See more details on using hashes here.

File details

Details for the file curvanato-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: curvanato-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 69.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for curvanato-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 878f71f90cc5723cb2a6e3649520d4b3741f0b036dbe57b51ddb7004095a50c5
MD5 03ca08bb02d60b38d0f15ba912ccc271
BLAKE2b-256 b617e833a72989d42f51b5978b88074a71255339613d67a62e77332b998c0f21

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page