Skip to content

Instantly share code, notes, and snippets.

@kevin-keraudren
kevin-keraudren / volume_rendering.py
Last active December 8, 2023 17:10
Volume rendering in Python using VTK-SimpleITK
#!/usr/bin/python
import SimpleITK as sitk
import vtk
import numpy as np
import sys
from vtk.util.vtkConstants import *
filename = sys.argv[1]
@kevin-keraudren
kevin-keraudren / vtk_heart.py
Created October 20, 2014 13:53
Python script to take screenshots of the VTK error meshes from the CETUS challenge
#!/usr/bin/python
"""
http://www.it.uu.se/edu/course/homepage/avgrafik/vt06/ComputerExercises/vtkexamples.shtml
"""
import sys
import vtk
import numpy as np
import math
from math import cos, sin
@kevin-keraudren
kevin-keraudren / clahe.py
Created July 3, 2015 10:08
ImageJ Jython script: CLAHE
#!/usr/bin/env jython
from ij import IJ
import sys
from mpicbg.ij.clahe import Flat
# http://fiji.sc/wiki/index.php/Enhance_Local_Contrast_(CLAHE)
# http://fiji.sc/cgi-bin/gitweb.cgi?p=mpicbg.git;a=blob;f=mpicbg/ij/clahe/PlugIn.java;h=663153764493547de560c08ee11f2e6b1e7e1a32;hb=HEAD
@kevin-keraudren
kevin-keraudren / cell_segmentation.py
Created July 3, 2015 10:27
ImageJ Jython: draft cell segmentation protocol
#!/usr/bin/env jython
# \begin{enumerate}
# \item Process $\rightarrow$ Gaussian Blur
# \item Process $\rightarrow$ Enhance Contrast (normalize \& equalize histogram)
# \item Image $\rightarrow$ Type $\rightarrow$ HSB stack
# \item Image $\rightarrow$ Stacks $\rightarrow$ Stack to images
# \item keep only the Hue image
# \item Process $\rightarrow$ Find maxima... (noise tolerance 60)
# \end{enumerate}
import numpy as np
def dr_toolbox(D,n_components=None):
"""
Landmark isomap dimensionality reduction method
This is the version implemented in
http://homepage.tudelft.nl/19j49/Matlab_Toolbox_for_Dimensionality_Reduction.html
Parameters
----------
@kevin-keraudren
kevin-keraudren / SLURM.md
Created August 12, 2015 15:28
SLURM examples
import dicom
import numpy as np
def load_dcm(filename):
dcm = dicom.ReadFile(filename)
# http://www.creatis.insa-lyon.fr/pipermail/dcmlib/2005-September/002141.html
# http://www.dabsoft.ch/dicom/3/C.7.6.2.1.1/
# http://xmedcon.sourceforge.net/Docs/OrientationDicomStandard
img0 = dcm[(0x5200, 0x9230)][0] # Per-frame Functional Groups Sequence
# http://stackoverflow.com/questions/9924135/fast-cartesian-to-polar-to-cartesian-in-python
import cv2
import numpy as np
import scipy.ndimage as nd
import irtk
def polar2cart(r, theta, center):
x = r * np.cos(theta) + center[0]
@kevin-keraudren
kevin-keraudren / SimpleElastix.md
Created December 10, 2015 21:44
Building SimpleElastix
#!/usr/bin/python
import numpy as np
import cv2
import densecrf as dcrf
from skimage.segmentation import relabel_sequential
import sys
# Usage:
# python dense_inference.py image annotations output