pyosv.post.composite

 1import numpy as np
 2from ..pre.normalizer import minmax_scaler
 3
 4def S1_RGB(s1_image : np.ndarray, clip_values_rgb : list = [0.3, 0.05, 25]) -> np.ndarray:
 5    '''
 6        Generate an RGB composite of VV and VH bands of Sentinel-1.
 7        This function works only with double raw GRD S1 data.
 8        Ref. https://gis.stackexchange.com/questions/400726/creating-composite-rgb-images-from-sentinel-1-channels
 9        
10        
11        Parameters:
12        -----------
13            - s1_image : np.ndarray 
14                WxHxB (VV and VH) Sentinel-1 data
15            - clip_values_rgb : list
16                list of clip values (max) to adjust color balance in the RGB composite (dafault [0.3, 0.05, 25])
17        
18        Returns:
19        --------
20            - nd : np.ndarray
21                WxHxB S1 RGB composite
22        
23        Usage:
24        ------
25        ```python
26        s1_image, _, _ = pyosv.io.read.load('s1.tif')
27        rgb_s1 = S1_RGB(s1_image, clip_values_rgb = [0.3, 0.05, 25])
28        ```
29
30    '''
31
32    if len(s1_image.shape) != 3:
33        raise Exception('Error: lenght of s1_image shape must be 3 - (space, space, channels)')
34    
35    if s1_image.shape[-1] != 2:
36        raise Exception('Error: s1_image channels must be 2 - (VV, VH)')
37    
38    if len(clip_values_rgb) != 3:
39        raise Exception('Error: lenght of clip_values_rgb must be 3 - (clip for R, clip for G, clip for B)')
40
41    vv_band = s1_image[:,:,0]
42    vh_band = s1_image[:,:,1]
43    # Clip values derived from [1]
44    vv_band = np.clip(vv_band, 0.0, clip_values_rgb[0])
45    vh_band = np.clip(vh_band, 0.0, clip_values_rgb[1])
46    
47    vv_band_norm = minmax_scaler(vv_band)
48    vh_band_norm = minmax_scaler(vh_band)
49
50    # Calculate ratio of VV/VH
51    ratio_band = np.divide(vv_band_norm, vh_band_norm, where=vh_band_norm != 0)
52    
53    # Clip values derived from [1]
54    ratio_band = np.clip(ratio_band, 0, clip_values_rgb[2])
55    
56    # Create RGB composite
57    rgb = np.dstack((vv_band_norm, vh_band_norm, ratio_band))
58    
59    
60    return rgb
def S1_RGB( s1_image: numpy.ndarray, clip_values_rgb: list = [0.3, 0.05, 25]) -> numpy.ndarray:
 5def S1_RGB(s1_image : np.ndarray, clip_values_rgb : list = [0.3, 0.05, 25]) -> np.ndarray:
 6    '''
 7        Generate an RGB composite of VV and VH bands of Sentinel-1.
 8        This function works only with double raw GRD S1 data.
 9        Ref. https://gis.stackexchange.com/questions/400726/creating-composite-rgb-images-from-sentinel-1-channels
10        
11        
12        Parameters:
13        -----------
14            - s1_image : np.ndarray 
15                WxHxB (VV and VH) Sentinel-1 data
16            - clip_values_rgb : list
17                list of clip values (max) to adjust color balance in the RGB composite (dafault [0.3, 0.05, 25])
18        
19        Returns:
20        --------
21            - nd : np.ndarray
22                WxHxB S1 RGB composite
23        
24        Usage:
25        ------
26        ```python
27        s1_image, _, _ = pyosv.io.read.load('s1.tif')
28        rgb_s1 = S1_RGB(s1_image, clip_values_rgb = [0.3, 0.05, 25])
29        ```
30
31    '''
32
33    if len(s1_image.shape) != 3:
34        raise Exception('Error: lenght of s1_image shape must be 3 - (space, space, channels)')
35    
36    if s1_image.shape[-1] != 2:
37        raise Exception('Error: s1_image channels must be 2 - (VV, VH)')
38    
39    if len(clip_values_rgb) != 3:
40        raise Exception('Error: lenght of clip_values_rgb must be 3 - (clip for R, clip for G, clip for B)')
41
42    vv_band = s1_image[:,:,0]
43    vh_band = s1_image[:,:,1]
44    # Clip values derived from [1]
45    vv_band = np.clip(vv_band, 0.0, clip_values_rgb[0])
46    vh_band = np.clip(vh_band, 0.0, clip_values_rgb[1])
47    
48    vv_band_norm = minmax_scaler(vv_band)
49    vh_band_norm = minmax_scaler(vh_band)
50
51    # Calculate ratio of VV/VH
52    ratio_band = np.divide(vv_band_norm, vh_band_norm, where=vh_band_norm != 0)
53    
54    # Clip values derived from [1]
55    ratio_band = np.clip(ratio_band, 0, clip_values_rgb[2])
56    
57    # Create RGB composite
58    rgb = np.dstack((vv_band_norm, vh_band_norm, ratio_band))
59    
60    
61    return rgb

Generate an RGB composite of VV and VH bands of Sentinel-1. This function works only with double raw GRD S1 data. Ref. https://gis.stackexchange.com/questions/400726/creating-composite-rgb-images-from-sentinel-1-channels

Parameters:

- s1_image : np.ndarray 
    WxHxB (VV and VH) Sentinel-1 data
- clip_values_rgb : list
    list of clip values (max) to adjust color balance in the RGB composite (dafault [0.3, 0.05, 25])

Returns:

- nd : np.ndarray
    WxHxB S1 RGB composite

Usage:

s1_image, _, _ = pyosv.io.read.load('s1.tif')
rgb_s1 = S1_RGB(s1_image, clip_values_rgb = [0.3, 0.05, 25])