Example #1
0
def vector_subphog(X, Y, W, H, grayscale, grayD):
    #from numpy.ma import MaskedArray
    #import scipy.stats
    
    subhistogram = numpy.zeros(PHOG_BINS, dtype="double")
    subphog = grayscale[X:(X+W), Y:(Y+H)] < 50
    #bindex = numpy.floor((MaskedArray(grayD, mask=subphog) / numpy.pi + 0.5) * PHOG_BINS).astype('int')
    # bins = numpy.bincount(numpy.where(bindex == PHOG_BINS, 0, bindex))
    
    print_array_info(grayD, title="grayD")
    print_array_info(subphog, title="subphog")
    #print_array_info(bindex, title="bindex")
    
    subdirectionals = (grayD[subphog] / numpy.pi + 0.5) * PHOG_BINS
    histo = numpy.bincount(
        numpy.where(
            subdirectionals.astype('int') == PHOG_BINS,
            0, subdirectionals.astype('int')))
    
    print_array_info(histo, title="HISTOGRAM (grayD[subphog])")
    # print_array_info(bins, title="BINS")
    
    
    
    # print("BINDEXES:")
    # print(numpy.array_repr(bindexes, max_line_width=200))
    # print("max: %s min: %s" % (numpy.max(bindexes), numpy.min(bindexes)))
    
    #return
    
    # yo = numpy.where(numpy.floor(bindexfp) == PHOG_BINS, 0, numpy.floor(bindexfp))
    # bindexes = numpy.where(bindexfp == numpy.floor(bindexfp),
    #     (numpy.floor(bindexfp).astype('int'), 1),
    #     (numpy.floor(bindexfp).astype('int'), bindexfp - numpy.floor(bindexfp)))
    # bindexes = numpy.zeros_like(subphog)
    # bindexes += numpy.where(values == numpy.floor(values).astype('int'),
    #     1, (values - numpy.floor(values)))
    # bindexes += numpy.where(values == numpy.ceil(values).astype('int'),
    #     0, (numpy.ceil(values) - values))
    # print("BINDEXES:")
    # print(bindexes)
    # return
    
    # "normalize histogram to max norm."
    # NB. this piece is actually vectorized
    histomax = numpy.max(subhistogram)
    if histomax > 0.0:
        subhistogram = numpy.minimum(
            QUANTIZATION_FACTOR,
            numpy.floor(
                QUANTIZATION_FACTOR * subhistogram / histomax))
    
    return subhistogram
Example #2
0
 def timetest_cythonized_HOG(ndim):
     hogg = hog(ndim)
     print("Cythonized HOG() function:")
     print_array_info(hogg)
     print("")