sketchkit.sketch2image package¶
Subpackages¶
Submodules¶
sketchkit.sketch2image.image_generator module¶
ImageGenerator for sketch-to-image conversion tasks.
This class provides functionality to convert vector sketches to realistic images using various AI methods.
- class sketchkit.sketch2image.image_generator.ImageGenerator(method: str = 'controlnet', device: str = 'cuda', **kwargs: Any)[source]¶
Bases:
objectA class for sketch-to-image conversion.
This class provides functionality to convert vector sketches to realistic images using various AI methods.
- method¶
The conversion method that is used.
- Type:
str
- device¶
The device that is used.
- Type:
str
- _model¶
The loaded AI model instance.
- _prepare_control_image(image: ndarray | Image) Image[source]¶
Prepare control image from rasterized sketch or PIL image.
- _prepare_t2i_adapter_image(image: ndarray | Image) Image[source]¶
Special preparation for T2I-Adapter edge detection.
- _run_controlnet(control_image: Image, prompt: str, size: int | Tuple[int, int], **kwargs: Any) Image[source]¶
Run ControlNet-based sketch-to-image conversion.
- _run_pix2pix(control_image: Image, prompt: str, size: int | Tuple[int, int], **kwargs: Any) Image[source]¶
Run Pix2Pix-based sketch-to-image conversion.
- _run_t2i_adapter(control_image: Image, prompt: str, size: int | Tuple[int, int], **kwargs: Any) Image[source]¶
Run T2I-Adapter-based sketch-to-image conversion.
- _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 sketch-to-image conversion 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 sketch-to-image conversion 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 = 'a realistic photo', size: int | Tuple[int, int] | None = None, input_size: Tuple[int, int] | None = None, **kwargs: Any) Image[source]¶
Convert the input sketch or image to realistic 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 image generation.
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 3. 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. adapter_conditioning_scale (float): T2I-Adapter conditioning scale. Defaults to 1.0. image_guidance_scale (float): Pix2Pix image guidance scale. Defaults to 1.0. seed (int): Random seed for reproducibility. Optional.
- Returns:
Generated image as PIL Image.
Module contents¶
Sketch-to-Image Conversions
This module provides a unified API for converting vector sketches into realistic images.
- class sketchkit.sketch2image.ImageGenerator(method: str = 'controlnet', device: str = 'cuda', **kwargs: Any)[source]¶
Bases:
objectA class for sketch-to-image conversion.
This class provides functionality to convert vector sketches to realistic images using various AI methods.
- method¶
The conversion method that is used.
- Type:
str
- device¶
The device that is used.
- Type:
str
- _model¶
The loaded AI model instance.
- _prepare_control_image(image: ndarray | Image) Image[source]¶
Prepare control image from rasterized sketch or PIL image.
- _prepare_t2i_adapter_image(image: ndarray | Image) Image[source]¶
Special preparation for T2I-Adapter edge detection.
- _run_controlnet(control_image: Image, prompt: str, size: int | Tuple[int, int], **kwargs: Any) Image[source]¶
Run ControlNet-based sketch-to-image conversion.
- _run_pix2pix(control_image: Image, prompt: str, size: int | Tuple[int, int], **kwargs: Any) Image[source]¶
Run Pix2Pix-based sketch-to-image conversion.
- _run_t2i_adapter(control_image: Image, prompt: str, size: int | Tuple[int, int], **kwargs: Any) Image[source]¶
Run T2I-Adapter-based sketch-to-image conversion.
- _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 sketch-to-image conversion 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 sketch-to-image conversion 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 = 'a realistic photo', size: int | Tuple[int, int] | None = None, input_size: Tuple[int, int] | None = None, **kwargs: Any) Image[source]¶
Convert the input sketch or image to realistic 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 image generation.
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 3. 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. adapter_conditioning_scale (float): T2I-Adapter conditioning scale. Defaults to 1.0. image_guidance_scale (float): Pix2Pix image guidance scale. Defaults to 1.0. seed (int): Random seed for reproducibility. Optional.
- Returns:
Generated image as PIL Image.