RSGISLib Image Change Detection

Classification Outlier Change Detection

rsgislib.changedetect.pxloutlierchng.find_class_pyod_outliers(pyod_obj, input_img: str, in_msk_img: str, output_img: str, out_scores_img: str = None, img_mask_val: int = 1, img_bands: List[int] = None, gdalformat: str = 'KEA')

This function uses the pyod (https://github.com/yzhao062/pyod) library to find outliers within a class. It is assumed that the input images are from a different date than the mask (classification) and therefore the outliers will be related to class changes.

Parameters:
  • pyod_obj – an instance of a pyod.models (e.g., pyod.models.knn.KNN) pass parameters to the constructor

  • input_img – input image used for analysis

  • in_msk_img – input image mask use to define the region of interest.

  • output_img – output image with pixel over of 1 for within mask but not outlier and 2 for in mask and outlier.

  • out_scores_img – output image (optional, None and won’t be provided; Default None) providing the probability of each pixel being an outlier

  • img_mask_val – the pixel value within the mask image for the class of interest. (Default 1)

  • img_bands – the image bands to be used for the analysis. If None then all used (Default: None)

  • gdalformat – file format for the output image(s). Default KEA.

rsgislib.changedetect.pxloutlierchng.find_class_kurt_skew_outliers(input_img: str, in_msk_img: str, output_img: str, vld_min: float, vld_max: float, init_thres: float, low_thres: bool, contamination: float = 10.0, only_kurtosis: bool = False, img_mask_val: int = 1, img_band: int = 1, img_val_no_data: float = None, gdalformat: str = 'KEA', plot_thres_file: str = None) float

This function to find outliers within a class using an optimisation of the skewness and kurtosis. It is assumed that the input_img is from a different date than the mask (classification) and therefore the outliers will related to class changes. The skewness and kurtosis method assume that without change image values will be normally distributed.

Parameters:
  • input_img – the input image for the analysis. Just a single band will be used.

  • in_msk_img – input image mask use to define the region (class) of interest.

  • output_img – output image with pixel over of 1 for within mask but not outlier and 2 for in mask and outlier.

  • vld_min – the minimum threshold for valid image values.

  • vld_max – the maximum threshold for valid image values.

  • init_thres – an initial estimate of the change threshold

  • low_thres – a boolean as to whether the threshold is on the upper or lower side of the histogram. If True (default) then outliers will be identified as values below the threshold. If False then outliers will be above the threshold.

  • contamination – An estimate of the amount of contamination (i.e., outliners) which is within the scene.

  • only_kurtosis

    A boolean to specify that only the kurtosis should be used

    to estimate the threshold. Default: False (i.e., both the

    kurtosis and skewness are used.

  • img_mask_val – the pixel value within the in_msk_img specifying the class of interest.

  • img_band – the input_img image band to be used for the analysis.

  • img_val_no_data – the input_img image not data value. If None then the value will be read from the image header.

  • gdalformat – the output image file format. (Default: KEA)

  • plot_thres_file – A file path for a plot of the histogram with the threshold. If None then ignored.

Returns:

The threshold identified.

rsgislib.changedetect.pxloutlierchng.find_class_otsu_outliers(input_img: str, in_msk_img: str, output_img: str, low_thres: bool, img_mask_val: int = 1, img_band: int = 1, img_val_no_data: float = None, gdalformat: str = 'KEA', plot_thres_file: str = None) float

This function to find outliers within a class using an otsu thresholding. It is assumed that the input_img is from a different date than the mask (classification) and therefore the outliers will related to class changes.

Parameters:
  • input_img – the input image for the analysis. Just a single band will be used.

  • in_msk_img – input image mask use to define the region (class) of interest.

  • output_img – output image with pixel over of 1 for within mask but not outlier and 2 for in mask and outlier.

  • low_thres – a boolean as to whether the threshold is on the upper or lower side of the histogram. If True (default) then outliers will be identified as values below the threshold. If False then outliers will be above the threshold.

  • img_mask_val – the pixel value within the in_msk_img specifying the class of interest.

  • img_band – the input_img image band to be used for the analysis.

  • img_val_no_data – the input_img image not data value. If None then the value will be read from the image header.

  • gdalformat – the output image file format. (Default: KEA)

  • plot_thres_file – A file path for a plot of the histogram with the threshold. If None then ignored.

Returns:

The threshold identified.

rsgislib.changedetect.pxloutlierchng.find_class_li_outliers(input_img: str, in_msk_img: str, output_img: str, low_thres: bool, tolerance: float = None, init_thres: float = None, img_mask_val: int = 1, img_band: int = 1, img_val_no_data: float = None, gdalformat: str = 'KEA', plot_thres_file: str = None) float

This function to find outliers within a class using Li’s iterative Minimum Cross Entropy method. It is assumed that the input_img is from a different date than the mask (classification) and therefore the outliers will related to class changes.

Parameters:
  • input_img – the input image for the analysis. Just a single band will be used.

  • in_msk_img – input image mask use to define the region (class) of interest.

  • output_img – output image with pixel over of 1 for within mask but not outlier and 2 for in mask and outlier.

  • low_thres – a boolean as to whether the threshold is on the upper or lower side of the histogram. If True (default) then outliers will be identified as values below the threshold. If False then outliers will be above the threshold.

  • tolerance – float (optional) - Finish the computation when the change in the threshold in an iteration is less than this value. By default, this is half the smallest difference between data values.

  • init_thres – an initial estimate of the change threshold

  • img_mask_val – the pixel value within the in_msk_img specifying the class of interest.

  • img_band – the input_img image band to be used for the analysis.

  • img_val_no_data – the input_img image not data value. If None then the value will be read from the image header.

  • gdalformat – the output image file format. (Default: KEA)

  • plot_thres_file – A file path for a plot of the histogram with the threshold. If None then ignored.

Returns:

The threshold identified.

Image to Image Change Detection

rsgislib.changedetect.imgchngmthds.image_difference(in_base_img: str, in_chng_img: str, out_diff_img: str, vld_msk_img: str = None, vld_msk_val: int = 1, gdalformat: str = 'KEA', apply_std: bool = False, img_base_bands: List[int] = None, img_chng_bands: List[int] = None, base_img_no_data: float = 0, chng_img_no_data: float = 0)
Parameters:
  • in_base_img – The input base image file path

  • in_chng_img – The input change image file path

  • out_diff_img – Output differance image file path

  • vld_msk_img – An optional valid pixel image mask - if not specified the no data values of the input images will be used.

  • vld_msk_val – the pixel value within in the mask defining which pixels are valid. Default is 1.

  • gdalformat – Output GDAL image file format

  • apply_std – Optionally apply standardisation to the input images.

  • img_base_bands – Optionally specified a list of bands for the base image

  • img_chng_bands – Optionally specified a list of bands for the change image

  • base_img_no_data – Optionally specified nodata value for the base image

  • chng_img_no_data – Optionally specified nodata value for the change image

rsgislib.changedetect.imgchngmthds.change_vector_analysis(in_base_img: str, in_chng_img: str, out_chng_img: str, out_chng_dist_img: str, vld_msk_img: str = None, vld_msk_val: int = 1, gdalformat: str = 'KEA', apply_std: bool = False, img_base_bands: List[int] = None, img_chng_bands: List[int] = None, use_kmeans: bool = False, base_img_no_data: float = 0, chng_img_no_data: float = 0)

A function which performs Change vector analysis (CVA) between two images. The two images must have exactly the extent, resolution and image size (width and height).

Parameters:
  • in_base_img – The input base image file path

  • in_chng_img – The input change image file path

  • out_chng_img – Output binary change image file path

  • out_chng_dist_img – Output change distance image file path

  • vld_msk_img – An optional valid pixel image mask - if not specified the no data values of the input images will be used.

  • vld_msk_val – the pixel value within in the mask defining which pixels are valid. Default is 1.

  • gdalformat – Output GDAL image file format

  • apply_std – Optionally apply standardisation to the input images.

  • img_base_bands – Optionally specified a list of bands for the base image

  • img_chng_bands – Optionally specified a list of bands for the change image

  • base_img_no_data – Optionally specified nodata value for the base image

  • chng_img_no_data – Optionally specified nodata value for the change image

rsgislib.changedetect.imgchngmthds.slow_feature_analysis(in_base_img: str, in_chng_img: str, out_chng_img: str, out_chng_dist_img: str, vld_msk_img: str = None, vld_msk_val: int = 1, gdalformat: str = 'KEA', apply_std: bool = False, img_base_bands: List[int] = None, img_chng_bands: List[int] = None, sfa_max_iter: int = 50, sfa_epsilon: float = 1e-06, sfa_norm_trans: bool = False, sfa_regular: bool = False, use_kmeans: bool = False, base_img_no_data: float = 0, chng_img_no_data: float = 0)

A function which performs Slow Feature Analysis (SFA) between two images. The two images must have exactly the extent, resolution and image size (width and height). There must be at least three image bands.

C. Wu, B. Du, and L. Zhang, “Slow feature analysis for change detection in multispectral imagery,” IEEE Trans. Geosci. Remote Sens., vol. 52, no. 5, pp. 2858–2874, 2014.

Parameters:
  • in_base_img – The input base image file path

  • in_chng_img – The input change image file path

  • out_chng_img – Output binary change image file path

  • out_chng_dist_img – Output change distance image file path

  • vld_msk_img – An optional valid pixel image mask - if not specified the no data values of the input images will be used.

  • vld_msk_val – the pixel value within in the mask defining which pixels are valid. Default is 1.

  • gdalformat – Output GDAL image file format

  • apply_std – Optionally apply standardisation to the input images.

  • img_base_bands – Optionally specified a list of bands for the base image

  • img_chng_bands – Optionally specified a list of bands for the change image

  • sfa_max_iter – Maximum number of iterations for the algorithm to converge.

  • sfa_epsilon – Threshold for convergence.

  • sfa_norm_trans – Specifies whether to normalise the transformation matrix

  • sfa_regular – Specifies whether to regularise the transformation matrix

  • base_img_no_data – Optionally specified nodata value for the base image

  • chng_img_no_data – Optionally specified nodata value for the change image

rsgislib.changedetect.imgchngmthds.multivariate_alteration_detection(in_base_img: str, in_chng_img: str, out_chng_img: str, out_chng_dist_img: str, out_chng_mads_img: str, vld_msk_img: str = None, vld_msk_val: int = 1, gdalformat: str = 'KEA', apply_std: bool = False, img_base_bands: List[int] = None, img_chng_bands: List[int] = None, mad_max_iter: int = 50, mad_epsilon: float = 1e-06, use_kmeans: bool = True, base_img_no_data: float = 0, chng_img_no_data: float = 0)

A function which performs Multivariate Alteration Detection (MAD) between two images. The two images must have exactly the extent, resolution and image size (width and height). MAD is a change detection algorithm based on canonical correlation analysis (CCA) that aims to maximize the variance of projection feature difference.

Parameters:
  • in_base_img – The input base image file path

  • in_chng_img – The input change image file path

  • out_chng_img – Output binary change image file path

  • out_chng_dist_img – Output change distance image file path

  • out_chng_mads_img – Output change MADs variates image file path

  • gdalformat – Output GDAL image file format

  • apply_std – Optionally apply standardisation to the input images.

  • img_base_bands – Optionally specified a list of bands for the base image

  • img_chng_bands – Optionally specified a list of bands for the change image

  • mad_max_iter – Maximum number of iterations for the algorithm to converge.

  • mad_epsilon – Threshold for convergence.

  • base_img_no_data – The base image no data value.

  • chng_img_no_data – The change image no data value.

  • base_img_no_data – Optionally specified nodata value for the base image

  • chng_img_no_data – Optionally specified nodata value for the change image