pypindou.pattern.generate
High-level image-to-pattern generation API.
The functions in this module connect image preprocessing, palette filtering,
color quantization, and pypindou.pattern.Pattern construction. They
are the main public entry point for applications that need a pure Python
image-to-bead-pattern workflow.
Example:
>>> from PIL import Image
>>> from pypindou.pattern import generate_pattern
>>> image = Image.new("RGB", (4, 4), "white")
>>> pattern = generate_pattern(image, width=4, height=4, max_colors=4, color_space="rgb")
>>> pattern.board_size
(4, 4)
PatternOptions
- class pypindou.pattern.generate.PatternOptions(width, height, palette='mard-221-alfonse-doudou', fit='contain', background='white', alpha_threshold=16, resample='lanczos', prefilter='none', prefilter_radius=1.0, brightness=1.0, contrast=1.0, saturation=1.0, sharpness=1.0, grayscale=0.0, color_space='lab', quantize='nearest', dither_strength=1.0, max_colors=None, cleanup='none', cleanup_passes=0, cleanup_threshold=5, min_region_size=0, include_codes=None, exclude_codes=None, allow_unidentified=False, random_state=0)[源代码]
Options for
generate_pattern().- 参数:
width (int) -- Target bead-grid width.
height (int) -- Target bead-grid height.
palette (Union[str, pypindou.color.Palette], optional) -- Built-in palette id or explicit palette object, defaults to
"mard-221-alfonse-doudou".fit (pypindou.image.FitMode, optional) -- Image fit strategy, defaults to
"contain".background (pypindou.image.BackgroundMode, optional) -- Alpha handling strategy, defaults to
"white".alpha_threshold (int, optional) -- Transparent-pixel threshold, defaults to
16.resample (pypindou.image.ResampleMode, optional) -- Resize filter, defaults to
"lanczos".prefilter (pypindou.image.PreprocessMode, optional) -- Optional pre-resize denoising or edge-preserving filter, defaults to
"none".prefilter_radius (float, optional) -- Radius used by the prefilter, defaults to
1.0.brightness (float, optional) -- Brightness adjustment factor, defaults to
1.0.contrast (float, optional) -- Contrast adjustment factor, defaults to
1.0.saturation (float, optional) -- Saturation adjustment factor, defaults to
1.0.sharpness (float, optional) -- Sharpness adjustment factor, defaults to
1.0.grayscale (float, optional) -- Grayscale blend ratio, defaults to
0.0.color_space (pypindou.color.ColorSpace, optional) -- Color distance space, defaults to
"lab".quantize (pypindou.image.QuantizeMethod, optional) -- Quantization method, defaults to
"nearest".dither_strength (float, optional) -- Floyd-Steinberg diffusion strength, defaults to
1.0.max_colors (Optional[int], optional) -- Maximum number of bead colors to use, defaults to
None.cleanup (pypindou.image.CleanupMode, optional) -- Post-quantization cleanup mode, defaults to
"none".cleanup_passes (int, optional) -- Number of cleanup passes, defaults to
0.cleanup_threshold (int, optional) -- Majority threshold for cleanup, defaults to
5.min_region_size (int, optional) -- Small connected regions below this size are merged, defaults to
0.include_codes (Optional[Tuple[str, ...]], optional) -- Optional allowed color-code list.
exclude_codes (Optional[Tuple[str, ...]], optional) -- Optional excluded color-code list.
allow_unidentified (bool, optional) -- Whether to keep colors marked unidentified, defaults to
False.random_state (int, optional) -- Random seed for palette reduction, defaults to
0.
generate_pattern
- pypindou.pattern.generate.generate_pattern(image, *, width, height, palette='mard-221-alfonse-doudou', fit='contain', background='white', alpha_threshold=16, resample='lanczos', prefilter='none', prefilter_radius=1.0, brightness=1.0, contrast=1.0, saturation=1.0, sharpness=1.0, grayscale=0.0, color_space='lab', quantize='nearest', dither_strength=1.0, max_colors=None, cleanup='none', cleanup_passes=0, cleanup_threshold=5, min_region_size=0, include_codes=None, exclude_codes=None, allow_unidentified=False, random_state=0)[源代码]
Generate a fuse-bead pattern from an input image.
The default path favors clean, editable regions over photographic texture: use
max_colorsto limit the palette,prefilterand enhancement options to simplify the source image, then optionally runcleanupandmin_region_sizeto remove tiny color islands. Enablequantize="floyd-steinberg"when visible dithering is preferred.- 参数:
image (Union[str, pathlib.Path, PIL.Image.Image]) -- Source image, image path, or
PIL.Image.Image.width (int) -- Target bead-grid width.
height (int) -- Target bead-grid height.
palette (Union[str, pypindou.color.Palette], optional) -- Built-in palette id or explicit palette object, defaults to
"mard-221-alfonse-doudou".fit (pypindou.image.FitMode, optional) -- Image fit strategy, defaults to
"contain".background (pypindou.image.BackgroundMode, optional) -- Alpha handling strategy, defaults to
"white".alpha_threshold (int, optional) -- Transparent-pixel threshold, defaults to
16.resample (pypindou.image.ResampleMode, optional) -- Resize filter, defaults to
"lanczos".prefilter (pypindou.image.PreprocessMode, optional) -- Optional pre-resize filter, defaults to
"none".prefilter_radius (float, optional) -- Radius used by the prefilter, defaults to
1.0.brightness (float, optional) -- Brightness adjustment factor, defaults to
1.0.contrast (float, optional) -- Contrast adjustment factor, defaults to
1.0.saturation (float, optional) -- Saturation adjustment factor, defaults to
1.0.sharpness (float, optional) -- Sharpness adjustment factor, defaults to
1.0.grayscale (float, optional) -- Grayscale blend ratio, defaults to
0.0.color_space (pypindou.color.ColorSpace, optional) -- Color distance space, defaults to
"lab".quantize (pypindou.image.QuantizeMethod, optional) -- Quantization method, defaults to
"nearest".dither_strength (float, optional) -- Floyd-Steinberg diffusion strength, defaults to
1.0.max_colors (Optional[int], optional) -- Maximum number of bead colors to use, defaults to
None.cleanup (pypindou.image.CleanupMode, optional) -- Post-quantization cleanup mode, defaults to
"none".cleanup_passes (int, optional) -- Number of cleanup passes, defaults to
0.cleanup_threshold (int, optional) -- Majority threshold for cleanup, defaults to
5.min_region_size (int, optional) -- Regions smaller than this value are merged into neighboring colors, defaults to
0.include_codes (Optional[Tuple[str, ...]], optional) -- Optional allowed color-code list.
exclude_codes (Optional[Tuple[str, ...]], optional) -- Optional excluded color-code list.
allow_unidentified (bool, optional) -- Whether to keep colors marked unidentified, defaults to
False.random_state (int, optional) -- Random seed for palette reduction, defaults to
0.
- 返回:
Generated bead pattern.
- 返回类型:
pypindou.pattern.Pattern
generate_pattern_with_options
- pypindou.pattern.generate.generate_pattern_with_options(image, options)[源代码]
Generate a pattern from a
PatternOptionsobject.- 参数:
image (Union[str, pathlib.Path, PIL.Image.Image]) -- Source image, image path, or
PIL.Image.Image.options (PatternOptions) -- Pattern-generation options.
- 返回:
Generated bead pattern.
- 返回类型:
pypindou.pattern.Pattern