Skip to content

Instantly share code, notes, and snippets.

@brikeats
brikeats / tkinter_template.py
Last active February 25, 2016 20:34
Demo of Tkinter's widgets. Can be used as a template / skeleton for a simple GUI application.
import sys
import Tkinter as tk
from tkFileDialog import askopenfilename, asksaveasfilename
class App(tk.Tk):
"""
A simple demo of the basic Tkinter widgets. This can be used as a skeleton for a simple GUI applications.
@brikeats
brikeats / wxpython_template.py
Last active August 21, 2022 09:53
Skeleton simple GUI application in wxpython
import wx
APP_EXIT = 1
FILE_SAVE = 2
FILE_OPEN = 3
SHOW_HELP = 4
SHOW_ABOUT = 5
class Example(wx.Frame):
@brikeats
brikeats / BKlib.py
Last active February 7, 2017 09:36
A library of python functions that I've found helpful for image processing.
import time
import itertools
import platform
import subprocess
from functools import partial
from scipy import optimize, ndimage
from scipy.integrate import simps
from scipy.interpolate import splev, splprep
import numpy as np
from PIL import Image
@brikeats
brikeats / volshow.py
Last active June 13, 2023 11:02
Show slices through a 3D numpy array (volume) with optional mask overlay. Uses only numpy and matplotlib.
def volshow(vol, sl_dim=0, mask=None, **kwargs):
# FIXME: doesn't work when sl_dim=-1
"""
This function displays slices into a 3-dimensional numpy array. Optionally, the user can
pass a binary mask of the same size to be displayed on top of the volume. This is intended
to be a 3D equivalent of pyplot.imshow.
Usage:
the up and down arrows flip through the slices
'd' toggles the slice dimension (eg, axial->sagittal->coronal)
@brikeats
brikeats / scribble.py
Last active April 25, 2024 07:29
matplotlib GUI to allow user to scribble on an image
from collections import OrderedDict
import numpy as np
import matplotlib
matplotlib.use('TkAgg')
import warnings;
with warnings.catch_warnings():
warnings.simplefilter("ignore");
import matplotlib.pyplot as plt
from skimage.transform import rescale
@brikeats
brikeats / hist_match.py
Created May 25, 2016 22:00
Histogam matching. This should be part of skimage
def hist_match(im, ref_im):
if np.squeeze(im).ndim == 2:
im = np.expand_dims(im, axis=2)
ref_im = np.expand_dims(ref_im, axis=2)
out_im = np.empty_like(im)
for chan_num in range(im.shape[2]):
chan, ref_chan = im[...,chan_num], ref_im[...,chan_num]
@brikeats
brikeats / backup.sh
Last active August 26, 2016 20:40
Backup script for OSX. Takes incremental snapshots and puts them in folders with the date/time.
#!/bin/bash
LOG_FOLDER=~/MineAnnotationsBackup/logs
BACKUP_FOLDER=~/MineAnnotationsBackup
# script from here: http://www.howtogeek.com/175008/the-non-beginners-guide-to-syncing-data-with-rsync/
#copy old time.txt to time2.txt
yes | cp $LOG_FOLDER/time.txt $LOG_FOLDER/time2.txt
@brikeats
brikeats / roslocal
Created September 11, 2016 22:03
Run ROS initialization script with ROS_MASTER set to the local IP. Suitable for running ROS stuff on a single machine.
source /opt/ros/indigo/setup.bash
source /home/brian/robotics_code/ROS/workspace/devel/setup.bash
export ROS_IP=`ifconfig|grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}"|tail -n 3|head -n 1`
export ROS_MASTER_URI=http://$ROS_IP:11311/
echo "ROS is now ready to run, with ROS_MASTER set to $ROS_MASTER_URI."
@brikeats
brikeats / image_parameter_tweak.py
Last active October 24, 2016 20:17
Use ipython notebook widgets to experiment with image processing parameters.
import matplotlib.pyplot as plt
import inspect
from ipywidgets import *
from IPython.display import display
%matplotlib inline
plt.rcParams['image.cmap'] = 'gray'
plt.rcParams['image.interpolation'] = 'none'
# http://ipywidgets.readthedocs.io/en/latest/examples/Using%20Interact.html
@brikeats
brikeats / tile_image.py
Last active April 5, 2017 15:24
Partition a big image into equally-size overlapping tiles. Reassemble the tiles.
import numpy as np
from collections import OrderedDict
# im_fn = 'images/copperopolis_quarry_google_17_cropped.tif'
# im = plt.imread(im_fn)
def tile_image(im, tile_size, overlap=0):
"""
Partition a large image into equally-sized overlapping tiles.