dsa-helpers 1.0.1.dev0__tar.gz → 1.0.2.dev0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. {dsa_helpers-1.0.1.dev0/dsa_helpers.egg-info → dsa_helpers-1.0.2.dev0}/PKG-INFO +1 -1
  2. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/girder_utils.py +92 -0
  3. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0/dsa_helpers.egg-info}/PKG-INFO +1 -1
  4. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/pyproject.toml +1 -1
  5. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/.gitignore +0 -0
  6. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/.readthedocs.yaml +0 -0
  7. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/LICENSE +0 -0
  8. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/README.md +0 -0
  9. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/app.py +0 -0
  10. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/docs/requirements.txt +0 -0
  11. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/docs/source/conf.py +0 -0
  12. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/docs/source/index.rst +0 -0
  13. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/__init__.py +0 -0
  14. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/dash/__init__.py +0 -0
  15. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/dash/dash_paperdragon_utils.py +0 -0
  16. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/dash/header.py +0 -0
  17. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/dash/header_callbacks.py +0 -0
  18. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/imread.py +0 -0
  19. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/imwrite.py +0 -0
  20. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/ml/__init__.py +0 -0
  21. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/ml/callbacks.py +0 -0
  22. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/ml/datasets/SegFormerSegmentationDataset.py +0 -0
  23. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/ml/datasets/__init__.py +0 -0
  24. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/ml/datasets/utils.py +0 -0
  25. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/ml/evaluate.py +0 -0
  26. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/ml/metrics.py +0 -0
  27. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/ml/object_detection/__init__.py +0 -0
  28. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/ml/object_detection/get_pearce_roi_images.py +0 -0
  29. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/ml/object_detection/tile_image.py +0 -0
  30. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/ml/object_detection/utils.py +0 -0
  31. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/ml/segformer_semantic_segmentation/__init__.py +0 -0
  32. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/ml/segformer_semantic_segmentation/inference.py +0 -0
  33. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/ml/transforms/__init__.py +0 -0
  34. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/ml/transforms/segformer_transforms.py +0 -0
  35. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/mongo_utils.py +0 -0
  36. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/tile_utils.py +0 -0
  37. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/tiling.py +0 -0
  38. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers/utils.py +0 -0
  39. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers.egg-info/SOURCES.txt +0 -0
  40. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers.egg-info/dependency_links.txt +0 -0
  41. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers.egg-info/requires.txt +0 -0
  42. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/dsa_helpers.egg-info/top_level.txt +0 -0
  43. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/setup.cfg +0 -0
  44. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/tests/app/Dockerfile +0 -0
  45. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/tests/app/app.py +0 -0
  46. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/tests/docker-compose.yaml +0 -0
  47. {dsa_helpers-1.0.1.dev0 → dsa_helpers-1.0.2.dev0}/tests/test.ipynb +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dsa_helpers
3
- Version: 1.0.1.dev0
3
+ Version: 1.0.2.dev0
4
4
  Summary: Utility functions for working with the DSA girder client.
5
5
  Author-email: "Juan C. Vizcarra" <jvizcar@emory.edu>
6
6
  Maintainer-email: "Juan C. Vizcarra" <jvizcar@emory.edu>
@@ -576,3 +576,95 @@ def post_annotations_from_gdf(
576
576
  )
577
577
 
578
578
  return response
579
+
580
+
581
+ def get_thumbnail_with_mask(
582
+ gc: GirderClient,
583
+ item_id: str,
584
+ mag: float,
585
+ doc_name: str,
586
+ label2id: dict,
587
+ background_label: int = 0,
588
+ ):
589
+ """Get the thumbnail (i.e. low resolution image) and a label mask
590
+ drawn from annotation documents for an item.
591
+
592
+ Args:
593
+ gc (girder_client.GirderClient): The Girder client to use.
594
+ item_id (str): The item id of the image to get the thumbnail
595
+ and mask from.
596
+ mag (float): The magnification to get the thumbnail at.
597
+ doc_name (str): The name of the annotation document(s) to use.
598
+ label2id (dict): A dictionary mapping the label names to ids,
599
+ for generating the mask.
600
+ background_label (int, optional): The label to use for the
601
+ background. Defaults to 0.
602
+
603
+ Returns:
604
+ tuple: A tuple containing the thumbnail image and the mask.
605
+
606
+ """
607
+ # Get the thumbnail of the image.
608
+ thumbnail = get_thumbnail(gc, item_id, mag=mag)[:, :, :3]
609
+
610
+ # Get the width and h eight of the thumbnail.
611
+ h, w = thumbnail.shape[:2]
612
+
613
+ # Get the item large image metadata to get its scan magnification.
614
+ large_image_metadata = gc.get(f"item/{item_id}/tiles")
615
+ scan_mag = large_image_metadata["magnification"]
616
+
617
+ # Calculate a scale factor to go from full scale coordinates to thumbnail ones.
618
+ sf = mag / scan_mag
619
+
620
+ # Create a blank background mask.
621
+ mask = np.ones((h, w), dtype=np.uint8) * background_label
622
+
623
+ # Get annotation metadata for docs of interest.
624
+ for ann_doc in gc.get(
625
+ f"annotation",
626
+ parameters={"itemId": item_id, "name": doc_name, "limit": 0},
627
+ ):
628
+ # Get the full annotation document.
629
+ doc = gc.get(f"annotation/{ann_doc['_id']}")
630
+
631
+ # Get the elements.
632
+ for element in doc.get("annotation", {}).get("elements", []):
633
+ # Check if the label of the element is in the label2id dictionary.
634
+ if element.get("label", {}).get("value") not in label2id:
635
+ continue
636
+
637
+ label = element["label"]["value"]
638
+
639
+ # Create a mask for this element as background.
640
+ element_mask = np.ones((h, w), dtype=np.uint8) * background_label
641
+
642
+ if element["type"] == "polyline":
643
+ points = (np.array(element["points"])[:, :2] * sf).astype(int)
644
+
645
+ holes = []
646
+
647
+ for hole in element.get("holes", []):
648
+ holes.append((np.array(hole)[:, :2] * sf).astype(int))
649
+ elif element["rectangle"]:
650
+ # Format the rectangle as a polyline.
651
+ points = (get_rectangle_element_coords(element) * sf).astype(
652
+ int
653
+ )
654
+
655
+ # Draw the points on the mask with 1.
656
+ element_mask = cv.drawContours(
657
+ element_mask, [points], -1, 1, cv.FILLED
658
+ )
659
+
660
+ if len(holes):
661
+ # Draw the holes on the mask with 0.
662
+ element_mask = cv.drawContours(
663
+ element_mask, holes, -1, 0, cv.FILLED
664
+ )
665
+
666
+ # Specify the label of the elements on the thumbnail mask.
667
+ mask[element_mask == 1] = label2id[label]
668
+
669
+ # Return the thumbnail and the mask.
670
+ return thumbnail, mask
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dsa_helpers
3
- Version: 1.0.1.dev0
3
+ Version: 1.0.2.dev0
4
4
  Summary: Utility functions for working with the DSA girder client.
5
5
  Author-email: "Juan C. Vizcarra" <jvizcar@emory.edu>
6
6
  Maintainer-email: "Juan C. Vizcarra" <jvizcar@emory.edu>
@@ -35,7 +35,7 @@ classifiers = [
35
35
  "License :: OSI Approved :: MIT License",
36
36
  ]
37
37
  keywords = ["dsa", "girder", "girder_client"]
38
- version = "v1.0.1dev0"
38
+ version = "v1.0.2dev0"
39
39
 
40
40
  [project.urls]
41
41
  Repository = "https://github.com/Gutman-Lab/dsa-python-utils"