Skip to content

Instantly share code, notes, and snippets.

import numpy as np
from os.path import basename
from glob import glob
from skimage.color import label2rgb
import matplotlib
matplotlib.use('TkAgg')
from matplotlib import pyplot as plt
from tomopy.misc.phantom import shepp3d
"""
TODO:
@brikeats
brikeats / tile_image.py
Last active September 15, 2017 20:09
divide image into overlapping tiles
from skimage.util import pad
from collections import OrderedDict
# FIXME: probably a little neater to return a 4d array of shape (n_tile_rows, n_tile_col, H, W)
def tile_image(im, tile_size, overlap=(0,0)):
"""
Divide an image or video into spatially overlapping tiles.
Args:
@brikeats
brikeats / generate_webpage.py
Created March 22, 2017 19:27
Create a google maps webpage with polygons and heatmaps from geojson annotations and yield shapefiles
import shapely
html_template_part1 = """
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>%s</title>
<style>
@brikeats
brikeats / image_labeller.py
Last active February 22, 2017 01:52
simple matplotlib-based gui for labelling images
from os.path import basename
from glob import glob
from matplotlib import pyplot as plt
class ImageLabeller(object):
"""
Labels can be basically any type that you can cast to str.
Args:
@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.
@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 / 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 / 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 / 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]