virelay.image_processing

Contains some helper functions for processing images.

Functions

add_border

Up-samples the specified image, by making a border around the image.

center_crop

Crops the image evenly on all sides to the desired size.

generate_heatmap_image_black_fire_red

Generates a heatmap with a gray background, where red tones are used to visualize positive relevance values and blue tones are used to visualize negative relevances.

generate_heatmap_image_black_green

Generates a heatmap with a black background, where green tones are used to visualize positive relevance values and blue tones are used to visualize negative relevances.

generate_heatmap_image_black_yellow

Generates a heatmap with a black background, where yellow tones are used to visualize positive relevance values and blue tones are used to visualize negative relevances.

generate_heatmap_image_gray_red

Generates a heatmap with a gray background, where red tones are used to visualize positive relevance values and blue tones are used to visualize negative relevances.

generate_heatmap_image_using_matplotlib

Generates a heatmap from the specified attribution data using the color maps provided by matplotlib.

render_heatmap

Takes the raw attribution data and converts it so that the data can be visualized as a heatmap.

render_superimposed_heatmap

Renders the heatmap an superimposes it onto the specified image.

virelay.image_processing.add_border(image, new_width, new_height, method)[source]

Up-samples the specified image, by making a border around the image.

Parameters
  • image (numpy.ndarray) – The image that is to be up-sampled.

  • new_width (int) – The new width to which the image is to be up-sampled.

  • new_height (int) – The new height to which the image is to be up-sampled.

  • method (str) – The method that is to be used to create the border. Supported methods are ‘fill_zeros’ to fill up the border with zeros, ‘fill_ones’ to fill up the border with ones, ‘edge_repeat’ to repeat the values at the edge of the image, ‘mirror_edge’ to mirror the image at the edge, and ‘wrap_around’ to wrap the image around (e.g. the left edge is filled up with values from the right edge).

Raises

ValueError – If the specified method is not supported, then a ValueError is raised.

Returns

Returns the up-sampled image.

Return type

numpy.ndarray

virelay.image_processing.center_crop(image, new_width, new_height)[source]

Crops the image evenly on all sides to the desired size.

Parameters
  • image (numpy.ndarray) – The image that is to be down-sampled.

  • new_width (int) – The new width to which the image is to be down-sampled.

  • new_height (int) – The new height to which the image is to be down-sampled.

Returns

Returns the center-cropped image.

Return type

numpy.ndarray

virelay.image_processing.generate_heatmap_image_black_fire_red(attribution_data)[source]

Generates a heatmap with a gray background, where red tones are used to visualize positive relevance values and blue tones are used to visualize negative relevances.

Parameters

attribution_data (numpy.ndarray) – The raw attribution data for which the heatmap is to be rendered.

Returns

Returns the heatmap.

Return type

numpy.ndarray

virelay.image_processing.generate_heatmap_image_black_green(attribution_data)[source]

Generates a heatmap with a black background, where green tones are used to visualize positive relevance values and blue tones are used to visualize negative relevances.

Parameters

attribution_data (numpy.ndarray) – The raw attribution data for which the heatmap is to be rendered.

Returns

Returns the heatmap.

Return type

numpy.ndarray

virelay.image_processing.generate_heatmap_image_black_yellow(attribution_data)[source]

Generates a heatmap with a black background, where yellow tones are used to visualize positive relevance values and blue tones are used to visualize negative relevances.

Parameters

attribution_data (numpy.ndarray) – The raw attribution data for which the heatmap is to be rendered.

Returns

Returns the heatmap.

Return type

numpy.ndarray

virelay.image_processing.generate_heatmap_image_gray_red(attribution_data)[source]

Generates a heatmap with a gray background, where red tones are used to visualize positive relevance values and blue tones are used to visualize negative relevances.

Parameters

attribution_data (numpy.ndarray) – The raw attribution data for which the heatmap is to be rendered.

Returns

Returns the heatmap.

Return type

numpy.ndarray

virelay.image_processing.generate_heatmap_image_using_matplotlib(attribution_data, color_map_name)[source]

Generates a heatmap from the specified attribution data using the color maps provided by matplotlib.

Parameters
  • attribution_data (numpy.ndarray) – The raw attribution data for which the heatmap is to be rendered.

  • color_map_name (str) – The name of the color map that is used to produce the heatmap.

Returns

Returns the heatmap.

Return type

numpy.ndarray

virelay.image_processing.render_heatmap(attribution_data, color_map)[source]

Takes the raw attribution data and converts it so that the data can be visualized as a heatmap.

Parameters
  • attribution_data (numpy.ndarray) – The raw attribution data for which the heatmap is to be rendered.

  • color_map (str) – The name of color map that is to be used to render the heatmap.

Raises

ValueError – If the specified color map is unknown, then a ValueError is raised.

Returns

Returns the heatmap image.

Return type

numpy.ndarray

virelay.image_processing.render_superimposed_heatmap(attribution_data, superimpose, color_map)[source]

Renders the heatmap an superimposes it onto the specified image.

Parameters
  • attribution_data (numpy.ndarray) – The raw attribution data for which the heatmap is to be rendered.

  • superimpose (numpy.ndarray) – An image onto which the image is to be superimposed.

  • color_map (str) – The name of color map that is to be used to render the heatmap.

Raises

ValueError – If the specified color map is unknown, then a ValueError is raised.

Returns

Returns the heatmap image.

Return type

numpy.ndarray