scripts/FilterBank.py
def patch_stats(image, grid_w, grid_h):
    '''
    A simple function which takes an image, divides it
    into a (grid_y x grid_x) grid of patches, and iterates
    over the patches, computing per-patch statistics.
    
    In the special case of grid_x=grid_y=1, stats are for the whole image.
    '''
    
    pix_h = image.shape[0] # number of pixels
    pix_w = image.shape[1]
    
    gridsize = grid_w*grid_h
    
    dh = math.floor(pix_h/grid_h) # typical (non-edge) patch sizes
    dw = math.floor(pix_w/grid_w)
    
    meanvec = np.zeros(gridsize, dtype=np.float32) # initialize vectors to hold the stats
    medvec = np.zeros(gridsize, dtype=np.float32)
    maxvec = np.zeros(gridsize, dtype=np.float32)
    minvec = np.zeros(gridsize, dtype=np.float32)
    
    # Loop over the patches, starting at the top-left, and doing one grid row at a time.
    idx = 0
    for i in range(grid_h):
        
        start_h = i * dh
        if (i+1 == grid_h):
            stop_h = pix_h
        else:
            stop_h = start_h + dh
        
        for j in range(grid_w):
            
            start_w = j * dw
            if (j+1 == grid_w):
                stop_w = pix_w
            else:
                stop_w = start_w + dw
            
            patch = image[start_h:stop_h, start_w:stop_w]
            meanvec[idx] = np.mean(patch) # patch mean
            medvec[idx] = np.median(patch) # patch median
            maxvec[idx] = np.max(patch) # patch maximum
            minvec[idx] = np.min(patch) # patch minimum
            idx += 1
    
    return {"mean": meanvec, "med": medvec, "max": maxvec, "min": minvec}

    A simple function which takes an image, divides it
    into a (grid_y x grid_x) grid of patches, and iterates
    over the patches, computing per-patch statistics.
    
    In the special case of grid_x=grid_y=1, stats are for the whole image.
    
A simple function which takes an image, divides it
into a (grid_y x grid_x) grid of patches, and iterates
over the patches, computing per-patch statistics.

In the special case of grid_x=grid_y=1, stats are for the whole image.
A simple function which takes an image divides it into a ( grid_y x grid_x ) grid of patches and iterates over the patches computing per - patch statistics . In the special case of grid_x = grid_y = 1 stats are for the whole image .
def patch_stats(image, grid_w, grid_h):
    pix_h = image.shape[0] 
    pix_w = image.shape[1]
    gridsize = grid_w*grid_h
    dh = math.floor(pix_h/grid_h) 
    dw = math.floor(pix_w/grid_w)
    meanvec = np.zeros(gridsize, dtype=np.float32) 
    medvec = np.zeros(gridsize, dtype=np.float32)
    maxvec = np.zeros(gridsize, dtype=np.float32)
    minvec = np.zeros(gridsize, dtype=np.float32)
    idx = 0
    for i in range(grid_h):
        start_h = i * dh
        if (i+1 == grid_h):
            stop_h = pix_h
        else:
            stop_h = start_h + dh
        for j in range(grid_w):
            start_w = j * dw
            if (j+1 == grid_w):
                stop_w = pix_w
            else:
                stop_w = start_w + dw
            patch = image[start_h:stop_h, start_w:stop_w]
            meanvec[idx] = np.mean(patch) 
            medvec[idx] = np.median(patch) 
            maxvec[idx] = np.max(patch) 
            minvec[idx] = np.min(patch) 
            idx += 1
    return {"mean": meanvec, "med": medvec, "max": maxvec, "min": minvec}
def patch_stats ( image , grid_w , grid_h ) : pix_h = image . shape [ 0 ] pix_w = image . shape [ 1 ] gridsize = grid_w * grid_h dh = math . floor ( pix_h / grid_h ) dw = math . floor ( pix_w / grid_w ) meanvec = np . zeros ( gridsize , dtype = np . float32 ) medvec = np . zeros ( gridsize , dtype = np . float32 ) maxvec = np . zeros ( gridsize , dtype = np . float32 ) minvec = np . zeros ( gridsize , dtype = np . float32 ) idx = 0 for i in range ( grid_h ) : start_h = i * dh if ( i + 1 == grid_h ) : stop_h = pix_h else : stop_h = start_h + dh for j in range ( grid_w ) : start_w = j * dw if ( j + 1 == grid_w ) : stop_w = pix_w else : stop_w = start_w + dw patch = image [ start_h : stop_h , start_w : stop_w ] meanvec [ idx ] = np . mean ( patch ) medvec [ idx ] = np . median ( patch ) maxvec [ idx ] = np . max ( patch ) minvec [ idx ] = np . min ( patch ) idx += 1 return { "mean" : meanvec , "med" : medvec , "max" : maxvec , "min" : minvec }
A simple function which takes an image, divides it
into a (grid_y x grid_x) grid of patches, and iterates
over the patches, computing per-patch statistics.
A simple function which takes an image divides it into a ( grid_y x grid_x ) grid of patches and iterates over the patches computing per - patch statistics .
'''
    A simple function which takes an image, divides it
    into a (grid_y x grid_x) grid of patches, and iterates
    over the patches, computing per-patch statistics.
    
    In the special case of grid_x=grid_y=1, stats are for the whole image.
    ''' # number of pixels # typical (non-edge) patch sizes # initialize vectors to hold the stats # Loop over the patches, starting at the top-left, and doing one grid row at a time. # patch mean # patch median # patch maximum # patch minimum
image
grid_w
grid_h