filesystem write_annotation_image¶
Description¶
アノテーションzip、またはそれを展開したディレクトリから、Semantic Segmentation用のアノテーションの画像を生成します。
画像化対象のアノテーションは、アノテーションデータの _type
が以下の場合です。
BoundingBox
(矩形)Points
(ポリゴン or ポリライン)Segmentation
(塗りつぶし)SegmentationV2
(塗りつぶしv2)
警告
filesystem write_annotation_image
コマンドは非推奨です。2022-12-01以降に廃止する予定です。
替わりに filesystem draw_image
コマンドを利用してください。
Examples¶
基本的な使い方¶
--annotation
には、Annofabからダウンロードしたアノテーションzipか、アノテーションzipを展開したディレクトリを指定してください。
アノテーションzipは、annofabcli annotation download コマンドでダウンロードできます。
# アノテーションzipをダウンロードする。
$ annofabcli annotation download --project_id prj1 --output annotation.zip
--label_color
には、ラベル名とRGB値の対応関係をJSON形式で指定してください。
{"dog": [0,0,255],
"cat": [255,0,0]
}
アノテーション仕様画面で設定されている色を参照したい場合は、annofabcli annotation_specs list_label_color コマンドの出力結果を使用してください。
$ annofabcli annotation_specs list_label_color --project_id prj1 --output label_color.json
--image_size
には、画像サイズを {width}x{height}
の形式で指定してください。
$ annofabcli filesystem write_annotation_image --annotation annotation.zip \
--label_color '{"dog":[0,0,255], "cat": [255,0,0]}' \
--image_size 1280x720 \
--output_dir out/
ディレクトリ out
には、アノテーション画像が出力されます。ファイル名は {入力データID}.{拡張子}
です。
out/
├── input_data_id_1.png
├── input_data_id_2.png
...

警告
複数のタスクに同じ入力データが含まれている場合、出力されるアノテーション画像は上書きされます。
画像化対象の絞り込み¶
画像化対象のラベルを絞り込む場合は、--label_name
に画像化対象のラベル名を指定してください。
$ annofabcli filesystem write_annotation_image --annotation annotation.zip \
--label_color '{"dog":[0,0,255]}' \
--label_name dog \
--image_size 1280x720 \
--output_dir out/
画像化対象のタスクを絞り込む場合は、--task_id
に画像化対象のタスクのtask_idを指定してください。
task1
task2
...
$ annofabcli filesystem write_annotation_image --annotation annotation.zip \
--label_color file://label_color.json \
--task_id file://task_id.txt \
--image_size 1280x720 \
--output_dir out/
--task_status_complete
を指定すると、完了状態のタスクのみ画像化します。
$ annofabcli filesystem write_annotation_image --annotation annotation.zip \
--label_color file://label_color.json \
--task_status_complete \
--image_size 1280x720 \
--output_dir out/
画像サイズの指定¶
プロジェクトに異なるサイズの画像が含まれている場合、--image_size
は使用できません。
替わりに、入力データ全件ファイルを読み込み、入力データごとに画像サイズを取得します。
入力データ全件ファイルは、以下のコマンドでダウンロードします。
$ annfoabcli input_data download --project_id prj1 --output input_data.json
--input_data_json
に、入力データ全件ファイルを指定してください。入力データのプロパティ system_metadata.original_resolution
を参照して画像サイズを取得します。
$ annofabcli filesystem write_annotation_image --annotation annotation.zip \
--input_data_json input_data.json \
--label_color file://label_color.json \
--output_dir out/
注釈
2020-12-23 以前に登録/更新した入力データには、system_metadata.original_resolution
に画像サイズ情報は格納されていません。
警告
入力データのメタデータのキーで画像サイズを取得するオプション --metadata_key_of_image_size
は、廃止予定です。
2020-12-24 以降に登録/更新した入力データは、プロパティ system_metadata.original_resolution
に画像サイズが設定されるためです。
画像フォーマットの指定¶
デフォルトでは"png"画像が出力されます。画像フォーマットを指定する場合は、--image_extension
に出力される画像の拡張子を指定してください。
$ annofabcli filesystem write_annotation_image --annotation annotation.zip \
--label_color file://label_color.json \
--image_extension bmp \
--image_size 1280x720 \
--output_dir out/
背景色の指定¶
デフォルトでは背景は黒色です。 --background_color
に以下のようなフォーマットで色を指定すると、背景色を指定できます。
rgb(173, 216, 230)
lightgrey
#add8e6
サポートしているフォーマットは、Pillow - ImageColor Module を参照してください。
$ annofabcli filesystem write_annotation_image --annotation annotation.zip \
--label_color file://label_color.json \
--background_color "rgb(255,255,255)" \
--image_size 1280x720 \
--output_dir out/
Usage Details¶
[DEPRECATED] アノテーションzipを展開したディレクトリから、アノテーションの画像(Semantic Segmentation用)を生成する。矩形、ポリゴン、塗りつぶし、塗りつぶしv2が対象。
usage: annofabcli filesystem write_annotation_image [-h] [--yes]
[--endpoint_url ENDPOINT_URL]
[--logdir LOGDIR]
[--disable_log] [--debug]
--annotation ANNOTATION
(--image_size IMAGE_SIZE | --input_data_json INPUT_DATA_JSON)
[--label_name LABEL_NAME [LABEL_NAME ...]]
--label_color LABEL_COLOR
-o OUTPUT_DIR
[--image_extension {png,bmp,jpeg,jpg,gif,tif,tiff}]
[--background_color BACKGROUND_COLOR]
[--task_status_complete]
[-t TASK_ID [TASK_ID ...]]
[-tq TASK_QUERY]
Named Arguments¶
- --annotation
アノテーションzip、またはzipを展開したディレクトリ
- --image_size
画像サイズ。{width}x{height}。ex) 1280x720
- --input_data_json
入力データ情報が記載されたJSONファイルのパスを指定してください。入力データのプロパティ
system_metadata.original_resolution
を参照して画像サイズを決めます。JSONファイルは$ annofabcli input_data download
コマンドで取得できます。- --label_name
画像化対象のlabel_nameを指定します。指定しない場合は、すべてのlabel_nameが画像化対象になります。
file://
を先頭に付けると、label_name の一覧が記載されたファイルを指定できます。- --label_color
label_nameとRGBの関係をJSON形式で指定します。ex)
{"dog":[255,128,64], "cat":[0,0,255]}
file://
を先頭に付けると、JSON形式のファイルを指定できます。- -o, --output_dir
出力ディレクトリのパス
- --image_extension
Possible choices: png, bmp, jpeg, jpg, gif, tif, tiff
出力画像の拡張子を指定してください。
Default: "png"
- --background_color
アノテーションの画像の背景色を指定します。ex): "rgb(173, 216, 230)", "lightgrey", "#add8e6" [ImageColor Module](https://pillow.readthedocs.io/en/stable/reference/ImageColor.html) がサポートする文字列を利用できます。指定しない場合は、黒(rgb(0,0,0))になります。
- --task_status_complete
taskのstatusがcompleteの場合のみ画像を生成します。ただし非推奨です。替わりに
--task_query
を使ってください。- -t, --task_id
画像化するタスクのtask_idを指定します。指定しない場合、すべてのタスクが画像化されます。
file://
を先頭に付けると、task_idの一覧が記載されたファイルを指定できます。- -tq, --task_query
タスクを絞り込むためのクエリ条件をJSON形式で指定します。使用できるキーは task_id, status, phase, phase_stage です。
file://
を先頭に付けると、JSON形式のファイルを指定できます。
global optional arguments¶
- --yes
処理中に現れる問い合わせに対して、常に
yes
と回答します。- --endpoint_url
Annofab WebAPIのエンドポイントを指定します。
Default: "https://annofab.com"
- --logdir
ログファイルを保存するディレクトリを指定します。
Default: .log
- --disable_log
ログを無効にします。
- --debug
HTTPリクエストの内容やレスポンスのステータスコードなど、デバッグ用のログが出力されます。