Calling filter functions from a block processing function

I have some intense memory filters that I want to call block by block on large images / arrays (because they calculate the filter for the whole array, they run out of memory when trying to calculate the whole array).

def block_process(Ic, blocksize):
    B = numpy.empty(Ic.shape)

    colstart = 0
    while colstart < Ic.shape[1]:
        BlockWidth = blocksize
        if (colstart + blocksize) > Ic.shape[1]:
            BlockWidth = Ic.shape[1] - colstart
        rowstart = 0
        while rowstart < Ic.shape[0]:
            BlockHeight = blocksize
            if (rowstart + blocksize) > Ic.shape[0]:
                BlockHeight = Ic.shape[0] - rowstart

            B[colstart:colstart+BlockWidth, rowstart:rowstart+BlockHeight] = filter1(params) # One of many available filters

            rowstart += BlockHeight
        colstart += BlockWidth
    return B # The complete filtered array

My filters are calculated in other functions, i.e. def filter1(A, filtsize), def filter2(A, filtsize, otherparam)that have a parameter A(an input array specified by a block function) and other parameters, such as the size of the filter. Some filters have more options than others. They return a filtered array.

Two questions

  • block_process? . , , ( ) block_process()?
  • ?
0
1

:

def block_process(a, blocksize, filt, args):
    b = numpy.empty(a.shape)
    for row in xrange(0, a.shape[0], blocksize):
        for col in xrange(0, a.shape[1], blocksize):
            b[row:row + blocksize, col:col + blocksize] = (
                filt(a[row:row + blocksize, col:col + blocksize], *args))
    return b

- . . filter1(a, filtsize),

block_process(a, blocksize, filter1, (filtsize,))

, - , , .

, , , - .

+2

Source: https://habr.com/ru/post/1791253/


All Articles