Skip to content

Instantly share code, notes, and snippets.

View odebeir's full-sized avatar

Olivier Debeir odebeir

  • Université Libre de Bruxelles
  • Brussels, Belgium
View GitHub Profile
from enthought.enable.api import ComponentEditor, BaseTool
from enthought.chaco.api import ArrayPlotData, Plot, jet, gray, PlotGraphicsContext
from enthought.traits.api import HasTraits, Instance, Enum, Range, Dict, Button, Int, Bool, Str, Property,Event, Array, DelegatesTo, on_trait_change,List, Tuple
from enthought.traits.ui.api import Item, Group, View, InstanceEditor
def draw_plot(filename, container,size=(800,600)):
"""Render a plot to file"""
container.outer_bounds = list(size)
container.do_layout(force=True)
gc = PlotGraphicsContext(size, dpi=150)
from enthought.enable.api import ComponentEditor, BaseTool
from enthought.chaco.api import ArrayPlotData, Plot, jet, gray, PlotGraphicsContext
from enthought.traits.api import HasTraits, Instance, Enum, Range, Dict, Button, Int, Bool, Str, Property,Event, Array, DelegatesTo, on_trait_change,List, Tuple
from enthought.traits.ui.api import Item, Group, View, InstanceEditor
def draw_plot(filename, container,size=(800,600)):
"""Render a plot to file"""
container.outer_bounds = list(size)
container.do_layout(force=True)
@odebeir
odebeir / patissier.py
Created May 7, 2012 12:06
BSP - Monday 7 May
import numpy as np
n = 4
data = np.reshape(range(4*4),(n,n))
data = data[:,:,np.newaxis]
print data[:,:,0],data.shape
seq = [0,1,2,3]
@odebeir
odebeir / patissier2.py
Created May 7, 2012 13:57
BSP - Monday 7 May - some tests
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
def create_data(n):
data = np.reshape(range(n**2),(n,n))
data = data[:,:,np.newaxis]
print '-'*40
print data[:,:,0],data.shape
print '-'*40
@odebeir
odebeir / gist:3918044
Created October 19, 2012 12:38
Example of Gabor filter usage
#opencv
import cv2.cv as cv
import cv2
import numpy as np
def build_filters():
filters = []
ksize = 31
for theta in np.arange(0, np.pi, np.pi / 32):
@odebeir
odebeir / gist:5038467
Last active April 1, 2016 23:10
Color deconvolution for python cf : A. C. Ruifrok and D. A. Johnston, “Quantification of histochemical staining by color deconvolution.,” Analytical and quantitative cytology and histology / the International Academy of Cytology [and] American Society of Cytology, vol. 23, no. 4, pp. 291–9, Aug. 2001.
def convert_to_optical_densities(rgb,r0,g0,b0):
OD = rgb.astype(float)
OD[:,:,0] /= r0
OD[:,:,1] /= g0
OD[:,:,2] /= b0
return -np.log(OD)
def color_deconvolution(rgb,r0,g0,b0,verbose=False):
stain_OD = np.asarray([[0.18,0.20,0.08],[0.01,0.13,0.0166],[0.10,0.21,0.29]]) #hematoxylin, eosyn, DAB
@odebeir
odebeir / gist:5237529
Last active November 8, 2021 12:49
Small python code for building Gabor filters
# opencv
import cv2.cv as cv
import cv2
def build_filters():
""" returns a list of kernels in several orientations
"""
filters = []
ksize = 31
for theta in np.arange(0, np.pi, np.pi / 32):
@odebeir
odebeir / gist:5598052
Last active December 17, 2015 10:49
label2rgb
label = np.asarray([[0,1],[2,3]])
rgblabel = np.zeros([2,2,3])
rgblabel[label==1,:]=[1,0,0]
rgblabel[label==2,:]=[0,1,0]
rgblabel[label==3,:]=[0,0,1]
plt.imshow(rgblabel,interpolation='nearest')
plt.show()
import matplotlib.pyplot as plt
from skimage.morphology import watershed,disk
from skimage.filter import rank
from skimage import data
import numpy as np
image = data.camera()
gradient = rank.gradient(image, disk(2))
@odebeir
odebeir / feature_wood.py
Created June 17, 2016 15:57
feature woof
def wavelet_analysis(sig):
""" decompose signal into wavelets
returns the frequence of the thesholded filtered signal
"""
widths = np.arange(1, 100,1)
cwtmatr = signal.cwt(sig, signal.ricker, widths)
N = sig.size
fsig = cwtmatr[98,:]
detect_pos = fsig>30