pyosv.post.normalized_difference

 1import numpy as np
 2
 3def normalized_difference(channel_1 : np.ndarray, channel_2 : np.ndarray) -> np.ndarray:
 4    '''
 5        Normalized Difference
 6        
 7        nd = (channelA - channleB)/(channelA + channle_B + E)          (1)
 8        
 9        where E stabilizes the division.
10        
11        Parameters:
12        -----------
13            - channel_1 : np.ndarray 
14                channelA in equation (1)
15            - channel_2 : np.ndarray
16                channelB in equation (1)
17        
18        Returns:
19        --------
20            - nd : np.ndarray
21                normalized difference between channelA and Channelb in equation (1)            
22        
23        Usage:
24        ------
25        ```python
26        import numpy as np
27
28        ch1 = np.array(
29                    [
30                        [0.1, 0.2, 0.3],
31                        [0.4, 0.5, 0.6],
32                        [0.7, 0.8, 0.9]
33                    ]
34            )
35
36        ch2 = np.array(
37                    [
38                        [2.1, 2.2, 2.3],
39                        [2.4, 2.5, 2.6],
40                        [2.7, 2.8, 2.9]
41                    ]
42            )
43
44        nd = normalized_difference(ch1, ch2)
45        ```
46
47        Output:
48        -------
49        ```
50            [[-0.90909091 -0.83333333 -0.76923077]  
51            [-0.71428571 -0.66666667 -0.625     ]  
52            [-0.58823529 -0.55555556 -0.52631579]]  
53        ```
54
55    '''
56    
57    num = channel_1 - channel_2
58    den = channel_1 + channel_2
59    
60    nd = np.divide(num, den, where=den != 0)
61    
62    return nd
def normalized_difference(channel_1: numpy.ndarray, channel_2: numpy.ndarray) -> numpy.ndarray:
 4def normalized_difference(channel_1 : np.ndarray, channel_2 : np.ndarray) -> np.ndarray:
 5    '''
 6        Normalized Difference
 7        
 8        nd = (channelA - channleB)/(channelA + channle_B + E)          (1)
 9        
10        where E stabilizes the division.
11        
12        Parameters:
13        -----------
14            - channel_1 : np.ndarray 
15                channelA in equation (1)
16            - channel_2 : np.ndarray
17                channelB in equation (1)
18        
19        Returns:
20        --------
21            - nd : np.ndarray
22                normalized difference between channelA and Channelb in equation (1)            
23        
24        Usage:
25        ------
26        ```python
27        import numpy as np
28
29        ch1 = np.array(
30                    [
31                        [0.1, 0.2, 0.3],
32                        [0.4, 0.5, 0.6],
33                        [0.7, 0.8, 0.9]
34                    ]
35            )
36
37        ch2 = np.array(
38                    [
39                        [2.1, 2.2, 2.3],
40                        [2.4, 2.5, 2.6],
41                        [2.7, 2.8, 2.9]
42                    ]
43            )
44
45        nd = normalized_difference(ch1, ch2)
46        ```
47
48        Output:
49        -------
50        ```
51            [[-0.90909091 -0.83333333 -0.76923077]  
52            [-0.71428571 -0.66666667 -0.625     ]  
53            [-0.58823529 -0.55555556 -0.52631579]]  
54        ```
55
56    '''
57    
58    num = channel_1 - channel_2
59    den = channel_1 + channel_2
60    
61    nd = np.divide(num, den, where=den != 0)
62    
63    return nd

Normalized Difference

nd = (channelA - channleB)/(channelA + channle_B + E) (1)

where E stabilizes the division.

Parameters:

- channel_1 : np.ndarray 
    channelA in equation (1)
- channel_2 : np.ndarray
    channelB in equation (1)

Returns:

- nd : np.ndarray
    normalized difference between channelA and Channelb in equation (1)

Usage:

import numpy as np

ch1 = np.array(
            [
                [0.1, 0.2, 0.3],
                [0.4, 0.5, 0.6],
                [0.7, 0.8, 0.9]
            ]
    )

ch2 = np.array(
            [
                [2.1, 2.2, 2.3],
                [2.4, 2.5, 2.6],
                [2.7, 2.8, 2.9]
            ]
    )

nd = normalized_difference(ch1, ch2)

Output:

    [[-0.90909091 -0.83333333 -0.76923077]  
    [-0.71428571 -0.66666667 -0.625     ]  
    [-0.58823529 -0.55555556 -0.52631579]]