sketchkit.stylization package¶
Subpackages¶
- sketchkit.stylization.NeuralBrushstroke package
- Subpackages
- Submodules
- sketchkit.stylization.NeuralBrushstroke.NeuralBrushstroke module
NeuralBrushstrokeNeuralBrushstroke.model_nameNeuralBrushstroke.style_idNeuralBrushstroke.models_dirNeuralBrushstroke.deviceNeuralBrushstroke._get_option()NeuralBrushstroke._import_forger()NeuralBrushstroke._render_sketch_to_png()NeuralBrushstroke._run_forger_stylization()NeuralBrushstroke.run()NeuralBrushstroke.run_from_png()
- sketchkit.stylization.NeuralBrushstroke.models module
- Module contents
NeuralBrushstrokeNeuralBrushstroke.model_nameNeuralBrushstroke.style_idNeuralBrushstroke.models_dirNeuralBrushstroke.deviceNeuralBrushstroke._get_option()NeuralBrushstroke._import_forger()NeuralBrushstroke._render_sketch_to_png()NeuralBrushstroke._run_forger_stylization()NeuralBrushstroke.run()NeuralBrushstroke.run_from_png()
Submodules¶
sketchkit.stylization.stylizer module¶
- class sketchkit.stylization.stylizer.Stylizer(method: str = 'NeuralBrushstroke', **kwargs: Any)[source]¶
Bases:
objectA unified wrapper class for stylizing sketches using various methods.
This class provides a consistent API across different stylization methods, allowing users to switch between methods easily.
- method¶
The stylization method being used.
- Type:
str
- _stylizer¶
The underlying method-specific stylizer instance.
- property model_name: str | None¶
Get the model name (if supported by the method).
- run(sketch: Sketch, output_path: str | None = None, **kwargs: Any) Image[source]¶
Stylize a sketch using the selected method.
- Parameters:
sketch – Input vector sketch.
output_path – Output file path. If None, uses a temporary path.
**kwargs – Method-specific parameters (passed to the underlying method).
- Returns:
Stylized image as PIL Image.
- run_from_png(png_path: str | Path, output_path: str | None = None, **kwargs: Any) Image[source]¶
Stylize an existing PNG image using the selected method.
- Parameters:
png_path – Path to the input PNG geometry image.
output_path – Output file path. If None, uses a temporary path.
**kwargs – Method-specific parameters (passed to the underlying method).
- Returns:
Stylized image as PIL Image.
- property style_id: str | None¶
Get the style ID (if supported by the method).
Module contents¶
- class sketchkit.stylization.NeuralBrushstroke(model_name: str = 'style2', style_id: str = 'playdoh10', models_dir: str | Path | None = None, device: str = 'cuda', auto_download: bool = True, **kwargs: Any)[source]¶
Bases:
objectA class for stylizing sketches using the Neural Brushstroke Engine (NeuBE).
This class provides functionality to convert vector sketches into stylized images using various brushstroke styles from the NeuBE model.
- model_name¶
The model name to use (‘style1’ or ‘style2’).
- Type:
str
- style_id¶
The style ID to use for stylization.
- Type:
str
- device¶
Device to use (for future use, currently not used).
- Type:
str
- _get_option(name: str, kwargs: Dict[str, Any])[source]¶
Get option value from kwargs or fall back to instance default.
- _import_forger()[source]¶
Import forger module using relative imports.
Since stylizer.py and forger/thirdparty are in the same directory, we can use relative imports for cleaner code.
The forger module internally uses absolute imports (import forger.xxx), so we need to register ‘forger’ and ‘thirdparty’ in sys.modules as top-level modules before importing.
- Returns:
The forger module.
- Raises:
ImportError – If forger module is not found.
- _render_sketch_to_png(sketch: Sketch, output_dir: Path, canvas_size: int | None = None) str[source]¶
Render sketch to PNG using CairoRenderer.
- Parameters:
sketch – Input vector sketch.
output_dir – Directory to save the rendered PNG.
canvas_size – Canvas size for rendering. If None, uses sketch’s actual width and height.
- Returns:
Path to the rendered PNG file.
- _run_forger_stylization(png_path: str, style_id: str, library_path: str | Path | None = None, output_dir: Path | None = None, output_file: str | Path | None = None, **kwargs: Any) str[source]¶
Run forger stylization by directly calling forger functions.
This method directly imports and uses forger modules without requiring pip install -e . Only needs the brushstroke_engine directory in the filesystem.
- run(sketch: Sketch, output_path: str | None = None, canvas_size: int | None = None, style_id: str | None = None, library_path: str | Path | None = None, **kwargs: Any) Image[source]¶
Stylize a sketch using the brushstroke engine.
- Parameters:
sketch – Input vector sketch.
output_path – Output file path. If None, uses a temporary path.
canvas_size – Canvas size for rendering. If None, uses sketch’s actual width and height.
style_id – Style ID to use. If None, uses the instance default.
library_path – Path to brush library. If None, uses default.
**kwargs – Additional parameters for stylization: - feature_blending_level (int): Feature blending level. Defaults to 2. - color_mode (str): Color mode. Defaults to ‘1’. - crop_margin (int): Crop margin. Defaults to 10. - on_white (bool): Render on white background. Defaults to True.
- Returns:
Stylized image as PIL Image.
- run_from_png(png_path: str | Path, output_path: str | None = None, style_id: str | None = None, library_path: str | Path | None = None, **kwargs: Any) Image[source]¶
Stylize an existing PNG geometry image using the brushstroke engine.
This method assumes the input PNG is a line drawing (black on white), similar to the –geom_image expected by sketchkit.stylizer.NeuralBrushstroke.forger.viz.paint_image_main.
- Parameters:
png_path – Path to the input PNG geometry image.
output_path – Output file path. If None, uses a temporary path.
style_id – Style ID to use. If None, uses the instance default.
library_path – Path to brush library. If None, uses default.
**kwargs – Additional parameters for stylization (same as run()).
- Returns:
Stylized image as PIL Image.
- class sketchkit.stylization.Stylizer(method: str = 'NeuralBrushstroke', **kwargs: Any)[source]¶
Bases:
objectA unified wrapper class for stylizing sketches using various methods.
This class provides a consistent API across different stylization methods, allowing users to switch between methods easily.
- method¶
The stylization method being used.
- Type:
str
- _stylizer¶
The underlying method-specific stylizer instance.
- property model_name: str | None¶
Get the model name (if supported by the method).
- run(sketch: Sketch, output_path: str | None = None, **kwargs: Any) Image[source]¶
Stylize a sketch using the selected method.
- Parameters:
sketch – Input vector sketch.
output_path – Output file path. If None, uses a temporary path.
**kwargs – Method-specific parameters (passed to the underlying method).
- Returns:
Stylized image as PIL Image.
- run_from_png(png_path: str | Path, output_path: str | None = None, **kwargs: Any) Image[source]¶
Stylize an existing PNG image using the selected method.
- Parameters:
png_path – Path to the input PNG geometry image.
output_path – Output file path. If None, uses a temporary path.
**kwargs – Method-specific parameters (passed to the underlying method).
- Returns:
Stylized image as PIL Image.
- property style_id: str | None¶
Get the style ID (if supported by the method).