SlidingWindow

class xaitk_saliency.impls.perturb_image.sliding_window.SlidingWindow(window_size: tuple[int, int] = (50, 50), stride: tuple[int, int] = (20, 20))

Produce perturbation matrices based on hard, block-y occlusion areas as generated by sliding a window of a configured size over the area of an image.

Due to the geometry of sliding windows, if the stride given does not evenly divide the window size along the applicable axis, then the result plane of values when summing the generated masks will not be even.

Related, if the stride is set to be larger than the window size, the resulting plane of summed values will also not be even, as there be increasingly long valleys of unperturbed space between masked regions.

Methods

from_config

Instantiate a new instance of this class given the configuration JSON-compliant dictionary encapsulating initialization arguments.

get_config

Get the configuration dictionary of the SlidingWindow instance.

get_default_config

Returns the default configuration for the SlidingWindow.

get_impls

Discover and return a set of classes that implement the calling class.

is_usable

Check whether this class is available for use.

perturb

Produce a mask based on hard, block-y occlusion areas as generated by sliding a window

__init__(window_size: tuple[int, int] = (50, 50), stride: tuple[int, int] = (20, 20)) None

Produce perturbation matrices based on hard, block-y occlusion areas as generated by sliding a window of a configured size over the area of an image.

Parameters:
  • window_size – The block window size in pixels as a tuple with format (height, width).

  • stride – The sliding window striding step in pixels as a tuple with format (height_step, width_step).

get_config() dict[str, Any]

Get the configuration dictionary of the SlidingWindow instance.

Returns:

dict[str, Any]: Configuration dictionary.

classmethod get_default_config() dict[str, Any]

Returns the default configuration for the SlidingWindow.

This method provides a default configuration dictionary, specifying default values for key parameters in the factory. It can be used to create an instance of the factory with preset configurations.

Returns:

dict[str, Any]: A dictionary containing default configuration parameters.

perturb(ref_image: ndarray) ndarray

Produce a mask based on hard, block-y occlusion areas as generated by sliding a window

Parameters:

ref_image – Reference image to generate perturbations from.

Returns:

Mask matrix with shape [nMasks x Height x Width].