-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add function to create multiple annotations from the same image. Closes
#29 The functionality is implemented in a new function `create_annotation_infos` with a similar API as the already existing `create_annotation_info`. I think it makes sense to have a dedicated function for this use-case. An example is at `samples/multi-annotations`.
- Loading branch information
1 parent
207b4fa
commit feb8d5c
Showing
3 changed files
with
87 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from pathlib import Path | ||
import json | ||
|
||
from PIL import Image | ||
import numpy as np | ||
|
||
from pycococreatortools import pycococreatortools | ||
|
||
SAMPLE_IMAGE_PATH = Path(__file__).parent / "sample.png" | ||
assert SAMPLE_IMAGE_PATH.exists() | ||
|
||
raw_image_bitmask = Image.open(SAMPLE_IMAGE_PATH) | ||
image_bitmask = np.asarray(raw_image_bitmask.convert("1")).astype(np.uint8) | ||
|
||
annotation_infos = pycococreatortools.create_annotation_infos( | ||
1, 1, {"id": 1}, image_bitmask, raw_image_bitmask.size, tolerance=2, connectivity=1 | ||
) | ||
|
||
print(f"Found {len(annotation_infos)} annotations in the image:") | ||
print(json.dumps(annotation_infos, indent=4)) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters