Skip to content

Instantly share code, notes, and snippets.

View ashkanpakzad's full-sized avatar

Ashkan Pakzad ashkanpakzad

View GitHub Profile
@ashkanpakzad
ashkanpakzad / Remove oversampled interslices.py
Created May 25, 2023 20:15
Remove an interval of axial slices from a CT image in python
import nibabel as nib
import numpy as np
# set paths and params
in_path = 'case.nii.gz'
out_path = 'case_out.nii.gz'
interspace = 2
# load data
img = nib.load(in_path)
@ashkanpakzad
ashkanpakzad / MacBatchOpticalDiskRipper.py
Last active November 23, 2021 17:41
MacBatchOpticalDiskRipper
# By Ashkan Pakzad (ashkanpakzad.github.io) 2021
# This is a python script to batch rip several CD/DVD optical disks.
# It should only require you to change the disk when ejected and the rest is automated.
# Only works on mac as it uses mac's drutil commands to trigger the systems optical
# disk tray.
# Only runs on mac, dependent on pypi package progress,
# pip install progress
import nibabel as nib
import dicom_numpy
import os
import numpy as np
pathtodicom = '/path/to/dicom/'
# get list of dicom images from directory that make up the 3D image
dicomlist = [pathtodicom + f for f in os.listdir(pathtodicom)]
# load dicom volume
@ashkanpakzad
ashkanpakzad / edit.py
Created April 5, 2019 13:04
edit dicom
import os
import pydicom
# paths to data and save location
filepath = './data/' # directory containing the dicom series
dcmprefix = 'Image_' # Individual dicom file prefix before number
firstdcm = dcmprefix + '%04d.DICOM' %1 # first dicom image to inspect metadata fields
newdir = './data-edited/' # directory to save new metadata fields
# Find total number of dicom files in series
import os
import pydicom
# paths to data and save location
filepath = './data/' # directory containing the dicom series
dcmprefix = 'Image_' # Individual dicom file prefix before number
firstdcm = dcmprefix + '%04d.DICOM' %1 # first dicom image to inspect metadata fields
newdir = './data-edited/' # directory to save new metadata fields
# Find total number of dicom files in series
@ashkanpakzad
ashkanpakzad / dicomedit.py
Created April 5, 2019 12:51
Add missing dicom fields
import os
import pydicom
# paths to data and save location
filepath = './data/' # directory containing the dicom series
dcmprefix = 'Image_' # Individual dicom file prefix before number
firstdcm = dcmprefix + '%04d.DICOM' %1 # first dicom image to inspect metadata fields
newdir = './data-edited/' # directory to save new metadata fields
# Find total number of dicom files in series