• This repository has been archived on 17/Jul/2020
  • Stars
    star
    520
  • Rank 82,455 (Top 2 %)
  • Language
    JavaScript
  • License
    BSD 3-Clause "New...
  • Created over 10 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Javascript image annotation tool based on image segmentation.

JS Segment Annotator

Javascript image annotation tool based on image segmentation.

  • Label image regions with mouse.
  • Written in vanilla Javascript, with require.js dependency (packaged).
  • Pure client-side implementation of image segmentation.

A browser must support HTML canvas to use this tool.

There is an online demo.

Importing data

Prepare a JSON file that looks like the following. The required fields are labels and imageURLs. The annotationURLs are for existing data and can be omitted. Place the JSON file inside the data/ directory.

{
  "labels": [
    "background",
    "skin",
    "hair",
    "dress",
    "glasses",
    "jacket",
    "skirt"
  ],
  "imageURLs": [
    "data/images/1.jpg",
    "data/images/2.jpg"
  ],
  "annotationURLs": [
    "data/annotations/1.png",
    "data/annotations/2.png"
  ]
}

Then edit main.js to point to this JSON file. Open a Web browser and visit index.html.

Known issues

Browser incompatibility

A segmentation result can greatly differ due to the difference in Javascript implementation across Web browsers. The difference stems from numerical precision of floating point numbers, and there is no easy way to produce the exact same result across browsers.

Python tips

Annotation PNG

The annotation PNG file contains label map encoded in RGB value. Do the following to encode an index map.

import numpy as np
from PIL import Image

# Decode
encoded = np.array(Image.open('data/annotations/1.png'))
annotation = np.bitwise_or(np.bitwise_or(
    encoded[:, :, 0].astype(np.uint32),
    encoded[:, :, 1].astype(np.uint32) << 8),
    encoded[:, :, 2].astype(np.uint32) << 16)

print(np.unique(annotation))

# Encode
Image.fromarray(np.stack([
    np.bitwise_and(annotation, 255),
    np.bitwise_and(annotation >> 8, 255),
    np.bitwise_and(annotation >> 16, 255),
    ], axis=2).astype(np.uint8)).save('encoded.png')

JSON

Use JSON module.

import json

with open('data/example.json', 'r') as f:
    dataset = json.load(f)

Using dataURL

Do the following to convert between dataURL and NumPy format.

from PIL import Image
import base64
import io

# Encode
with io.BytesIO() as buffer:
    encoded.save(buffer, format='png')
    data_url = b'data:image/png;base64,' + base64.b64encode(buffer.getvalue())

# Decode
binary = base64.b64decode(data_url.replace(b'data:image/png;base64,', b''))
encoded = Image.open(io.BytesIO(binary))

Matlab tips

Annotation PNG

The annotation PNG file contains label map encoded in RGB value. Do the following to encode an index map.

% Decode

X = imread('data/annotations/0.png');
annotation = X(:, :, 1);
annotation = bitor(annotation, bitshift(X(:, :, 2), 8));
annotation = bitor(annotation, bitshift(X(:, :, 3), 16));

% Encode

X = cat(3, bitand(annotation, 255), ...
           bitand(bitshift(annotation, -8), 255), ...
           bitand(bitshift(annotation, -16)), 255));
imwrite(uint8(X), 'data/annotations/0.png');

JSON

Use the matlab-json package.

Using dataURL

Get the byte encoding tools.

Do the following to convert between dataURL and Matlab format.

% Decode

dataURL = 'data:image/png;base64,...';
png_data = base64decode(strrep(dataURL, 'data:image/png;base64,', ''));
annotation = imdecode(png_data, 'png');

% Encode

png_data = imencode(annotation, 'png');
dataURL = ['data:image/png;base64,', base64encode(png_data)];

Citation

We appreciate if you cite the following article in an academic paper. The tool was originally developed for this work.

@article{tangseng2017looking,
Author        = {Pongsate Tangseng and Zhipeng Wu and Kota Yamaguchi},
Title         = {Looking at Outfit to Parse Clothing},
Eprint        = {1703.01386v1},
ArchivePrefix = {arXiv},
PrimaryClass  = {cs.CV},
Year          = {2017},
Month         = {Mar},
Url           = {http://arxiv.org/abs/1703.01386v1}
}

More Repositories

1

mexopencv

Collection and a development kit of matlab mex functions for OpenCV library
MATLAB
655
star
2

faiss-wheels

Unofficial faiss wheel builder
Python
260
star
3

skia-python

Python binding to Skia Graphics Library
Jupyter Notebook
216
star
4

bbox-annotator

A bounding box annotation widget written in CoffeeScript.
HTML
161
star
5

mexplus

C++ Matlab MEX development kit.
C++
98
star
6

paperdoll

Paper doll parser implementation from ICCV 2013
Jupyter Notebook
83
star
7

matlab-json

Use official API: https://mathworks.com/help/matlab/json-format.html
Java
52
star
8

psd2svg

PSD to SVG converter.
Python
50
star
9

matlab-lmdb

Matlab LMDB wrapper
C
38
star
10

js-graph-annotator

Javascript widget to draw a graph annotation on an image.
JavaScript
37
star
11

matlab-sqlite3-driver

Matlab driver for SQLite3 database
C
35
star
12

sge-gpuprolog

Scripts to manage NVIDIA GPU devices in SGE 6.2u5
Shell
24
star
13

photoshop-connection

Python package to remotely execute ExtendScript in Adobe Photoshop.
Python
22
star
14

pf-segmentation

Image segmentation algorithm of [P Felzenszwalb 2004] for Matlab
C++
16
star
15

matlab-leveldb

Matlab LevelDB wrapper
C++
11
star
16

matlab-tcpip

TCP/IP server and client for Matlab
MATLAB
11
star
17

lda-matlab

Latent Dirichlet Allocation for Matlab
C++
4
star
18

matlab-fscache

File-system based cache for Matlab.
MATLAB
4
star
19

matlab-bson

Matlab BSON encoder based on libbson.
C
4
star
20

matlab-bdb

Persistent key-value storage for matlab.
C++
3
star
21

matlab-batch

Distributed Matlab job execution library.
MATLAB
3
star
22

matlab-serialization

Matlab object serialization functions
C++
2
star
23

matlab-ejdb

EJDB Matlab binding
C++
1
star