Skip to content

Instantly share code, notes, and snippets.

View cancan101's full-sized avatar

Alex Rothberg cancan101

View GitHub Profile
@cancan101
cancan101 / perspective-quadrilateral.ipynb
Created May 1, 2014 23:48
Automatic perspective correction for quadrilateral objects
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cancan101
cancan101 / load_gif_url.py
Last active August 29, 2015 14:01
OpenCV Load GIF URL
from PIL import Image
import requests
import tempfile
def load_gif_url(url):
with tempfile.NamedTemporaryFile(suffix=".gif") as f:
f.write(requests.get(url).content)
f.flush()
img = Image.open(f.name)
@cancan101
cancan101 / image_utils.py
Last active August 29, 2015 14:01
OpenCV Image Utilities
def get_bw(src):
return cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
def show_color(src):
plt.imshow(cv2.cvtColor(src, cv2.COLOR_BGR2RGB))
_ = plt.xticks([]), plt.yticks([])
def show_bw(bw):
plt.imshow(bw, cmap='gray')
_ = plt.xticks([]), plt.yticks([])
@cancan101
cancan101 / get_state_v0.py
Last active August 29, 2015 14:01
Get Solid-Filled Image for State Map v0
def get_state_v0(state):
url = make_url(state)
IN = load_gif_url(url)
#Drop the text at the top
IN = IN[150:]
#Convert 3 color channels to 1
IN_bw = get_bw(IN)
@cancan101
cancan101 / get_state_v1.py
Last active August 29, 2015 14:01
Get Solid-Filled Image for State Map v1
def get_state_v1(state):
url = make_url(state)
IN = load_gif_url(url)
#Drop the text at the top
IN = IN[150:]
#Convert 3 color channels to 1
IN_bw = get_bw(IN)
@cancan101
cancan101 / Map Recognition.ipynb
Last active August 29, 2015 14:01
Notebook Demonstrating Technique to Identify US State Maps
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cancan101
cancan101 / MLP Hu.ipynb
Created July 21, 2014 06:59
Notebook Demonstrating Using MLPs to Classify State Map Images
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cancan101
cancan101 / Linear Interpolator Test Pub.ipynb
Created August 12, 2014 04:42
Linear Interpolator Test
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cancan101
cancan101 / .numpy-site.cfg
Created August 14, 2014 19:59
numpy-site.cfg for building against openblas
[default]
library_dirs = /usr/local/lib
[atlas]
atlas_libs = openblas
library_dirs = /usr/local/lib
[lapack]
lapack_libs = openblas
library_dirs = /usr/local/lib
[openblas]
libraries = openblas
import os
os.environ['THEANO_FLAGS']="optimizer_including=conv_fft_valid:conv_fft_full"
from pylearn2.config import yaml_parse
from pylearn2.datasets.dense_design_matrix import DenseDesignMatrix
import numpy as np
train_str = """!obj:pylearn2.train.Train {
dataset: &train !import '__main__ .train_set',