1+ from typing import Any , Callable , Optional
12from vicentin import Graph
23from vicentin .image .utils import get_neighbors
34
45
5- def _compute_edges (H , W , L , img , weight_func , neighborhood ):
6+ def _compute_edges (
7+ H : int , W : int , L : int , img : Any , weight_func : Callable , neighborhood : int
8+ ):
69 """
710 Computes the weighted edges of a graph representation of an image.
811
@@ -14,7 +17,7 @@ def _compute_edges(H, W, L, img, weight_func, neighborhood):
1417 H (int): The height (number of rows) of the image.
1518 W (int): The width (number of columns) of the image.
1619 L (int): The depth (number of channels) of the image.
17- img (numpy.ndarray or jnp.ndarray ): A 1D, 2D, or 3D NumPy array representing the image.
20+ img (numpy.ndarray or torch.Tensor ): A 1D, 2D, or 3D NumPy array representing the image.
1821 weight_func (callable): A function `f(u, v) -> float` that computes edge
1922 weights based on pixel values.
2023 neighborhood (int): The type of neighborhood connectivity:
@@ -51,7 +54,9 @@ def _compute_edges(H, W, L, img, weight_func, neighborhood):
5154 return edges
5255
5356
54- def img2graph (img , weight_func = None , neighborhood = 4 ):
57+ def img2graph (
58+ img : Any , weight_func : Optional [Callable ] = None , neighborhood : int = 4
59+ ):
5560 """
5661 Converts a 1D, 2D, or 3D image into a graph representation.
5762
@@ -60,7 +65,7 @@ def img2graph(img, weight_func=None, neighborhood=4):
6065 are determined by a user-defined function (defaulting to squared intensity difference).
6166
6267 Args:
63- img (numpy.ndarray or jnp.ndarray ): An array of shape (N,), (N, M), or (N, M, L)
68+ img (numpy.ndarray or torch.Tensor ): An array of shape (N,), (N, M), or (N, M, L)
6469 representing a 1D, 2D, or 3D image.
6570 weight_func (callable, optional): A function `f(u, v) -> float` that computes edge
6671 weights based on pixel values.
0 commit comments