Measure Utility¶
Image Comparison Utility
-
kalmus.utils.measure_utils.
compare_needleman_wunsch
(str_barcode_1, str_barcode_2, local_sequence_size=2000, match_score=2, mismatch_penal=- 1, gap_penal=- 0.5, extending_gap_penal=- 0.1, normalized=False)[source]¶ Compare two input character arrays/strings (barcode)'s matching score using the Needleman Wunsch method. Needleman Wunsch: https://www.sciencedirect.com/science/article/abs/pii/0022283670900574?via%3Dihub
- Parameters
str_barcode_1 (str) -- The input string representation of barcode 1
str_barcode_2 (str) -- The input string representation of barcode 2
local_sequence_size (int) -- Divide the long barcode into several small barcode with local_sequence_size length
match_score (int) -- The score (bonus) for correctly matching character
mismatch_penal (int) -- The penalty for mismatch character
gap_penal (int) -- The penalty for gaps within matched sequence
extending_gap_penal (int) -- The penalty for extending gaps
normalized (bool) -- If True normalize the final matching score into range [0, 1]. If False, return the raw score
- Returns
The match score/normalized match score
- Return type
float
-
kalmus.utils.measure_utils.
compare_smith_waterman
(str_barcode_1, str_barcode_2, local_sequence_size=2000, match_score=2, mismatch_penal=- 1, gap_penal=- 0.5, extending_gap_penal=- 0.1, normalized=False)[source]¶ Compare two input character arrays/strings (barcode)'s matching score using the Smith Waterman method. Smith Waterman: https://www.sciencedirect.com/science/article/abs/pii/0022283681900875?via%3Dihub
- Parameters
str_barcode_1 (str) -- The input string representation of barcode 1
str_barcode_2 (str) -- The input string representation of barcode 2
local_sequence_size (int) -- Divide the long barcode into several small barcode with local_sequence_size length
match_score (int) -- The score (bonus) for correctly matching character
mismatch_penal (int) -- The penalty for mismatch character
gap_penal (int) -- The penalty for gaps within matched sequence
extending_gap_penal (int) -- The penalty for extending gaps
normalized (bool) -- If True, normalize the final matching score into range [0, 1]. If False, return the raw score.
- Returns
The match score/normalized match score
- Return type
float
-
kalmus.utils.measure_utils.
cross_correlation
(signal_template, signal_source)[source]¶ Signal matching. Cross correlation of two input signals. Signals need to be in the same shape
- Parameters
signal_template (numpy.ndarray) -- The template signal
signal_source (numpy.ndarray) -- The source signal
- Returns
The cross correlation between two input signals. High cross correlation means high similarity between two input signals. range in [-1, 1]
- Return type
float
-
kalmus.utils.measure_utils.
generate_brightness_string_from_brightness_barcode
(brightness_barcode, num_interval=15)[source]¶ Helper function Generate the string where each character represents the brightness interval of the brightness in the input brightness barcode.
- Parameters
brightness_barcode (numpy.ndarray) -- Input 1 dimensional brightness barcode with 1 channel.
kalmus.barcodes.Barcode.BrightnessBarcode.brightness
shape == [number of brightness, 1]num_interval (int) -- The number of intervals that will be divided in the brightness range [0, 255]
- Returns
The string where each character represents the brightness interval of the brightness in the input
- Return type
str
-
kalmus.utils.measure_utils.
generate_hue_strings_from_color_barcode
(color_barcode, num_interval=12)[source]¶ Helper function Generate the characters strings that represent the hue values of the input RGB color barcode (3 channel in range [0, 255]).
- Parameters
color_barcode (numpy.ndarray) -- Input color barcode, the input barcode must be a 1 dimensional color barcode with
kalmus.barcodes.ColorBarcode.colors
three channels (R, G, B). shape == [number of colors, 3]num_interval (int) -- The number of intervals that will be divided in the Hue ring (0 to 360 degree)
- Returns
The string where each character represent the hue interval of the colors in the input RGB barcode
- Return type
str
-
kalmus.utils.measure_utils.
local_cross_correlation
(signal_template, signal_source, horizontal_interval=40, vertical_interval=40)[source]¶ Local cross correlation between two input signals. The input signals need to be 2 dimensional for local windowing
- Parameters
signal_template (numpy.ndarray) -- The template signal
signal_source (numpy.ndarray) -- The source signal
horizontal_interval (int) -- Number of horizontal intervals (window width == signal width // horizontal intervals)
vertical_interval (int) -- Number of vertical intervals (window height == signal height // vertical intervals)
- Returns
The local cross correlation between two signals. Higher local cross correlation means higher similarity between two signals. range in [-1, 1]
- Return type
float
-
kalmus.utils.measure_utils.
nrmse_similarity
(image_1, image_2, norm_mode='Min max')[source]¶ Normalized root mean squared error (NRMSE).
- Parameters
image_1 (numpy.ndarray) -- The image 1 for comparison
image_2 (numpy.ndarray) -- The image 2 for comparison
norm_mode (str) -- The mode for the normalization, average mode use the max (||image_1||, ||image_2||) Min max use the max(image_1 value range, image_2 value range)
- Returns
The score that measure the similarity between two images in range [0,1] using NRMSE 0 is the least similar, 1 is the most similar (same)
- Return type
float
-
kalmus.utils.measure_utils.
ssim_similarity
(image_1, image_2, window_size=None)[source]¶ Structural similarity index measure (ssim)
- Parameters
image_1 (numpy.ndarray) -- The image 1 for comparison
image_2 (numpy.ndarray) -- The image 2 for comparison
window_size (int) -- The size of the local window, integer
- Returns
The Structural similarity index score in range [0,1] 0 is the least similar, 1 is the most similar (same)
- Return type
float