Skip to content

Instantly share code, notes, and snippets.

View fepegar's full-sized avatar

Fernando Pérez-García fepegar

View GitHub Profile
@fepegar
fepegar / toQImage.py
Last active June 22, 2017 19:11 — forked from smex/toQImage.py
Convert numpy arrays to QImage
from PyQt4.QtGui import QImage, qRgb
import numpy as np
class NotImplementedException:
pass
gray_color_table = [qRgb(i, i, i) for i in range(256)]
def toQImage(im, copy=False):
if im is None:
import os
import sys
import argparse
from os.path import join, exists, isdir
"""
Usage: Slicer --no-main-window --python-script interpolateMergedContours.py -i labelmapsInDir -o labelmapsOutDir
"""
def interpolateMergedContours(inputImagePath, outputImagePath=None, outputMeshPath=None):
@fepegar
fepegar / showGlyph.py
Last active July 6, 2018 11:09
Paste this code into 3D Slicer Python console to run this example on how to use vtkGlyph3d()
import numpy as np
points = vtk.vtkPoints()
vertices = vtk.vtkCellArray()
sizes = vtk.vtkFloatArray()
sizes.SetName('Sizes')
colors = vtk.vtkFloatArray()
colors.SetName('Colors')
@fepegar
fepegar / update_slicer.py
Last active January 20, 2022 15:10
Script I use to automatically update 3D Slicer on Linux every night
#!/usr/bin/env python
import re
import sys
from pathlib import Path
from sys import platform as _platform
import time
import shutil
import urllib.request
import tarfile
@fepegar
fepegar / README.md
Last active April 14, 2024 07:31
Python function to create maximum intensity projections using SimpleITK

Requirements:

  • Python
  • SimpleITK
  • NumPy

Install

conda install numpy -y
@fepegar
fepegar / k_means.py
Last active March 2, 2018 09:52
Naive example implementation of K-means clustering algorithm
import numpy as np
import matplotlib.pyplot as plt
def k_means(points, num_classes, epsilon=1e-5, plot=False):
means = np.random.rand(num_classes, 2)
diff_means = np.inf
while(diff_means > epsilon):
# Assignment step
@fepegar
fepegar / user-aliases.cmd
Last active February 5, 2019 21:45
My cmder aliases
;= @echo off
;= rem Call DOSKEY and use this file as the macrofile
;= %SystemRoot%\system32\doskey /listsize=1000 /macrofile=%0%
;= rem In batch mode, jump to the end of the file
;= goto:eof
;= Add aliases below here
e.=explorer .
glol=git log --oneline --all --graph --decorate $*
ls=ls --show-control-chars -F --color $*
pwd=cd
@fepegar
fepegar / .slicerrc.py
Last active October 27, 2019 20:55
My .slicerrc.py file
from glob import glob
from time import gmtime, strftime
from os.path import expanduser, splitext, basename, join, isdir
import qt, vtk, ctk, slicer
import numpy as np
import SimpleITK as sitk
ONE_BY_THREE_LAYOUT_ID = 501
@fepegar
fepegar / slicerv.py
Last active October 31, 2018 12:47
Script I use to upgrade 3D Slicer on macOS using brew
#!/usr/bin/env python3
"""
This script prints out the revision number and bitstream ID of the latest
nightly build of 3D Slicer.
"""
import re
import sys
from sys import platform as _platform
@fepegar
fepegar / unet-constraints.ipynb
Last active April 11, 2024 06:30
Understanding U-Net shape constraints
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.