Skip to content

Instantly share code, notes, and snippets.

@luispedro
Created April 13, 2011 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luispedro/916944 to your computer and use it in GitHub Desktop.
Save luispedro/916944 to your computer and use it in GitHub Desktop.
Beads
import numpy as np
import mahotas
from scipy import ndimage
img = mahotas.imread('copy_cam1.jpg')
img = img.mean(2)
img = img.astype(float)
bead = img[433:443,495:512]
sy,sx = bead.shape
bead = bead.astype(float)
bead = bead.ravel()
bead -= bead.mean()
bead /= bead.std()
def ncc(x,y):
x = x.ravel()
x_ = x.mean()
sx = x.std()
return np.dot(x-x_, y)/sx
nc = np.zeros(img.shape, float)
for y in xrange(img.shape[0]-sy):
for x in xrange(img.shape[1]-sx):
nc[y+sy//2,x+sx//2] = ncc(img[y:y+sy,x:x+sx],bead)
nc /= sx*sy
import matplotlib.pyplot as plt
import pymorph
imshow(pymorph.overlay(img.astype(np.uint8), pymorph.dilate(pymorph.dilate(nc > .7))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment