imgutils.segment.isnetis
- Overview:
Anime character segmentation, based on https://huggingface.co/skytnt/anime-seg .
get_isnetis_mask
- imgutils.segment.isnetis.get_isnetis_mask(image: str | PathLike | bytes | bytearray | BinaryIO | Image, scale: int = 1024)[source]
- Overview:
Get mask with isnetis.
- Parameters:
image – Original image (assume its size is
(H, W)
).scale – Scale when passing it into neural network. Default is
1024
, inspired by https://huggingface.co/spaces/skytnt/anime-remove-background/blob/main/app.py#L8 .
- Returns:
Get a mask with all the pixels, which shape is
(H, W)
.
segment_with_isnetis
- imgutils.segment.isnetis.segment_with_isnetis(image: str | PathLike | bytes | bytearray | BinaryIO | Image, background: str = 'lime', scale: int = 1024)[source]
- Overview:
Segment image with pure color background.
- Parameters:
image – Original image (assume its size is
(H, W)
).background – Background color for padding. Default is
lime
which represents#00ff00
.scale – Scale when passing it into neural network. Default is
1024
, inspired by https://huggingface.co/spaces/skytnt/anime-remove-background/blob/main/app.py#L8 .
- Returns:
The mask and An RGB image featuring a pure-colored background along with a segmented image.
- Examples::
>>> from imgutils.segment import segment_with_isnetis >>> >>> mask_, image_ = segment_with_isnetis('hutao.png') >>> image_.save('hutao_seg.png') >>> >>> mask_, image_ = segment_with_isnetis('skadi.jpg', background='white') # white background >>> image_.save('skadi_seg.jpg')
The result should be
segment_rgba_with_isnetis
- imgutils.segment.isnetis.segment_rgba_with_isnetis(image: str | PathLike | bytes | bytearray | BinaryIO | Image, scale: int = 1024)[source]
- Overview:
Segment image with transparent background.
- Parameters:
image – Original image (assume its size is
(H, W)
).scale – Scale when passing it into neural network. Default is
1024
, inspired by https://huggingface.co/spaces/skytnt/anime-remove-background/blob/main/app.py#L8 .
- Returns:
The mask and An RGBA image featuring a transparent background along with a segmented image.
- Examples::
>>> from imgutils.segment import segment_rgba_with_isnetis >>> >>> mask_, image_ = segment_rgba_with_isnetis('hutao.png') >>> image_.save('hutao_seg.png') >>> >>> mask_, image_ = segment_rgba_with_isnetis('skadi.jpg') >>> image_.save('skadi_seg.png')
The result should be