ingenii_quantum.qubo.graph
- ingenii_quantum.qubo.graph.apply_similarity(type, image, x1, y1, x2, y2, sigma=None)[source]
Apply chosen similarity to image.
- Parameters:
type (str) – Similarity type name
image (np.array) – input image
x1 (int) – x coordinates pixel 1
y1 (int) – y coordinates pixel 1
x2 (int) – x coordinates pixel 2
y2 (int) – y coordinates pixel 2
- Returns:
Edge weight
- Return type:
weight (float)
- ingenii_quantum.qubo.graph.canberra_distance(X, Y)[source]
Canberra distance.
- Parameters:
p1 (float) – pixel value 1
p2 (float) – pixel value 2
- Returns:
Canberra distance between p1 and p2
- Return type:
float
- ingenii_quantum.qubo.graph.chebyshev_distance(p1, p2)[source]
Chebyshev distance.
- Parameters:
p1 (float) – pixel value 1
p2 (float) – pixel value 2
- Returns:
Chebyshev distance between p1 and p2
- Return type:
float
- ingenii_quantum.qubo.graph.create_graph(data_small, type='Gaussian', sd_prop=0.3)[source]
Function to create the Graph encoding the image, where the edges are calculated using the Gaussian similarity between pixels. Here we perform hyperparameter optimization for the stadard deviation, ensuring that the proportion of the two tails of the weights distribution is around 0.17.
- Parameters:
data_small (np.array) – input data
type (str) – Similarity type name
- Returns:
Graph encoding the image to be segmented.
- Return type:
G (networkx.graph)
- ingenii_quantum.qubo.graph.euclidean_distance(p1, p2)[source]
Euclidean distance.
- Parameters:
p1 (float) – pixel value 1
p2 (float) – pixel value 2
- Returns:
Euclidean distance between p1 and p2
- Return type:
float
- ingenii_quantum.qubo.graph.gaussian_similarity(a, b, sigma)[source]
Gaussian similarity.
- Parameters:
p1 (float) – pixel value 1
p2 (float) – pixel value 2
- Returns:
Gaussian similarity between p1 and p2
- Return type:
float
- ingenii_quantum.qubo.graph.image_to_grid_graph(gray_img, type='Gaussian', sigma=None)[source]
Convert a grayscale image to a grid graph with Gaussian similarity as edge weights.
- Parameters:
gray_img (numpy.ndarray) – Grayscale image.
type (str) – Similarity type name
sigma (float) – Parameter for Gaussian similarity.
- Returns:
List of edges with weights for the graph.
- Return type:
list
ingenii_quantum.qubo.segmentation
- ingenii_quantum.qubo.segmentation.QUBO_formulation(G, alpha=10, height=32)[source]
Function that provides the QUBO formulation for quantum and simulated annealing. It provides the linear and quadratic constraints.
- Parameters:
G (networkx.Graph) – Weighted graph encoding the input image
alpha (float) – hyperparameter controlling the importance of the smoothness constraint.
- Returns:
linear constraints of QUBO model quadratic (dict): quadratic constraints of QUBO model problem_formulation_time (float): Problem formulation time
- Return type:
linear (dict)
- ingenii_quantum.qubo.segmentation.decode_binary_string(x, height, width)[source]
Decode a binary string into a binary segmentation mask.
- Parameters:
x (list) – Binary string representing the segmentation.
height (int) – Height of the image.
width (int) – Width of the image.
- Returns:
Segmentation mask.
- Return type:
numpy.ndarray
- ingenii_quantum.qubo.segmentation.gurobi_qubo_solver(G, alpha=10, height=32, width=32)[source]
Gurobi solver.
- Args
G (networkx.Graph): Weighted graph encoding the input image alpha (float): hyperparameter controlling the importance of the smoothness constraint.
- Returns:
Segmentation mask gurobi_qubo_value (float): QUBO value of segmentation mask
- Return type:
segmentation_mask (np.array)