def imfill(immsk):
    '''fill the empty patches of image mask 'immsk' '''

    for iz in range(immsk.shape[0]):
        for iy in range(immsk.shape[1]):
            ix0 = np.argmax(immsk[iz,iy,:]>0)
            ix1 = immsk.shape[2] - np.argmax(immsk[iz,iy,::-1]>0)
            if (ix1-ix0) > immsk.shape[2]-10: continue
            immsk[iz,iy,ix0:ix1] = 1
    return immsk
def imfill ( immsk ) : for iz in range ( immsk . shape [ 0 ] ) : for iy in range ( immsk . shape [ 1 ] ) : ix0 = np . argmax ( immsk [ iz , iy , : ] > 0 ) ix1 = immsk . shape [ 2 ] - np . argmax ( immsk [ iz , iy , : : - 1 ] > 0 ) if ( ix1 - ix0 ) > immsk . shape [ 2 ] - 10 : continue immsk [ iz , iy , ix0 : ix1 ] = 1 return immsk
fill the empty patches of image mask 'immsk'