imagediffer.core package¶
This package contains tools for loading and saving images, various color manipulations and comparing images.
imagediffer.core.differ module¶
Differ module contains functions for comparing images and creating diff images
-
imagediffer.core.differ.
calculate_mse
(image1, image2)¶ Calculate mean squared error for given images. The higher the value of MSE is, the more different the images are.
Parameters: - image1 – Numpy image array
- image2 – Numpy image array
Returns: Float number representing mean squared error
-
imagediffer.core.differ.
calculate_ssim
(image1, image2)¶ Calculate structural similarity index for given images. If the value is 1.0 the images are same. The lower the value is, the more different the images are.
Parameters: - image1 – Numpy image array
- image2 – Numpy image array
Returns: Float number from -1.0 to 1.0 representing SSIM
-
imagediffer.core.differ.
chebyshev_distance
(image1, image2)¶ Calculate chebyshev distance for each pixel in
image1
andimage2
. Images must have same dimension.Parameters: - image1 – Numpy image array
- image2 – Numpy image array
Returns: Array of chebyshev distances
-
imagediffer.core.differ.
diff
(image1, image2, compare_colors_method, tolerance=0, diff_color=(1.0, 0, 1.0, 1.0))¶ Create a diff image of
image1
andimage2
. Pixels are considered different if the distance of colors is greater thantolerance
using givencompare_colors_method
. The result image is created by blendingimage1
andimage2
together and replacing different pixels with thediff_color
.Parameters: - image1 – Numpy image array
- image2 – Numpy image array
- compare_colors_method – Method that takes two numpy image arrays and return array of color distances in range from 0.0 to 1.0. You can use
euclidean_distance
,chebyshev_distance
or implement your own method. - tolerance – Defines the color distance that is acceptable and colors are considered the same
- diff_color – RGBA color that should be used for different pixels
Returns: - Tuple containing:
diff_image
Numpy image arraydiff_pctg
Percentage of pixels where the color distance exceeded the acceptable tolerance
-
imagediffer.core.differ.
euclidean_distance
(image1, image2)¶ Calculate euclidean distance for each pixel in
image1
andimage2
. Images must have same dimension.Parameters: - image1 – Numpy image array
- image2 – Numpy image array
Returns: Array of euclidean distances
imagediffer.core.loader module¶
Loader module contains functions for loading and saving images.
-
imagediffer.core.loader.
load_image_from_file
(file)¶ Load image as a numpy array from given file.
Parameters: file – Path to the image file Returns: Numpy image array with color and alpha channels values from 0.0 to 1.0
-
imagediffer.core.loader.
load_image_from_url
(url)¶ Load image as a numpy array from given URL.
Parameters: url – Image URL Returns: Numpy image array with color and alpha channels values from 0.0 to 1.0
-
imagediffer.core.loader.
save_image
(image, path)¶ Save given image to the PNG file. If the file extension is not part of the
path
or is missing, it will be autocompleted or replaced.Parameters: - image – Numpy image array
- path – Path to the image file.
imagediffer.core.utils module¶
Utils module contains various functions for manipulating images.
-
imagediffer.core.utils.
extract_colors
(image)¶ Extract individual color channels and alpha channel from numpy image array.
Parameters: image – Numpy image array Returns: Array of width × height numpy arrays for each color and alpha channels
-
imagediffer.core.utils.
norm_color
(image)¶ Normalize colors to be in range from 0.0 to 1.0 instead of from 0 to 255.
Parameters: image – Numpy image array with colors from 0 to 255 Returns: Numpy image array with colors normalized to floats
-
imagediffer.core.utils.
to_blue
(source)¶ Convert source image to image using blue channel for all color channels.
Parameters: source – Numpy image array Returns: Numpy image array
-
imagediffer.core.utils.
to_grayscale
(source)¶ Convert image to grayscale using PAL/NTSC conversion.
Parameters: source – Numpy image array Returns: Numpy image array
-
imagediffer.core.utils.
to_green
(source)¶ Convert source image to image using green channel for all color channels.
Parameters: source – Numpy image array Returns: Numpy image array
-
imagediffer.core.utils.
to_red
(source)¶ Convert source image to image using red channel for all color channels.
Parameters: source – Numpy image array Returns: Numpy image array