pyosv.utils.printer
1import numpy as np 2 3def dict_disp(dictionary : dict) -> None: 4 ''' 5 Print a dictionary in a more readable way 6 7 Parameter: 8 ---------- 9 - dictionary : dict 10 python dictionary to print 11 12 Returns: 13 -------- 14 Nothing, it will print the dictionary 15 16 Usage: 17 ------ 18 19 ```python 20 dictionary = {'Name' : 'John', 'Surname' : 'Wick'} 21 disp_dict(dictionary) 22 ``` 23 24 Output: 25 ------- 26 27 ``` 28 -----------Dictionary------------ 29 [*] Name : Johnny 30 [*] Surname : Wick 31 ``` 32 33 ''' 34 35 l_k = len([k for k in dictionary.keys() if len(str(k))==max([len(str(n)) for n in dictionary.keys()])][0]) 36 l_v = len([k for k in dictionary.values() if len(str(k))==max([len(str(n)) for n in dictionary.values()])][0]) 37 38 n = 20 + l_k + l_v 39 print('{:-^{len}}'.format('Dictionary', len=n)) 40 41 for key, value in dictionary.items(): 42 print('\t [*] {} : {}'.format(str(key), str(value))) 43 44 45def print_stats(img : np.ndarray, bandwise : bool = False) -> None: 46 ''' 47 Print some statistics for the input image 48 49 Parameters: 50 ----------- 51 - image: a WxHxB image, with width W, height H and B bands 52 - bandwise : bool 53 if true the function will print the statistics for each band separately (default : False) 54 55 Returns: 56 -------- 57 Nothing, it will print image statistics 58 59 Usage: 60 ------ 61 ```python 62 import numpy as np 63 64 img = np.array( 65 [[ 66 [0.1, 0.2, 0.3], 67 [0.4, 0.5, 0.6], 68 [0.7, 0.8, 0.9] 69 ], 70 [ 71 [1.1, 1.2, 1.3], 72 [1.4, 1.5, 1.6], 73 [1.7, 1.8, 1.9] 74 ] 75 ] 76 ) 77 78 # Making channels last 79 img = np.moveaxis(img, 0, -1) 80 81 print_stats(img, bandwise = True) 82 83 ``` 84 85 Output: 86 ------- 87 88 ``` 89 ``` 90 ''' 91 92 if len(img.shape) != 3: 93 raise Exception('Error: lenght of image shape must be 3 - (space, space, channels)') 94 95 print('{:-^{len}}'.format('Image Statistics', len=50)) 96 print('{:<20s}{}'.format('[*] Shape', img.shape)) 97 98 if bandwise: 99 for i in range(img.shape[-1]): 100 print('{:<20s}'.format('Band '+str(i))) 101 print('\t{:<20s}{:<30s}'.format('[*] Max', str(np.max(img[:, :, i])))) 102 print('\t{:<20s}{:<30s}'.format('[*] Min', str(np.min(img[:, :, i])))) 103 print('\t{:<20s}{:<30s}'.format('[*] Mean', str(np.mean(img[:, :, i])))) 104 print('\t{:<20s}{:<30s}'.format('[*] Std', str(np.std(img[:, :, i])))) 105 print('\t{:<20s}{:<30s}'.format('[*] Med', str(np.median(img[:, :, i])))) 106 else: 107 print('{:<20s}{:<30s}'.format('[*] Max', str(np.max(img)))) 108 print('{:<20s}{:<30s}'.format('[*] Min', str(np.min(img)))) 109 print('{:<20s}{:<30s}'.format('[*] Mean', str(np.mean(img)))) 110 print('{:<20s}{:<30s}'.format('[*] Std', str(np.std(img)))) 111 print('{:<20s}{:<30s}'.format('[*] Med', str(np.median(img))))
def
dict_disp(dictionary: dict) -> None:
4def dict_disp(dictionary : dict) -> None: 5 ''' 6 Print a dictionary in a more readable way 7 8 Parameter: 9 ---------- 10 - dictionary : dict 11 python dictionary to print 12 13 Returns: 14 -------- 15 Nothing, it will print the dictionary 16 17 Usage: 18 ------ 19 20 ```python 21 dictionary = {'Name' : 'John', 'Surname' : 'Wick'} 22 disp_dict(dictionary) 23 ``` 24 25 Output: 26 ------- 27 28 ``` 29 -----------Dictionary------------ 30 [*] Name : Johnny 31 [*] Surname : Wick 32 ``` 33 34 ''' 35 36 l_k = len([k for k in dictionary.keys() if len(str(k))==max([len(str(n)) for n in dictionary.keys()])][0]) 37 l_v = len([k for k in dictionary.values() if len(str(k))==max([len(str(n)) for n in dictionary.values()])][0]) 38 39 n = 20 + l_k + l_v 40 print('{:-^{len}}'.format('Dictionary', len=n)) 41 42 for key, value in dictionary.items(): 43 print('\t [*] {} : {}'.format(str(key), str(value)))
Print a dictionary in a more readable way
Parameter:
- dictionary : dict
python dictionary to print
Returns:
Nothing, it will print the dictionary
Usage:
dictionary = {'Name' : 'John', 'Surname' : 'Wick'}
disp_dict(dictionary)
Output:
-----------Dictionary------------
[*] Name : Johnny
[*] Surname : Wick
def
print_stats(img: numpy.ndarray, bandwise: bool = False) -> None:
46def print_stats(img : np.ndarray, bandwise : bool = False) -> None: 47 ''' 48 Print some statistics for the input image 49 50 Parameters: 51 ----------- 52 - image: a WxHxB image, with width W, height H and B bands 53 - bandwise : bool 54 if true the function will print the statistics for each band separately (default : False) 55 56 Returns: 57 -------- 58 Nothing, it will print image statistics 59 60 Usage: 61 ------ 62 ```python 63 import numpy as np 64 65 img = np.array( 66 [[ 67 [0.1, 0.2, 0.3], 68 [0.4, 0.5, 0.6], 69 [0.7, 0.8, 0.9] 70 ], 71 [ 72 [1.1, 1.2, 1.3], 73 [1.4, 1.5, 1.6], 74 [1.7, 1.8, 1.9] 75 ] 76 ] 77 ) 78 79 # Making channels last 80 img = np.moveaxis(img, 0, -1) 81 82 print_stats(img, bandwise = True) 83 84 ``` 85 86 Output: 87 ------- 88 89 ``` 90 ``` 91 ''' 92 93 if len(img.shape) != 3: 94 raise Exception('Error: lenght of image shape must be 3 - (space, space, channels)') 95 96 print('{:-^{len}}'.format('Image Statistics', len=50)) 97 print('{:<20s}{}'.format('[*] Shape', img.shape)) 98 99 if bandwise: 100 for i in range(img.shape[-1]): 101 print('{:<20s}'.format('Band '+str(i))) 102 print('\t{:<20s}{:<30s}'.format('[*] Max', str(np.max(img[:, :, i])))) 103 print('\t{:<20s}{:<30s}'.format('[*] Min', str(np.min(img[:, :, i])))) 104 print('\t{:<20s}{:<30s}'.format('[*] Mean', str(np.mean(img[:, :, i])))) 105 print('\t{:<20s}{:<30s}'.format('[*] Std', str(np.std(img[:, :, i])))) 106 print('\t{:<20s}{:<30s}'.format('[*] Med', str(np.median(img[:, :, i])))) 107 else: 108 print('{:<20s}{:<30s}'.format('[*] Max', str(np.max(img)))) 109 print('{:<20s}{:<30s}'.format('[*] Min', str(np.min(img)))) 110 print('{:<20s}{:<30s}'.format('[*] Mean', str(np.mean(img)))) 111 print('{:<20s}{:<30s}'.format('[*] Std', str(np.std(img)))) 112 print('{:<20s}{:<30s}'.format('[*] Med', str(np.median(img))))
Print some statistics for the input image
Parameters:
- image: a WxHxB image, with width W, height H and B bands
- bandwise : bool
if true the function will print the statistics for each band separately (default : False)
Returns:
Nothing, it will print image statistics
Usage:
import numpy as np
img = np.array(
[[
[0.1, 0.2, 0.3],
[0.4, 0.5, 0.6],
[0.7, 0.8, 0.9]
],
[
[1.1, 1.2, 1.3],
[1.4, 1.5, 1.6],
[1.7, 1.8, 1.9]
]
]
)
# Making channels last
img = np.moveaxis(img, 0, -1)
print_stats(img, bandwise = True)
Output: