modules/motion.py
def prune_stack(imstack, ecc_mats, full_res, thres=None):
    '''
        Prune a stack of images which are not well registered.
        
        Inputs:
            imstack: nimg x H x W stack of images
            ecc_mats: nimg x 2 x 3 stack of transformation matrices
            full_res: Full resolution size
            thres: Threshold of registration error to consider when rejecting 
                images. If None, 2*median(error_array) is used
                
        Outputs:
            imstack: nimg_good x H x W stack of good images
            ecc_mats: nimg_good x 2 x 3 stack of good transformation matrices
    '''
    nimg, Hl, Wl = imstack.shape
    H, W = full_res
    
    if thres is None:
        thres = 1

    imref = cv2.resize(imstack[0, ...], (W, H), interpolation=cv2.INTER_AREA)
    imten = torch.tensor(imref).cuda()[None, None, ...]
    imstack_ten = torch.tensor(imstack).cuda()[:, None, ...]
    imten = torch.repeat_interleave(imten, int(nimg), 0)
    
    mat = torch.tensor(ecc_mats.astype(np.float32)).cuda()
    imtrans = kornia.warp_affine(imten, mat, (Hl, Wl))
    
    imdiff = abs(imtrans - imstack_ten).cpu()[:, 0, ...]
    diff_array = (imdiff/(imstack + 1e-2*imstack.max())).mean(-1).mean(-1)
    mask = diff_array < thres
    
    imstack = np.copy(imstack[mask == 1, ...], order='C')
    ecc_mats = np.copy(ecc_mats[mask == 1, ...], order='C')
    imdiff = imdiff[mask == 1, ...]
    
    return imstack, ecc_mats, mask, imdiff

        Prune a stack of images which are not well registered.
        
        Inputs:
            imstack: nimg x H x W stack of images
            ecc_mats: nimg x 2 x 3 stack of transformation matrices
            full_res: Full resolution size
            thres: Threshold of registration error to consider when rejecting 
                images. If None, 2*median(error_array) is used
                
        Outputs:
            imstack: nimg_good x H x W stack of good images
            ecc_mats: nimg_good x 2 x 3 stack of good transformation matrices
    
Prune a stack of images which are not well registered.

nimg_good x H x W stack of good images
ecc_mats: nimg_good x 2 x 3 stack of good transformation matrices
Prune a stack of images which are not well registered . nimg_good x H x W stack of good images ecc_mats : nimg_good x 2 x 3 stack of good transformation matrices
def prune_stack(imstack, ecc_mats, full_res, thres=None):
    nimg, Hl, Wl = imstack.shape
    H, W = full_res
    if thres is None:
        thres = 1
    imref = cv2.resize(imstack[0, ...], (W, H), interpolation=cv2.INTER_AREA)
    imten = torch.tensor(imref).cuda()[None, None, ...]
    imstack_ten = torch.tensor(imstack).cuda()[:, None, ...]
    imten = torch.repeat_interleave(imten, int(nimg), 0)
    mat = torch.tensor(ecc_mats.astype(np.float32)).cuda()
    imtrans = kornia.warp_affine(imten, mat, (Hl, Wl))
    imdiff = abs(imtrans - imstack_ten).cpu()[:, 0, ...]
    diff_array = (imdiff/(imstack + 1e-2*imstack.max())).mean(-1).mean(-1)
    mask = diff_array < thres
    imstack = np.copy(imstack[mask == 1, ...], order='C')
    ecc_mats = np.copy(ecc_mats[mask == 1, ...], order='C')
    imdiff = imdiff[mask == 1, ...]
    return imstack, ecc_mats, mask, imdiff
def prune_stack ( imstack , ecc_mats , full_res , thres = None ) : nimg , Hl , Wl = imstack . shape H , W = full_res if thres is None : thres = 1 imref = cv2 . resize ( imstack [ 0 , ... ] , ( W , H ) , interpolation = cv2 . INTER_AREA ) imten = torch . tensor ( imref ) . cuda ( ) [ None , None , ... ] imstack_ten = torch . tensor ( imstack ) . cuda ( ) [ : , None , ... ] imten = torch . repeat_interleave ( imten , int ( nimg ) , 0 ) mat = torch . tensor ( ecc_mats . astype ( np . float32 ) ) . cuda ( ) imtrans = kornia . warp_affine ( imten , mat , ( Hl , Wl ) ) imdiff = abs ( imtrans - imstack_ten ) . cpu ( ) [ : , 0 , ... ] diff_array = ( imdiff / ( imstack + 1e-2 * imstack . max ( ) ) ) . mean ( - 1 ) . mean ( - 1 ) mask = diff_array < thres imstack = np . copy ( imstack [ mask == 1 , ... ] , order = 'C' ) ecc_mats = np . copy ( ecc_mats [ mask == 1 , ... ] , order = 'C' ) imdiff = imdiff [ mask == 1 , ... ] return imstack , ecc_mats , mask , imdiff
Prune a stack of images which are not well registered.
Prune a stack of images which are not well registered .
'''
        Prune a stack of images which are not well registered.
        
        Inputs:
            imstack: nimg x H x W stack of images
            ecc_mats: nimg x 2 x 3 stack of transformation matrices
            full_res: Full resolution size
            thres: Threshold of registration error to consider when rejecting 
                images. If None, 2*median(error_array) is used
                
        Outputs:
            imstack: nimg_good x H x W stack of good images
            ecc_mats: nimg_good x 2 x 3 stack of good transformation matrices
    '''
imstack
ecc_mats
full_res
thres