excolor.patch
- class excolor.patch.Patch(coords=None, img=None, start=None)[source]
Bases:
objectA class representing a patch that can be drawn on images.
A patch is defined by either a set of coordinates or a mask image, and can be filled with solid colors or gradients. It can also cast shadows or glows on images.
- mask
Binary mask where 1 indicates inside area and 0 outside
- Type:
- __init__(coords=None, img=None, start=None)[source]
Initializes a Patch from coordinates or mask.
- Parameters:
- Raises:
ValueError – If neither coords nor mask is provided If mask is provided without start_pos
- fill_solid(color)[source]
Fills the patch with a solid color.
- Parameters:
color (str) – Color to fill the patch with. Can be: - Color name (e.g., ‘red’) - Hex string (e.g., ‘#FF0000’)
- Returns:
Image of the filled patch with transparency
- Return type:
PIL.Image.Image
- cast_shadow(img, kernel=(31, 31), sigma=10, color='#000000')[source]
Casts a shadow of the patch.
Note:
Returns only shadow image. Use add_layer() to add shadow to an image.
- param img:
Image to cast shadow onto
- type img:
PIL.Image.Image
- param kernel:
Size of the Gaussian kernel
- type kernel:
Tuple[int, int], default=(31, 31)
- param sigma:
Standard deviation of the Gaussian kernel
- type sigma:
float, default=10
- param color:
Color of the shadow
- type color:
str, default=”#000000”
- returns:
Image with shadow cast
- rtype:
PIL.Image.Image
- get_average_color(img)[source]
Calculates the average color of the area where the patch will be placed.
- Parameters:
img (PIL.Image.Image) – Image to analyze
- Returns:
Average color as hex string
- Return type:
- get_centroid_color(img)[source]
Calculates the color of the centroid of the patch.
- Parameters:
img (PIL.Image.Image) – Image to analyze
- Returns:
Centroid color as hex string
- Return type:
- get_darkest_color(img)[source]
Calculates the darkest color of the area where the patch will be placed.
- Parameters:
img (PIL.Image.Image) – Image to analyze
- Returns:
Darkest color as hex string
- Return type:
- get_lightest_color(img)[source]
Calculates the lightest color of the area where the patch will be placed.
- Parameters:
img (PIL.Image.Image) – Image to analyze
- Returns:
Lightest color as hex string
- Return type:
- draw(fig, size)[source]
Draws the patch fill and shadow on an image.
- Parameters:
fig (matplotlib.figure.Figure) – Figure to draw on
size (Tuple[int, int]) – The size of the figure canvas in pixels
- Return type:
None