In [1]:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
from filter import findPoints, filterNoise, substract
from math import sqrt
from matplotlib import gridspec
%matplotlib inline

Chargement des images

On dresse une liste de coordonnées de tous les points détectés pour chaque image.


In [5]:
PHOTOS = {}
IMG_SIZE = None

for i in range(32):
    photo_on, photo_off = "imgs/%02d.png"%(2*i), "imgs/%02d.png"%(2*i+1)
    try:
        image = filterNoise(substract(photo_on, photo_off))
        if IMG_SIZE is None:
            IMG_SIZE = image.shape[:2]
        PHOTOS[(photo_on, photo_off)] = [(x, 480-y) for x, y in findPoints(image)]
    except:
        continue

Nombre de points détectés par image

Affichage du nombre d'images en fonction du nombre de points détectés


In [6]:
nPoints = map(len, PHOTOS.values())
plt.hist(nPoints, bins=50)
plt.show()


Répartition des points sur les images

Où sont situé les points parmi toutes les images ?


In [7]:
allPoints = [(0,0)]
for points in PHOTOS.values():
    allPoints += points

BIN_SIZE = 5
X, Y = zip(*allPoints)
H, W = np.linspace(0, IMG_SIZE[0], IMG_SIZE[0]/BIN_SIZE), np.linspace(0, IMG_SIZE[1], IMG_SIZE[1]/BIN_SIZE)

muX = sum(X)/len(X)
muY = sum(Y)/len(Y)
sigmaX = sqrt(sum(map(lambda x: (x-muX)**2, X))/len(X))
sigmaY = sqrt(sum(map(lambda y: (y-muY)**2, Y))/len(Y))
normalX = BIN_SIZE*len(X)*mlab.normpdf(W, muX, sigmaX)
normalY = BIN_SIZE*len(Y)*mlab.normpdf(H, muY, sigmaY)

gs = gridspec.GridSpec(3, 3, width_ratios=[2, 1, 0.5], height_ratios=[2, 1, 0.5])
fig = plt.figure(1, figsize=(15, 15))
ax = fig.add_subplot(gs[0])
counts, binx, biny, img = ax.hist2d(X, Y, bins=(W, H))

ax = fig.add_subplot(gs[1])
ax.plot(normalY, H, 'r', lw=2, label="normal")
ax.hist(Y, bins=W, orientation="horizontal", histtype='stepfilled', color='y', alpha=0.5)
ax.legend()

ax = fig.add_subplot(gs[2])
ax.boxplot(Y)
ax.legend()

ax = fig.add_subplot(gs[3])
ax.plot(W, normalX, 'r', lw=2, label="normal")
ax.hist(X, bins=H, orientation="vertical", histtype='stepfilled', color='y', alpha=0.5)
ax.legend()

ax = fig.add_subplot(gs[4])
fig.colorbar(img, spacing="proportionnal")

ax = fig.add_subplot(gs[6])
ax.boxplot(X, vert=False)
ax.legend()

plt.show()



In [4]: