Coverage for src/abm_shape_collection/get_shape_coefficients.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2024-09-25 19:34 +0000

1import numpy as np 

2from aicsshparam import shparam, shtools 

3 

4 

5def get_shape_coefficients(array: np.ndarray, reference: np.ndarray, order: int) -> dict: 

6 """ 

7 Calculate spherical harmonic coefficients for binary image array. 

8 

9 Parameters 

10 ---------- 

11 array 

12 Binary image array. 

13 reference 

14 Binary reference array that determines alignment angle. 

15 order 

16 Order of the spherical harmonics coefficient parametrization. 

17 

18 Returns 

19 ------- 

20 : 

21 Dictionary of spherical harmonics, angle, and MSE. 

22 """ 

23 

24 _, angle = shtools.align_image_2d(image=reference) 

25 aligned_array = shtools.apply_image_alignment_2d(array, angle).squeeze() 

26 

27 (coeffs, reconstructed_array), (_, _, downsampled_array, _) = shparam.get_shcoeffs( 

28 image=aligned_array, lmax=order, compute_lcc=False, alignment_2d=False 

29 ) 

30 

31 mse = shtools.get_reconstruction_error(downsampled_array, reconstructed_array) 

32 coeffs["angle"] = angle 

33 coeffs["mse"] = mse 

34 

35 return coeffs