Skip to content

Instantly share code, notes, and snippets.

View mistycheney's full-sized avatar

Yuncong Chen mistycheney

View GitHub Profile
@mistycheney
mistycheney / 0_reuse_code.js
Last active August 29, 2015 14:09
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@mistycheney
mistycheney / colorbar_same_height.py
Created February 10, 2015 02:23
Set Matplotlib colorbar size to match graph
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import numpy as np
plt.figure()
ax = plt.gca()
im = ax.imshow(np.arange(100).reshape((10,10)))
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
plt.colorbar(im, cax=cax)
@mistycheney
mistycheney / ipython_notebook_config.py
Last active October 23, 2015 18:27
Sample iPython Notebook Config File
# Configuration file for ipython-notebook.
c = get_config()
#------------------------------------------------------------------------------
# NotebookApp configuration
#------------------------------------------------------------------------------
# NotebookApp will inherit config from: BaseIPythonApplication, Application
@mistycheney
mistycheney / patches_to_rec.py
Last active January 28, 2016 21:13
Generate mxnet record from image patches
stack = 'MD589'
data_dir = '/oasis/projects/nsf/csd395/yuncong/CSHL_data_patches/%s_byLandmark'%(stack)
all_image_names = []
for label in os.listdir(data_dir):
if label == 'BackG':
# limit the number of BackG examples
for img_filename in os.listdir(data_dir + '/' + label)[:300]:
all_image_names.append((label_dict[label], label + '/' + img_filename))
else:
@mistycheney
mistycheney / sort_vertices_counterclockwise.py
Created March 13, 2016 11:41
sort polygon vertices counterclockwise
def less(center):
def less_helper(a, b):
if (a[0] - center[0] >= 0 and b[0] - center[0] < 0):
return 1;
if (a[0] - center[0] < 0 and b[0] - center[0] >= 0):
return -1;
if (a[0] - center[0] == 0 and b[0] - center[0] == 0):
if (a[1] - center[1] >= 0 or b[1] - center[1] >= 0):
return 2*int(a[1] > b[1]) - 1;
return 2*int(b[1] > a[1]) - 1
@mistycheney
mistycheney / concave_hull.py
Last active March 13, 2016 11:42
concave hull
# https://gist.github.com/hellpanderrr/2c08af0f07eed4782234
from scipy.spatial import Delaunay, ConvexHull
import networkx as nx
def concave_hull(points,alpha_x=150,alpha_y=250):
points = [(i[0],i[1]) if type(i) <> tuple else i for i in points]
de = Delaunay(points)
dec = []
a = alpha_x
@mistycheney
mistycheney / bbox.py
Last active April 13, 2016 02:45
bounding box for 2d or 3d binary images
# http://stackoverflow.com/a/31402351
def bbox_2d(img):
rows = np.any(img, axis=1)
cols = np.any(img, axis=0)
rmin, rmax = np.where(rows)[0][[0, -1]]
cmin, cmax = np.where(cols)[0][[0, -1]]
return cmin, cmax, rmin, rmax
@mistycheney
mistycheney / incorporating_uncertainty.md
Created May 17, 2016 08:08
incorporating_uncertainty

Incorporating Uncertainty

If the score maps given by the classifier are not extremely reliable, we need to balance between the reference structure locations constrained by the atlas and the evidence from score maps.

We do this in a Bayesian setting. Suppose the atlas gives a prior distribution for the structure's location, represented by $P(\theta)$. An observation distribution $P(s | \Omega)$ models classification uncertainty, where $\Omega$ is the set of voxels that belong to a particular structure, and $s$ is the computed score volume.

Let $\Omega(\theta)$ denote this structure's voxel locations transformed by $\theta$, and let $s$ denote the score volume, then the likelihood of the score volume is $P(s | \Omega(\theta))$. The optimal transform $\theta^*$ should maximize the posterior:

$$ \theta^* = \arg\max P(s | \Omega(\theta)) P(\theta).$$

Cereal Name Manufacturer Type Calories Protein (g) Fat Sodium Dietary Fiber Carbs Sugars Display Shelf Potassium Vitamins and Minerals Serving Size Weight Cups per Serving
100%_Bran Nabisco C 70 4 1 130 10 5 6 3 280 25 1 0.33
100%_Natural_Bran Quaker Oats C 120 3 5 15 2 8 8 3 135 0 1 -1
All-Bran Kelloggs C 70 4 1 260 9 7 5 3 320 25 1 0.33
All-Bran_with_Extra_Fiber Kelloggs C 50 4 0 140 14 8 0 3 330 25 1 0.5
Almond_Delight Ralston Purina C 110 2 2 200 1 14 8 3 -1 25 1 0.75
Apple_Cinnamon_Cheerios General Mills C 110 2 2 180 1.5 10.5 10 1 70 25 1 0.75
Apple_Jacks Kelloggs C 110 2 0 125 1 11 14 2 30 25 1 1
Basic_4 General Mills C 130 3 2 210 2 18 8 3 100 25 1.33 0.75
Bran_Chex Ralston Purina C 90 2 1 200 4 15 6 1 125 25 1 0.67
@mistycheney
mistycheney / batch_convert
Created October 12, 2017 23:05
batch convert imagej plugin
// Batch Convert
//
// This macro convert all the files in a folder to TIFF, 8-bit TIFF,
// JPEG, GIF, PNG, PGM, BMP, FITS, Text Image, ZIP or Raw
// format. Three dialog boxes are displayed. Select the source
// folder in the first, the format in the second and the destination
// folder in the third. Batch_Converter, a similar plugin is at
// http://rsb.info.nih.gov/ij/plugins/batch-converter.html
// https://imagej.nih.gov/ij/plugins/batch-converter.html