Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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