Skip to content

Instantly share code, notes, and snippets.

View gattia's full-sized avatar

Anthony gattia

View GitHub Profile
import SimpleITK as sitk
import numpy as np
import os
import matplotlib.pyplot as plt
folder_dicom = 'FILL THIS PATH IN'
where_to_save = 'PATH_TO_SAVE/filename.nrrd'
# read in the dicom series as an image
@gattia
gattia / python_submit.py
Created September 6, 2023 14:02
function for submitting slurm jobs using python.
import os
import json
import subprocess
def python_submit(command,
out='./slurm-%j.out',
gpu='2080ti',
node='any',
memory=24,
@gattia
gattia / laurel_dsc.py
Last active August 26, 2023 00:41
dsc calculation
import torch
import numpy as np
from typing import Callable, Sequence, Union
arr_type = Union[np.ndarray, torch.Tensor]
def flatten_other_dims(
xs: Union[arr_type, Sequence[arr_type]], dim: Union[int, Sequence[int]] = None
):
"""Flattens all dimensions other than the specified dimension(s).
@gattia
gattia / calc_surface_metrics.py
Created August 15, 2023 15:17
Calculate surface metrics including ASSD (average symmetric surface distance).
imoport numpy as np
import SimpleITK as sitk
def get_maps(binary_seg):
dist_map = sitk.Abs(sitk.SignedMaurerDistanceMap(binary_seg,
squaredDistance=False,
useImageSpacing=True))
surface_map = sitk.LabelContour(binary_seg)
return (dist_map, surface_map)
apt-get update
apt-get install --yes \
build-essential \
cmake \
libtool \
autoconf \
pkg-config \
gfortran \
libopenblas-dev \
liblapack-dev \
import numpy as np
from pycpd import RigidRegistration
# Based off of this example: https://github.com/siavashk/pycpd/blob/master/examples/bunny_rigid_3D.py
X = np.loadtxt('data/bunny_target.txt')
# synthetic data, equaivalent to X + 1
Y = np.loadtxt('data/bunny_source.txt')
reg = RigidRegistration(**{'X': X, 'Y': Y})
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 4.0.2
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
package org.opensim.modeling;
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 4.0.2
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
package org.opensim.modeling;
@gattia
gattia / COMAKInverseKinematicsTool.java
Created January 21, 2022 17:52
SWIG Java file for COMAKInverseKinematicsTool
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 4.0.2
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
package org.opensim.modeling;
@gattia
gattia / jam.py
Created January 19, 2022 18:47
opensim-jam built jam.py file
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 4.0.2
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
from sys import version_info as _swig_python_version_info
if _swig_python_version_info < (2, 7, 0):
raise RuntimeError("Python 2.7 or later required")