A convenient and user-friendly anime-style image data processing library that integrates various advanced anime-style image processing models.
You can simply install it with pip
command line from the official PyPI site.
pip install -e .
For more information about installation, you can refer to Installation.
- Tachie(差分) Detection and Clustering
- Contrastive Character Image Pretraining
- Object Detection
- Edge Detection / Lineart Generation
- Monochrome Image Detection
- Truncated Image Check
- Image Tagging
- Character Extraction
imgutils
also includes many other features besides that. For detailed descriptions and examples, please refer to
the official documentation. Here, we won't go into each of them
individually.
We can use imgutils
to extract features from anime character images (containing only a single character), calculate
the visual dissimilarity between two characters, and determine whether two images depict the same character. We can also
perform clustering operations based on this metric, as shown below
from imgutils.metrics import ccip_difference, ccip_clustering
# same character
print(ccip_difference('ccip/1.jpg', 'ccip/2.jpg')) # 0.16583099961280823
# different characters
print(ccip_difference('ccip/1.jpg', 'ccip/6.jpg')) # 0.42947039008140564
print(ccip_difference('ccip/1.jpg', 'ccip/7.jpg')) # 0.4037521779537201
print(ccip_difference('ccip/2.jpg', 'ccip/6.jpg')) # 0.4371533691883087
print(ccip_difference('ccip/2.jpg', 'ccip/7.jpg')) # 0.40748104453086853
print(ccip_difference('ccip/6.jpg', 'ccip/7.jpg')) # 0.392294704914093
images = [f'ccip/{i}.jpg' for i in range(1, 13)]
print(images)
# ['ccip/1.jpg', 'ccip/2.jpg', 'ccip/3.jpg', 'ccip/4.jpg', 'ccip/5.jpg', 'ccip/6.jpg', 'ccip/7.jpg', 'ccip/8.jpg', 'ccip/9.jpg', 'ccip/10.jpg', 'ccip/11.jpg', 'ccip/12.jpg']
print(ccip_clustering(images, min_samples=2)) # few images, min_sample should not be too large
# [0, 0, 0, 3, 3, 3, 1, 1, 1, 1, 2, 2]
For more usage, please refer to official documentation of CCIP.
Currently, object detection is supported for anime heads and person, as shown below
- Face Detection
- Head Detection
- Person Detection
Based on practical tests, head detection currently has a very stable performance and can be used for automation tasks. However, person detection is still being further iterated and will focus on enhancing detection capabilities for artistic illustrations in the future.
Anime images can be converted to line drawings using the model provided by patrickvonplaten/controlnet_aux, as shown below.
It is worth noting that the lineart
model may consume more computational resources, while canny
is the fastest but
has average effect. Therefore, lineart_anime
may be the most balanced choice in most cases.
The following code can be used to detect incomplete image files (such as images interrupted during the download process):
from imgutils.validate import is_truncated_file
if __name__ == '__main__':
filename = 'test_jpg.jpg'
if is_truncated_file(filename):
print('This image is truncated, you\'d better '
'remove this shit from your dataset.')
else:
print('This image is okay!')
When we need to extract the character parts from anime images, we can use
the segment-rgba-with-isnetis
function for extraction and obtain an RGBA format image (with the background part being transparent), just like the
example shown below.
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')
This model can be found at https://huggingface.co/skytnt/anime-seg .