O seguinte programa serve para calcular a quantidade de dinheiro a partir de uma imagem contendo moedas, tal como a figura acima. Note que a biblioteca PyMorph deve estar devidamente instalada no ambiente.

from numpy import array
from scipy.misc.pilutil import imsave, imread, imresize
from pymorph import add4dilate
from pymorph import binary
from pymorph import blob
from pymorph import close_holes
from pymorph import label


if __name__ == '__main__':
    f = imread('coins.bmp', flatten=True)
    binaryImage = binary(f, k=100)
    binaryImage = add4dilate(binaryImage, 8)
    binaryImage = close_holes(binaryImage)
    labeled = label(binaryImage)
    areasOfCoins = blob(labeled, 'area', output='data')
    areasOfCoins = array(areasOfCoins)
    numberOfCoins = areasOfCoins.shape[0]
    totalValue = 0.0
    for i in xrange(numberOfCoins):
        coinArea = areasOfCoins[i]
        if coinArea > 2000:
            totalValue = totalValue + 0.50
        else:
            totalValue = totalValue + 0.05
    print areasOfCoins
    print 'Total value is $%0.2f' % totalValue