Skip to content

Instantly share code, notes, and snippets.

View jcreinhold's full-sized avatar

Jacob Reinhold jcreinhold

View GitHub Profile
@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 / 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 / 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 / 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")
@jcreinhold
jcreinhold / normalize-ct-torch.py
Created December 9, 2021 16:28
normalize ct images in pytorch
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Normalize the intensity of a CT image
Author: Jacob Reinhold
"""
import sys
from argparse import ArgumentParser
from pathlib import Path
from typing import Tuple, Union
@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 / normalize-tissue.py
Created November 23, 2021 21:38
normalize by tissue mean
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Normalize the intensity of a set of images by
finding a tissue mean in the foreground and
voxel-wise dividing the image by that value
Author: Jacob Reinhold
"""
import os
import re
@jcreinhold
jcreinhold / normalize-mode.py
Created November 23, 2021 21:11
normalize intensity of images by dividing images of a specified intensity peak in histogram
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Normalize the intensity of a set of images by
finding a specified peak of each image foreground intensity
and voxel-wise dividing the image by that value
Author: Jacob Reinhold
"""
import os
import re
@jcreinhold
jcreinhold / normalize-percentile-foreground.py
Created November 23, 2021 19:53
normalize all images in a directory by the percentile of the estimated foreground
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Normalize the intensity of a set of images by
finding the specified percentile of each image
foreground and voxel-wise dividing the image by that value
Author: Jacob Reinhold
"""
import os
import re