def apply_transform(x, transform_matrix, channel_index=2, fill_mode='nearest', cval=0.0):
 x = np.rollaxis(x, channel_index, 0)
 final_affine_matrix = transform_matrix[:2, :2]
 final_offset = transform_matrix[:2, 2]
 channel_images = [ndi.interpolation.affine_transform(x_channel, final_affine_matrix, final_offset, order=0, mode=fill_mode, cval=cval) for x_channel in x]
 x = np.stack(channel_images, axis=0)
 x = np.rollaxis(x, 0, (channel_index + 1))
 return x

def apply_transform ( x , transform_matrix , channel_index = 2 , fill_mode = 'nearest' , cval = 0.0 ) : x = np . rollaxis ( x , channel_index , 0 ) final_affine_matrix = transform_matrix [ : 2 , : 2 ] final_offset = transform_matrix [ : 2 , 2 ] channel_images = [ ndi . interpolation . affine_transform ( x_channel , final_affine_matrix , final_offset , order = 0 , mode = fill_mode , cval = cval ) for x_channel in x ] x = np . stack ( channel_images , axis = 0 ) x = np . rollaxis ( x , 0 , ( channel_index + 1 ) ) return x
return transformed images by given transform_matrix from transform_matrix_offset_center .