sketchkit.colorization package¶
Subpackages¶
Submodules¶
sketchkit.colorization.colorizer module¶
Colorizer for sketch colorization tasks.
This class provides functionality to colorize vector sketches using various AI methods.
- class sketchkit.colorization.colorizer.Colorizer(method: str = 'controlnet_lineart', device: str = 'cuda', **kwargs: Any)[source]¶
Bases:
objectA class for sketch colorization.
This class provides functionality to colorize vector sketches using various AI methods.
- method¶
The colorization method that is used.
- Type:
str
- device¶
The device that is used.
- Type:
str
- _model¶
The loaded AI model instance.
- _generate_with_control_image(control_image: Image, prompt: str, size: int | Tuple[int, int], **kwargs: Any) Image[source]¶
Generate colorized image using control image.
- _prepare_control_image(image: ndarray | Image) Image[source]¶
Prepare control image from rasterized sketch or PIL image.
- _run_with_image(image: Image | ndarray, prompt: str, size: int | Tuple[int, int] | None, input_size: Tuple[int, int] | None, **kwargs: Any) Image[source]¶
Run colorization with Image input.
- _run_with_sketch(sketch: Sketch, prompt: str, size: int | Tuple[int, int] | None, input_size: Tuple[int, int] | None, **kwargs: Any) Image[source]¶
Run colorization with Sketch input.
- _sketch_to_raster(sketch: Sketch, size: int | Tuple[int, int] = 512, background_color: Tuple[float, float, float] = (1, 1, 1), stroke_width: int = 3, fit_canvas: bool = True) ndarray[source]¶
Convert sketch to rasterized image using CairoRenderer.
- run(input_data: Sketch | Image | ndarray, prompt: str = 'vibrant colors, anime style', size: int | Tuple[int, int] | None = None, input_size: Tuple[int, int] | None = None, **kwargs: Any) Image[source]¶
Colorize the input sketch or image.
- Parameters:
input_data – Input can be: - Sketch: Vector sketch object - Image.Image: PIL Image object - np.ndarray: Numpy array image
prompt – Text description guiding the colorization.
size – Output image size (int for square, tuple for rectangle). If None, for Sketch input, uses sketch’s height and width; for Image input, uses the image size.
input_size – Optional input resize dimensions (height, width). If provided, the input will be resized before processing.
- Keyword Args for Generation Control:
stroke_width (int): Stroke width for rasterization. Defaults to 2. fit_canvas (bool): Whether to fit sketch to canvas. Defaults to True. num_inference_steps (int): Number of inference steps. Defaults to 20. guidance_scale (float): CFG scale for text guidance. Defaults to 7.5. controlnet_conditioning_scale (float): ControlNet conditioning scale. Defaults to 1.0. negative_prompt (str): Negative prompt to avoid unwanted features.
Defaults to “blurry, low quality, distorted”.
seed (int): Random seed for reproducibility. Optional.
- Returns:
Colorized image as PIL Image.
Module contents¶
Sketch Colorization
This module provides a unified API for colorizing vector sketches.
- class sketchkit.colorization.Colorizer(method: str = 'controlnet_lineart', device: str = 'cuda', **kwargs: Any)[source]¶
Bases:
objectA class for sketch colorization.
This class provides functionality to colorize vector sketches using various AI methods.
- method¶
The colorization method that is used.
- Type:
str
- device¶
The device that is used.
- Type:
str
- _model¶
The loaded AI model instance.
- _generate_with_control_image(control_image: Image, prompt: str, size: int | Tuple[int, int], **kwargs: Any) Image[source]¶
Generate colorized image using control image.
- _prepare_control_image(image: ndarray | Image) Image[source]¶
Prepare control image from rasterized sketch or PIL image.
- _run_with_image(image: Image | ndarray, prompt: str, size: int | Tuple[int, int] | None, input_size: Tuple[int, int] | None, **kwargs: Any) Image[source]¶
Run colorization with Image input.
- _run_with_sketch(sketch: Sketch, prompt: str, size: int | Tuple[int, int] | None, input_size: Tuple[int, int] | None, **kwargs: Any) Image[source]¶
Run colorization with Sketch input.
- _sketch_to_raster(sketch: Sketch, size: int | Tuple[int, int] = 512, background_color: Tuple[float, float, float] = (1, 1, 1), stroke_width: int = 3, fit_canvas: bool = True) ndarray[source]¶
Convert sketch to rasterized image using CairoRenderer.
- run(input_data: Sketch | Image | ndarray, prompt: str = 'vibrant colors, anime style', size: int | Tuple[int, int] | None = None, input_size: Tuple[int, int] | None = None, **kwargs: Any) Image[source]¶
Colorize the input sketch or image.
- Parameters:
input_data – Input can be: - Sketch: Vector sketch object - Image.Image: PIL Image object - np.ndarray: Numpy array image
prompt – Text description guiding the colorization.
size – Output image size (int for square, tuple for rectangle). If None, for Sketch input, uses sketch’s height and width; for Image input, uses the image size.
input_size – Optional input resize dimensions (height, width). If provided, the input will be resized before processing.
- Keyword Args for Generation Control:
stroke_width (int): Stroke width for rasterization. Defaults to 2. fit_canvas (bool): Whether to fit sketch to canvas. Defaults to True. num_inference_steps (int): Number of inference steps. Defaults to 20. guidance_scale (float): CFG scale for text guidance. Defaults to 7.5. controlnet_conditioning_scale (float): ControlNet conditioning scale. Defaults to 1.0. negative_prompt (str): Negative prompt to avoid unwanted features.
Defaults to “blurry, low quality, distorted”.
seed (int): Random seed for reproducibility. Optional.
- Returns:
Colorized image as PIL Image.