import rastereasy
Read image
name_im='./data/demo/sentinel.tif'
image=rastereasy.Geoimage(name_im)
image.info()
image.colorcomp(extent='pixel',title='original image')
- Size of the image:
   - Rows (height): 1000
   - Cols (width): 1000
   - Bands: 12
- Spatial resolution: 10.0  meters / degree (depending on projection system)
- Central point latitude - longitude coordinates: (7.04099599, 38.39058840)
- Driver: GTiff
- Data type: int16
- Projection system: EPSG:32637
- Nodata: -32768.0
- Given names for spectral bands: 
   {'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10, '11': 11, '12': 12}
Infos on filters
help(image.filter)
Help on method filter in module rastereasy.rastereasy:
filter(method='generic', kernel=None, sigma=1, size=3, axis=-1, pre_smooth_sigma=None, inplace=False, dest_name=None) method of rastereasy.rastereasy.Geoimage instance
    Apply a spatial filter to the Geoimage.
    
    Parameters
    ----------
    method : str, default="generic"
        Type of filter. Options:
        - "generic" : Generic convolution with a kernel.
        - "gaussian" : Gaussian filter.
        - "median"   : Median filter.
        - "sobel"    : Sobel edge detection (discrete operator).
        - "laplace"  : Laplacian operator (discrete operator).
    
    kernel : numpy.ndarray, optional
        Convolution kernel (required if mode="generic").
    
    sigma : float, default=1
        Standard deviation for Gaussian filter (if mode="gaussian").
    
    size : int, default=3
        Size of the filter window (for median).
    
    axis : int, default=-1
        Axis along which to compute the Sobel filter (if mode="sobel").
        It is 0 for x, 1 for y. If None, computes gradient magnitude.
    
    pre_smooth_sigma : float or None, default=None
        If set (e.g., 1.0 or 2.0), a Gaussian filter is applied before Sobel or Laplace,
        useful to reduce noise and simulate larger kernels.
    
    inplace : bool, default False
        If False, returns a new Geoimage instance with the filtered data.
        If True, modifies the current image in place.
    
    dest_name : str, optional
        Path to save the filtered image. If None, the image is not saved.
        Default is None.
    
    Returns
    -------
    Geoimage
        A new filtered Geoimage if inplace=False, otherwise self.
    
    Raises
    ------
    ValueError
        If `method` is unknown.
    
    Examples
    --------
    >>> # Create a gaussian with sigma = 8
    >>> imf = image.filter("gaussian", sigma=8)
    >>> # Create a median with size = 7
    >>> imf = image.filter("median", size=7)
    >>> # Create a sobel in x-axis
    >>> imf = image.filter("sobel", axis=0)
    >>> # Create a sobel in y-axis
    >>> imf = image.filter("sobel", axis=1)
    >>> # Create the norm of sobel
    >>> imf = image.filter("sobel")
    >>> # Create a sobel in x-axis with pre_smooth_sigma = 2
    >>> imf = image.filter("sobel", axis=0, pre_smooth_sigma=2)
    >>> # Create a sobel in y-axis with pre_smooth_sigma = 2
    >>> imf = image.filter("sobel", axis=1, pre_smooth_sigma=2)
    >>> # Create the norm of sobel with pre_smooth_sigma = 2
    >>> imf = image.filter("sobel", pre_smooth_sigma=2))
    >>> # Create a laplacian filter
    >>> imf = image.filter("laplace")
    >>> # Create a laplacian filter pre_smooth_sigma = 2
    >>> imf = image.filter("laplace", pre_smooth_sigma=2)
Apply a gaussian filter
imf = image.filter("gaussian", sigma=8)
imf.colorcomp()
imf.info()
- Size of the image:
   - Rows (height): 1000
   - Cols (width): 1000
   - Bands: 12
- Spatial resolution: 10.0  meters / degree (depending on projection system)
- Central point latitude - longitude coordinates: (7.04099599, 38.39058840)
- Driver: GTiff
- Data type: float64
- Projection system: EPSG:32637
- Nodata: -32768.0
- Given names for spectral bands: 
   {'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10, '11': 11, '12': 12}
Apply a median filter
imf = image.filter("median", size=5)
imf.colorcomp()
imf.info()
- Size of the image:
   - Rows (height): 1000
   - Cols (width): 1000
   - Bands: 12
- Spatial resolution: 10.0  meters / degree (depending on projection system)
- Central point latitude - longitude coordinates: (7.04099599, 38.39058840)
- Driver: GTiff
- Data type: int16
- Projection system: EPSG:32637
- Nodata: -32768.0
- Given names for spectral bands: 
   {'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10, '11': 11, '12': 12}
Apply a sobel filter
Without pre-smoothing the image
# on x-axis
imf = image.filter("sobel", axis=0)
imf.colorcomp()
imf.info()
- Size of the image:
   - Rows (height): 1000
   - Cols (width): 1000
   - Bands: 12
- Spatial resolution: 10.0  meters / degree (depending on projection system)
- Central point latitude - longitude coordinates: (7.04099599, 38.39058840)
- Driver: GTiff
- Data type: float64
- Projection system: EPSG:32637
- Nodata: -32768.0
- Given names for spectral bands: 
   {'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10, '11': 11, '12': 12}
# on y-axis
imf = image.filter("sobel", axis=1)
imf.colorcomp()
imf.info()
- Size of the image:
   - Rows (height): 1000
   - Cols (width): 1000
   - Bands: 12
- Spatial resolution: 10.0  meters / degree (depending on projection system)
- Central point latitude - longitude coordinates: (7.04099599, 38.39058840)
- Driver: GTiff
- Data type: float64
- Projection system: EPSG:32637
- Nodata: -32768.0
- Given names for spectral bands: 
   {'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10, '11': 11, '12': 12}
# norm of the vector
imf = image.filter("sobel")
imf.colorcomp()
imf.info()
- Size of the image:
   - Rows (height): 1000
   - Cols (width): 1000
   - Bands: 12
- Spatial resolution: 10.0  meters / degree (depending on projection system)
- Central point latitude - longitude coordinates: (7.04099599, 38.39058840)
- Driver: GTiff
- Data type: float64
- Projection system: EPSG:32637
- Nodata: -32768.0
- Given names for spectral bands: 
   {'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10, '11': 11, '12': 12}
With pre-smoothing the image
# on x-axis
imf = image.filter("sobel", axis=0, pre_smooth_sigma=4)
imf.colorcomp()
imf.info()
- Size of the image:
   - Rows (height): 1000
   - Cols (width): 1000
   - Bands: 12
- Spatial resolution: 10.0  meters / degree (depending on projection system)
- Central point latitude - longitude coordinates: (7.04099599, 38.39058840)
- Driver: GTiff
- Data type: float64
- Projection system: EPSG:32637
- Nodata: -32768.0
- Given names for spectral bands: 
   {'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10, '11': 11, '12': 12}
# on y-axis
imf = image.filter("sobel", axis=1,  pre_smooth_sigma=4)
imf.colorcomp()
imf.info()
- Size of the image:
   - Rows (height): 1000
   - Cols (width): 1000
   - Bands: 12
- Spatial resolution: 10.0  meters / degree (depending on projection system)
- Central point latitude - longitude coordinates: (7.04099599, 38.39058840)
- Driver: GTiff
- Data type: float64
- Projection system: EPSG:32637
- Nodata: -32768.0
- Given names for spectral bands: 
   {'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10, '11': 11, '12': 12}
Apply a Laplacian filter
Without pre-smoothing the image
imf = image.filter("laplace")
imf.colorcomp()
imf.info()
- Size of the image:
   - Rows (height): 1000
   - Cols (width): 1000
   - Bands: 12
- Spatial resolution: 10.0  meters / degree (depending on projection system)
- Central point latitude - longitude coordinates: (7.04099599, 38.39058840)
- Driver: GTiff
- Data type: float64
- Projection system: EPSG:32637
- Nodata: -32768.0
- Given names for spectral bands: 
   {'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10, '11': 11, '12': 12}
## With pre-smoothing the image
imf = image.filter("laplace", pre_smooth_sigma=9)
imf.colorcomp()
imf.info()
- Size of the image:
   - Rows (height): 1000
   - Cols (width): 1000
   - Bands: 12
- Spatial resolution: 10.0  meters / degree (depending on projection system)
- Central point latitude - longitude coordinates: (7.04099599, 38.39058840)
- Driver: GTiff
- Data type: float64
- Projection system: EPSG:32637
- Nodata: -32768.0
- Given names for spectral bands: 
   {'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10, '11': 11, '12': 12}
Apply a generic filter
Create a generic filter (example here : average 9x9)
import numpy as np
blur_kernel = np.ones((9, 9)) / (81)
Filter the image and create a new image (with inplace=False, default)
image_filtered=image.filter(method="generic", kernel=blur_kernel)
image_filtered.colorcomp(extent='pixel', title='filtered image')
image_filtered.info()
- Size of the image:
   - Rows (height): 1000
   - Cols (width): 1000
   - Bands: 12
- Spatial resolution: 10.0  meters / degree (depending on projection system)
- Central point latitude - longitude coordinates: (7.04099599, 38.39058840)
- Driver: GTiff
- Data type: float64
- Projection system: EPSG:32637
- Nodata: -32768.0
- Given names for spectral bands: 
   {'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10, '11': 11, '12': 12}
Show some details
image.colorcomp(zoom=((200,300),(200,300)),extent='pixel',title='zoom original image')
image_filtered.colorcomp(zoom=((200,300),(200,300)),extent='pixel', title='zoom filtered image')
Filter the image and modify it (with inplace=True)
blur_kernel = np.ones((15, 15)) / (15*15)
image.colorcomp(extent='pixel',title='image before filter')
image.filter(method="generic", kernel=blur_kernel,dest_name='generic_filter.tif',inplace=True)
image.colorcomp(extent='pixel',title='image after filter')