示例#1
0
def test_haar2d():
    """
    Asserts that some basic test cases are correct.
    
    """

    assert haar2d(np.random.random([5,3]),2,debug=True).shape == (8,4), "Transform data must be padded to compatible shape."
    assert haar2d(np.random.random([8,4]),2,debug=True).shape == (8,4), "Transform data must be padded to compatible shape, only if neccersary."

    image = np.random.random([5,3])
    haart = haar2d(image, 3, debug=False)
    haari = ihaar2d(haart, 3, debug=False)[:image.shape[0], :image.shape[1]]
    assert (image - haari < 0.0001).all(), "Transform must be circular."
示例#2
0
def test_haar2d():
    """
    Asserts the forwards and inverse wavelet transformations are correct. 
    """

    assert haar2d.haar2d(np.random.random([5,3]),2,debug=True).shape == (8,4), \
        "Transform data must be padded to compatible shape."
    
    assert haar2d.haar2d(np.random.random([8,4]),2,debug=True).shape == (8,4), \
        "Transform data must be padded to compatible shape, if required."

    image = np.random.random([5,3])
    
    haart = haar2d.haar2d(image, 3)
    haari = haar2d.ihaar2d(haart, 3)[:image.shape[0], :image.shape[1]]
    
    assert (image - haari < 0.0001).all(), "Transform must be circular."
示例#3
0
def _detectHaarFeatures(image, options={}):
    if options is None:
        options = _haarDefaultOptions(image)
    levels = options.get('levels')   
    maxpoints = options.get('maxpoints')
    threshold = options.get('threshold')
    locality = options.get('locality')
    
    haarData = haar2d(image, levels)

    avgRows = haarData.shape[0] / 2 ** levels
    avgCols = haarData.shape[1] / 2 ** levels
    
    SalientPoints = {}
    
    siloH = np.zeros([haarData.shape[0]/2, haarData.shape[1]/2, levels])
    siloD = np.zeros([haarData.shape[0]/2, haarData.shape[1]/2, levels])
    siloV = np.zeros([haarData.shape[0]/2, haarData.shape[1]/2, levels])
    
    # Build the saliency silos
    for i in range(levels):
        level = i + 1
        halfRows = haarData.shape[0] / 2 ** level
        halfCols = haarData.shape[1] / 2 ** level
        siloH[:,:,i] = nd.zoom(haarData[:halfRows, halfCols:halfCols*2], 2**(level-1)) 
        siloD[:,:,i] = nd.zoom(haarData[halfRows:halfRows*2, halfCols:halfCols*2], 2**(level-1)) 
        siloV[:,:,i] = nd.zoom(haarData[halfRows:halfRows*2, :halfCols], 2**(level-1)) 
    
    # Calculate saliency heat-map
    saliencyMap = np.max(np.array([
                                np.sum(np.abs(siloH), axis=2), 
                                np.sum(np.abs(siloD), axis=2),
                                np.sum(np.abs(siloV), axis=2)
                                ]), axis=0)
                               
    # Determine global maximum and saliency threshold
    maximum = np.max(saliencyMap)
    sthreshold = threshold * maximum
    
    # Extract features by finding local maxima
    rows = haarData.shape[0] / 2
    cols = haarData.shape[1] / 2
    features = {}
    id = 0
    for row in range(locality,rows-locality):
        for col in range(locality,cols-locality):
            saliency = saliencyMap[row,col]
            if saliency > sthreshold:
                if  saliency >= np.max(saliencyMap[row-locality:row+locality, col-locality:col+locality]):
                    features[id] = (row*2,col*2)
                    id += 1

    result = {}
    result['points'] = features
    return result