Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

Simple python API to read annotation data of Manga109

Project description

Manga109 API

PyPI version

Simple python API to read annotation data of Manga109.

Manga109 is the largest dataset for manga (Japanese comic) images, that is made publicly available for academic research purpose with proper copyright notation.

To download images/annotations of Manga109, please visit here and send an application via the form. After that, you will receive the password for downloading images (109 titles of manga as jpeg files) and annotations (bounding box coordinates of face, body, frame, and speech balloon with texts, in the form of XML).

This package provides a simple Python API to read annotation data (i.e., parsing XML) with some utility functions such as reading an image.



You can install the package via pip. The library works with Python 3.5+ on linux

pip install manga109api


You can insantiate a parser with the path to the root directory of Manga109. The annotations are available via the parser.

import manga109api
from pprint import pprint

manga109_root_dir = "YOUR_DIR/Manga109_2017_09_28"
p = manga109api.Parser(root_dir=manga109_root_dir)

# ['ARMS', 'AisazuNihaIrarenai', 'AkkeraKanjinchou', 'Akuhamu', 'AosugiruHaru', ...

# {'book': {'@title': 'ARMS',
#           'characters': {'character': [{'@id': '00000003', '@name': '女1'},
#                                        {'@id': '00000010', '@name': '男1'},
#                                        {'@id': '00000090', '@name': 'ロボット1'},
#                                        {'@id': '000000fe', '@name': 'エリー'},
#                                        {'@id': '0000010a', '@name': 'ケイト'},
#                                        {'@id': '0000010e', '@name': '大佐'},
# ...
#           'pages': {'page': [{'@height': 1170, '@index': 0, '@width': 1654},
#                              {'@height': 1170, '@index': 1, '@width': 1654},
#                              {'@height': 1170,
#                               '@index': 2,
#                               '@width': 1654,
#                               'body': {'@character': '00000003',
#                                        '@id': '00000002',
#                                        '@xmax': 548,
#                                        '@xmin': 178,
#                                        '@ymax': 965,
#                                        '@ymin': 660},
#                               'face': {'@character': '00000003',
#                                        '@id': '00000004',
#                                        '@xmax': 456,
#                                        '@xmin': 406,
# ...

# annotations of the 7th page
# {'@height': 1170,
#  '@index': 6,
#  '@width': 1654,
#  'body': [{'@character': '00000010',
#            '@id': '00000057',
#            '@xmax': 1155,
#            '@xmin': 1089,
#            '@ymax': 253,
#            '@ymin': 166},
#           {'@character': '00000003',
#            '@id': '0000005f',
#            '@xmax': 302,
#            '@xmin': 125,
#            '@ymax': 451,
#            '@ymin': 314},
# ... 

# image path to the 7th page
print(p.img_path(book="ARMS", index=6))  
# YOUR_DIR/Manga109_2017_09_28/images/ARMS/006.jpg

The text data is also available:

pprint([roi["#text"] for roi in p.annotations["ARMS"]["book"]["pages"]["page"][6]["text"]])
# ['どこへ行きやがった!?',
#  'ティーザー=電気ショックによる麻痺銃',
#  'えーいちょろちょろと',
#  'あつっ',
#  'そこだ!',
#  '出て来て正々堂々と戦え!',
#  '!',
#  '私を生捕りにする気!?',
#  '卑怯者っ',
#  'ティーザー!!',
#  'やろォ',
#  'キャア',
#  'あっまた逃げた',
#  'わーっ']

An example of visualization is as follows

from PIL import Image, ImageDraw

def draw_rectangle(img, x0, y0, x1, y1, annotation_type):
    assert annotation_type in ["body", "face", "frame", "text"]
    color = {"body": "#258039", "face": "#f5be41",
             "frame": "#31a9b8", "text": "#cf3721"}[annotation_type]
    width = 10
    draw = ImageDraw.Draw(img)
    draw.line([x0 - width/2, y0, x1 + width/2, y0], fill=color, width=width)
    draw.line([x1, y0, x1, y1], fill=color, width=width)
    draw.line([x1 + width/2, y1, x0 - width/2, y1], fill=color, width=width)
    draw.line([x0, y1, x0, y0], fill=color, width=width)

img ="ARMS", index=6))
for annotation_type in ["body", "face", "frame", "text"]:
    rois = p.annotations["ARMS"]["book"]["pages"]["page"][6][annotation_type]
    for roi in rois:
        draw_rectangle(img, roi["@xmin"], roi["@ymin"], roi["@xmax"], roi["@ymax"], annotation_type)

ARMS, (c) Kato Masaki



When you make use of images in Manga109, please cite the following paper:

    author={Yusuke Matsui and Kota Ito and Yuji Aramaki and Azuma Fujimoto and Toru Ogawa and Toshihiko Yamasaki and Kiyoharu Aizawa},
    title={Sketch-based Manga Retrieval using Manga109 Dataset},
    journal={Multimedia Tools and Applications},

When you use annotation data of Manga109, please cite this:

    author={Toru Ogawa and Atsushi Otsubo and Rei Narita and Yusuke Matsui and Toshihiko Yamasaki and Kiyoharu Aizawa},
    title={Object Detection for Comics using Manga109 Annotations},

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
manga109api-0.1.0-py3-none-any.whl (4.8 kB) Copy SHA256 hash SHA256 Wheel py3
manga109api-0.1.0.tar.gz (5.5 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page