Skip to content

Instantly share code, notes, and snippets.

View jcreinhold's full-sized avatar

Jacob Reinhold jcreinhold

View GitHub Profile
@jcreinhold
jcreinhold / rpca_gpu.py
Last active February 7, 2024 04:10
GPU RPCA and SVT
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
rpca_gpu
implementations of RPCA on the GPU (leveraging pytorch)
for low-rank and sparse matrix decomposition as well as
a nuclear-norm minimization routine via singular value
thresholding for matrix completion
@jcreinhold
jcreinhold / nii_to_tif.py
Last active August 1, 2023 18:23
Convert NIfTI images into multiple TIF images
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
nii_to_tif
command line executable to convert 3d nifti images to
individual tiff images along a user-specified axis
call as: python nii_to_tif.py /path/to/nifti /path/to/tif
(append optional arguments to the call as desired)
@jcreinhold
jcreinhold / tif_to_nii.py
Last active November 23, 2022 15:46
Convert TIFF image directory (of one image) to NIfTI
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
tif_to_nii
command line executable to convert a directory of tif images
(from one image) to a nifti image stacked along a user-specified axis
call as: python tif_to_nii.py /path/to/tif/ /path/to/nifti
(append optional arguments to the call as desired)
@jcreinhold
jcreinhold / mha_to_nii.py
Created December 29, 2018 23:45
Convert mha file format to NIfTI
#/usr/bin/env python
# -*- coding: utf-8 -*-
"""
nii_to_tif
convert all mha files in a directory to nifti
Author: Jacob Reinhold (jacob.reinhold@jhu.edu)
"""
@jcreinhold
jcreinhold / pooled-var.ipynb
Last active April 15, 2022 21:30
Pooled variance vs. variance using pooled mean
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jcreinhold
jcreinhold / pvalues.Rmd
Last active April 13, 2022 20:44
Explore the distribution of p-values
---
title: "On the distribution of p-values"
output: html_notebook
---
```{r}
sample.sizes <- seq(5, 100, 10)
num.trials <- 1000
num.experiments <- 1
null.mu <- 0.0
@jcreinhold
jcreinhold / normalize-image-by-tissue.py
Last active April 7, 2022 16:54
normalize one image by a rough estimate of tissue class mean
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Normalize the intensity of an image by
finding a tissue mean in the foreground and
voxel-wise dividing the image by that value
Author: Jacob Reinhold
"""
import sys
from argparse import ArgumentParser
@jcreinhold
jcreinhold / quicksort.ml
Last active March 18, 2022 21:23
OCaml implementation of QuickSort
let swap arr i j =
let tmp = arr.(j) in
arr.(j) <- arr.(i);
arr.(i) <- tmp
let partition arr l h =
let pivot = arr.(h) in
let i = ref @@ (l - 1) in
for j = l to h - 1 do
if arr.(j) <= pivot then begin
@jcreinhold
jcreinhold / rselect.ml
Last active March 18, 2022 21:21
randomized order statistic selection in OCaml
let swap arr i j =
let tmp = arr.(j) in
arr.(j) <- arr.(i);
arr.(i) <- tmp
let partition arr l h =
let pivot = arr.(h) in
let i = ref @@ (l - 1) in
for j = l to h - 1 do
if arr.(j) <= pivot then begin
@jcreinhold
jcreinhold / test_image_equality.py
Last active March 4, 2022 15:23
Testing if two images are the same
# pymedio is used here because it opens a wide variety of
# medical image formats but you can use 'nibabel', 'pydicom',
# or 'SimpleITK' and extract the pixel data as an array and
# use the same functions to test equality
from pymedio.image import Image
# 'query_image' and 'target_image' can be most common medical
# image formats, e.g., NIfTI, directory of DICOM frames, etc.
query = Image.from_path("path/to/query_image")
target = Image.from_path("path/to/target_image")