sketchkit.vectorization package

Subpackages

Submodules

sketchkit.vectorization.vectorizer module

class sketchkit.vectorization.vectorizer.Vectorizer(method: str = 'DeepVecSIG24', device: str = 'cuda')[source]

Bases: object

A class for image vectorization.

This class provides functionality to convert a raster image to a vector image.

method

The vectorization method that is used.

Type:

str

device

The device that is used.

Type:

str

run(input: ndarray) Sketch[source]

Vectorize the input raster image.

Parameters:

input (numpy.ndarray) – input raster image in shape (H, W), with values in [0, 255].

Returns:

a Sketch instance.

Return type:

sketch (Sketch)

Module contents

class sketchkit.vectorization.DeepVecSIG24(device: str = 'cuda')[source]

Bases: object

A class for image vectorization using the method of paper “Deep Sketch Vectorization via Implicit Surface Extraction” in SIGGRAPH 2024.

device

The device that is used.

Type:

str

_D(t)[source]
_download_models()[source]

Download the pretrained models

_load_checkpoint_ndc(filepath)[source]

Loads model from a checkpoint we will need the distance threshold to accruately recover the UDF for the next NDC model

_load_checkpoint_udf(filepath)[source]

Loads model from a checkpoint we will need the distance threshold to accruately recover the UDF for the next NDC model

_load_img(img_np, device, resize=False, resize_to=1024)[source]
_load_model(device)[source]
_paths_to_Sketch(paths)[source]
_pre_svg(net, udf, gsize)[source]
_pre_udf(net, img)[source]
_predict_SVG(udf_topo_pre, model_ndc, args_udf, args_ndc, refine=True)[source]
_predict_UDF(img, img_np, model_udf, usm_thr=0.5)[source]
_simplify_SVG(path_to_svg, keypt_pre_dict, rdp_simplify=False, epsilon=0.4, skip_len=4)[source]
_vis_stroke(strokes, canvas_size, save_path)[source]
run(image_array: ndarray, image_folder: str = './', out_folder: str = 'svg') Sketch[source]

Vectorize the input raster image.

Parameters:
  • image_array (numpy.ndarray) – input raster image in shape (H, W), with values in [0, 255].

  • image_folder (str, optional) – the folder of the input raster image.

  • out_folder (str, optional) – an output folder to store the output svg file.

Returns:

a Sketch instance.

Return type:

sketch (Sketch)

class sketchkit.vectorization.LineDrawer(method: str = 'CNNVE', device: str = 'cuda')[source]

Bases: object

Native LineDrawer integration that mirrors the structure of other vectorizers.

_convert_to_sketch(merge_dic: dict, height: int, width: int) Sketch[source]

Convert the CNNVE output dictionary to a Sketch object.

run(img: ndarray) Sketch[source]

Vectorize the provided numpy image.

Parameters:

img (np.ndarray) – Input image as a 2D numpy array (grayscale).

Returns:

The vectorized sketch.

Return type:

Sketch

class sketchkit.vectorization.Vectorizer(method: str = 'DeepVecSIG24', device: str = 'cuda')[source]

Bases: object

A class for image vectorization.

This class provides functionality to convert a raster image to a vector image.

method

The vectorization method that is used.

Type:

str

device

The device that is used.

Type:

str

run(input: ndarray) Sketch[source]

Vectorize the input raster image.

Parameters:

input (numpy.ndarray) – input raster image in shape (H, W), with values in [0, 255].

Returns:

a Sketch instance.

Return type:

sketch (Sketch)