histonets_cv package¶
Submodules¶
histonets_cv.api module¶
histonets_cv.cli module¶
histonets_cv.utils module¶
-
class
histonets_cv.utils.
Choice
(choices)[source]¶ Bases:
click.types.Choice
Fix to click.Choice to be able to use integer choices
-
class
histonets_cv.utils.
Image
(content=None, image=None)[source]¶ Bases:
object
Proxy class to handle image input in the commands
-
format
¶
-
classmethod
get_images
(values)[source]¶ Helper to process local, remote, and base64 piped images as input, and return Image objects
-
image
¶
-
-
class
histonets_cv.utils.
JSONNumpyEncoder
(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]¶ Bases:
json.encoder.JSONEncoder
Enable serialization of basic Numpy arrays
-
default
(obj)[source]¶ Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
-
-
class
histonets_cv.utils.
JSONStream
(mode='r')[source]¶ Bases:
histonets_cv.utils.Stream
JSON Stream Click option type to handle and decode JSON input and files coming (compressed or not) from the Internet (http:// and https://) or locally (file://, absolute, or relative paths).
-
class
histonets_cv.utils.
Stream
(mode='r')[source]¶ Bases:
click.types.ParamType
Click option type for http/https/file inputs
Based on https://github.com/moshe/click-stream
-
SUPPORTED_SCHEMES
= ('http', 'https', 'file')¶
-
convert
(param=None, ctx=None, value=None)[source]¶ Converts the value. This is not invoked for values that are None (the missing value).
-
name
= 'stream'¶
-
-
histonets_cv.utils.
argfirst2D
(arr, item)[source]¶ Return the index of the first element of the 2D array arr matching the row item, or None if not found.
-
histonets_cv.utils.
astar
(grid, start, end)[source]¶ Run A* algorithm from start to end to find a path in grid. It uses squared Euclidean distance as the distance method and the cost estimate heuristic, and it uses the Von Neumann method to assess the 8-neighbors. Returns a predecessors dictionary from which a path can be built.
-
histonets_cv.utils.
edges_to_graph
(edges, fmt=None)[source]¶ Build a graph based on a list of edges and serialize it to format. Each edge is a dictionary with at least keys defined for source_key and target_key, expressing the source and the target of the edge, respectively. The graph is built and serialized using NetworkX, therefore only a subset of its formats are available: ‘edgelist’, ‘gexf’, ‘gml’, ‘graphml’, ‘nodelink’. See http://networkx.readthedocs.io/en/stable/reference/readwrite.html for more information.
-
histonets_cv.utils.
get_color_histogram
(*args, **kwargs)[source]¶ Calculate the color histogram of image (colors and their counts)
-
histonets_cv.utils.
get_images
(ctx, param, value)[source]¶ Callback to retrieve images by either their local path or URL
-
histonets_cv.utils.
get_inner_paths
(grid, regions)[source]¶ Create 1 pixel width paths connecting the loose ends surrounding the regions to their center. Each region is defined by its top-left and bottom-right corners points expressed in [x, y] coordinates. Grid must be a black and white image
-
histonets_cv.utils.
get_mask_polygons
(polygons, height, width)[source]¶ Turn a list of polygons into a mask image of height by width. Each polygon is expressed as a list of [x, y] points.
-
histonets_cv.utils.
get_palette
(*args, **kwargs)[source]¶ Calculate a palette of n_colors from RGB values from an array of colors. Parameters background_value and background_saturation are ignored for methods other than ‘auto’. When method=’auto’, the first palette entry is always the background color; the rest are determined from foreground pixels by running K-Means clustering. Returns the palette.
-
histonets_cv.utils.
get_quantize_method
(method)[source]¶ Transform a string (‘median’, ‘octree’, ‘linear’, ‘max’) to the corresponding PIL quantize method constant
-
histonets_cv.utils.
get_shortest_paths
(grid, look_for)[source]¶ Traverse the grid, where 0’s represent holes and 1’s paths, and return the paths to get from sources to targets, expressed in look_for in the form of ((start1, end1), (start2, end2)), where each ‘start’ and ‘end’ are coordinates of the grid in the form [x, y] pairs. It uses the Floyd-Warshall algorithm to find first all shortest paths and then returns only those in look_for
-
histonets_cv.utils.
get_shortest_paths_astar
(grid, look_for)[source]¶ Traverse the grid, where 0’s represent holes and 1’s paths, and return the paths to get from sources to targets, expressed in look_for in the form of ((start1, end1), (start2, end2)), where each ‘start’ and ‘end’ are coordinates of the grid in the form [x, y] pairs. It uses the A* algorithm and it only computes the paths in the look_for.
-
histonets_cv.utils.
grid_to_adjacency_matrix
(grid, neighborhood=8)[source]¶ Convert a boolean grid where 0’s express holes and 1’s connected pixel into a sparse adjacency matrix representing the grid-graph. Neighborhood for each pixel is calculated from its 4 or 8 more immediate surrounding neighbors (defaults to 8).
-
histonets_cv.utils.
io_handler
(input=None, *args, **kwargs)[source]¶ Decorator to handle the ‘input’ argument and the ‘output’ option. If input is other than ‘image’, it is considered to be a JSON file or URL. Defaults to ‘image’.
-
histonets_cv.utils.
kmeans
(X, n_clusters, **kwargs)[source]¶ Classify vectors in X using K-Means algorithm with n_clusters. Arguments in kwargs are passed to scikit-learn MiniBatchKMeans. Returns a tuple of cluster centers and predicted labels.
-
histonets_cv.utils.
local_decode
(value)[source]¶ Decode bytes into a string by using the system preferred encoding. Defaults to utf8 otherwise.
-
histonets_cv.utils.
local_encode
(value)[source]¶ Encode a string to bytes by using the system preferred encoding. Defaults to utf8 otherwise.
-
histonets_cv.utils.
match_template_mask
(*args, **kwargs)[source]¶ Match template against image applying mask to template using method. Method can be either of (None, ‘laplacian’, ‘sobel’, ‘scharr’, ‘prewitt’, ‘roberts’, ‘canny’). Returns locations to look for max values.
-
histonets_cv.utils.
output_as_mask
(f)[source]¶ Decorator to add a return_mask option when image and mask are being returned
-
histonets_cv.utils.
pair_options_to_argument
(argument, options, args=None, args_slice=None)[source]¶ Enforces pairing of options to an argument. Only commands with one argument with nargs=-1 are supported. Not paired options do still work.
Options is a dictionary with the option name as key and the default value as value. A slice to specify where in the arguments the argument and the options are found can be used. By default it will ignore first and last.
Example:
@click.command() @click.argument('arg', nargs=-1, required=True) @click.option('-o', '--option', multiple=True) @pair_options_to_argument('arg', {'option': 0}) def command(arg, option): pass
-
histonets_cv.utils.
parse_colors
(ctx, param, value)[source]¶ Callback to parse color values from a JSON list or hexadecimal string to a RGB tuple.
-
histonets_cv.utils.
parse_histogram
(histogram)[source]¶ Parse a dictionary or JSON string representing a histogram of colors by parsing the keys that codify colors into lists of RGB components and the values to integer numbers
-
histonets_cv.utils.
parse_jsons
(ctx, param, value)[source]¶ Callback to load a list JSON strings as objects
-
histonets_cv.utils.
parse_palette
(ctx, param, value)[source]¶ Callback to turn a JSON representing a palette of colors in hexadecimal or by its RGB components, into a list of all RGB components
-
histonets_cv.utils.
parse_pipeline_json
(ctx, param, value)[source]¶ Parse the actions JSON used mainly in the pipeline command
-
histonets_cv.utils.
sample_histogram
(histogram, sample_fraction=0.05)[source]¶ Sample a sample_fraction of colors from histogram