Skip to content

Commit 8c1f1bd

Browse files
committed
2 parents bb4012a + 95c2e11 commit 8c1f1bd

31 files changed

+4014
-214
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ all: coverage tests
1010
$(PYTHON) setup.py build_ext --inplace
1111

1212
tests:
13-
$(PYTESTS)
13+
$(PYTESTS) -n 8
1414

1515
stress-tests: AO_TEST_LEVEL=stress
1616
stress-tests: tests
17-
$(PYTESTS)
17+
$(PYTESTS) -n 8
1818

1919
clean:
2020
rm -rf superannotate.egg-info
64.6 KB
Loading

docs/source/class_distribution.png

47.5 KB
Loading

docs/source/pandas_df.png

98.7 KB
Loading

docs/source/superannotate.sdk.rst

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ _____________________________________________________________
318318

319319
----------
320320

321-
Editing annotations
322-
____________________
321+
Working with annotations
322+
________________________
323323

324324
.. _ref_add_annotation_bbox_to_json:
325325
.. autofunction:: superannotate.add_annotation_bbox_to_json
@@ -329,9 +329,22 @@ ____________________
329329
.. autofunction:: superannotate.add_annotation_ellipse_to_json
330330
.. autofunction:: superannotate.add_annotation_template_to_json
331331
.. autofunction:: superannotate.add_annotation_cuboid_to_json
332+
.. autofunction:: superannotate.aggregate_annotations_as_df
333+
.. autofunction:: superannotate.df_to_annotations
334+
.. _ref_filter_annotation_instances:
335+
.. autofunction:: superannotate.filter_annotation_instances
336+
337+
----------
332338

333339
Aggregating class distribution from annotations
334340
_____________________________________________________________
335341

336342
.. autofunction:: superannotate.class_distribution
337-
.. autofunction:: superannotate.attribute_distribution
343+
.. autofunction:: superannotate.attribute_distribution
344+
345+
----------
346+
347+
Utility functions
348+
--------------------------------
349+
350+
.. autofunction:: superannotate.dicom_to_rgb_sequence

docs/source/tutorial.sdk.rst

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,25 +342,109 @@ project with the found contributor as an QA:
342342
343343
sa.share_project(project, "hovnatan@superannotate.com", user_role="QA")
344344
345+
346+
347+
----------
348+
349+
350+
pandas DataFrame out of project annotations and annotation instance filtering
351+
_____________________________________________________________________________
352+
353+
354+
To create a `pandas DataFrame <https://pandas.pydata.org/>`_ from project
355+
SuperAnnotate format annotations:
356+
357+
.. code-block:: python
358+
359+
df = sa.aggregate_annotations_as_df("<path_to_project_folder>")
360+
361+
The created DataFrame will have columns :code:`imageName`, :code:`instanceId`,
362+
:code:`className`, :code:`attributeGroupName`, :code:`attributeName`, :code:`type`, :code:`error`, :code:`locked`, :code:`visible`, :code:`trackingId`, :code:`probability`, :code:`pointLabels`, :code:`meta` (geometry information as string), :code:`commentResolved`, :code:`classColor`, :code:`groupId`.
363+
364+
Example of created DataFrame:
365+
366+
.. image:: pandas_df.png
367+
368+
Each row represents annotation information. One full annotation with multiple
369+
attribute groups can be grouped under :code:`instanceId` field.
370+
371+
A helper function :ref:`filter_annotation_instances <ref_filter_annotation_instances>` to annotation instances by their class or attribute from the DataFrame is available. E.g., to get annotations that have annotation class :code:`Human` and attribute :code:`"height" : "tall"` that are **not** of type :code:`polygon`:
372+
373+
.. code-block:: python
374+
375+
filtered_df = sa.filter_annotation_instances(df, include=[{"className" : "Human",
376+
"attributes" : [{"groupName" : "height",
377+
"name" : "tall"}]
378+
}],
379+
exclude=[{"type" : "polygon"}])
380+
381+
To transform back pandas DataFrame annotations to SuperAnnotate format annotation:
382+
383+
.. code-block:: python
384+
385+
sa.df_to_annotations(filtered_df, "<path_to_output_folder>")
386+
387+
388+
----------
389+
390+
345391
Aggregating class distribution across multiple projects
346-
______________________________
392+
_______________________________________________________
347393

348394
After exporting annotations from multiple projects, it is possible to aggregate class distribution of annotated instances as follows
349395

350396
.. code-block:: python
351397
352398
df = sa.class_distribution("<path_to_export_folder>", [project_names])
353399
354-
Aggregated distribution is returned as pandas dataframe with columns class_name and count. Enabling visualize flag plots histogram of obtained distribution.
400+
Aggregated distribution is returned as pandas dataframe with columns className and count. Enabling visualize flag plots histogram of obtained distribution.
355401

356402
.. code-block:: python
357403
358404
df = sa.class_distribution("<path_to_export_folder>", [project_names], visualize = True)
359405
406+
.. image:: class_distribution.png
407+
408+
360409
Similarly aggregation of class attributes across multiple projects can be obtained with
361410

362411
.. code-block:: python
363412
364413
df = sa.attribute_distribution("<path_to_export_folder>", [project_names], visualize = True)
365414
366-
Here pandas dataframe with columns identifying attribute and corresponding instance count is returned. Within visualized histogram attributes of the same class are grouped by color and sorted accordingly.
415+
Here pandas DataFrame with columns identifying attribute and corresponding instance count is returned. Within visualized histogram attributes of the same class are grouped by color and sorted accordingly.
416+
417+
.. image:: attribute_distribution.png
418+
419+
----------
420+
421+
422+
Working with DICOM files
423+
_______________________________________________________
424+
425+
426+
To convert DICOM file images to JPEG images:
427+
428+
429+
.. code-block:: python
430+
431+
df = sa.dicom_to_rgb_sequence("<path_to_dicom_file>", "<path_to_output_dir>")
432+
433+
JPEG images with names :file:`<dicom_file_name>_<frame_num>.jpg` will be created
434+
in :file:`<path_to_output_dir>`. Those JPEG images can be uploaded to
435+
SuperAnnotate platform using the regular:
436+
437+
.. code-block:: python
438+
439+
sa.upload_images_from_folder_to_project(project, "<path_to_output_dir>")
440+
441+
Some DICOM files can have image frames that are compressed. To load them, `GDCM :
442+
Grassroots DICOM library <http://gdcm.sourceforge.net/wiki/index.php/Main_Page>`_ needs to be installed:
443+
444+
.. code-block:: bash
445+
446+
# using conda
447+
conda install -c conda-forge gdcm
448+
449+
# or on Ubuntu with versions above 19.04
450+
sudo apt install python3-gdcm

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pydicom>=2.0.0
12
boto3>=1.14.53
23
requests>=2.23.0
34
requests-toolbelt>=0.9.1

0 commit comments

Comments
 (0)