Created
April 13, 2011 04:00
-
-
Save luispedro/916944 to your computer and use it in GitHub Desktop.
Beads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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