anybioimage 0.3.0__py3-none-any.whl

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.
@@ -0,0 +1,24 @@
1
+ """BioImageViewer - Interactive image viewer widget with annotation tools."""
2
+
3
+ from .viewer import BioImageViewer
4
+ from .utils import (
5
+ MASK_COLORS,
6
+ CHANNEL_COLORS,
7
+ normalize_image,
8
+ array_to_base64,
9
+ labels_to_rgba,
10
+ hex_to_rgb,
11
+ composite_channels,
12
+ )
13
+
14
+ __version__ = "0.1.0"
15
+ __all__ = [
16
+ "BioImageViewer",
17
+ "MASK_COLORS",
18
+ "CHANNEL_COLORS",
19
+ "normalize_image",
20
+ "array_to_base64",
21
+ "labels_to_rgba",
22
+ "hex_to_rgb",
23
+ "composite_channels",
24
+ ]
@@ -0,0 +1,15 @@
1
+ """Mixin classes for BioImageViewer functionality."""
2
+
3
+ from .image_loading import ImageLoadingMixin
4
+ from .mask_management import MaskManagementMixin
5
+ from .annotations import AnnotationsMixin
6
+ from .plate_loading import PlateLoadingMixin
7
+ from .sam_integration import SAMIntegrationMixin
8
+
9
+ __all__ = [
10
+ "ImageLoadingMixin",
11
+ "PlateLoadingMixin",
12
+ "MaskManagementMixin",
13
+ "AnnotationsMixin",
14
+ "SAMIntegrationMixin",
15
+ ]
@@ -0,0 +1,108 @@
1
+ """Annotations mixin for BioImageViewer."""
2
+
3
+ import pandas as pd
4
+
5
+
6
+ class AnnotationsMixin:
7
+ """Mixin class providing annotation management for BioImageViewer.
8
+
9
+ This mixin handles ROIs (rectangles), polygons, and point annotations,
10
+ providing DataFrame interfaces for easy data access and manipulation.
11
+
12
+ Attributes expected to be defined by the main class:
13
+ - _rois_data: List of ROI dicts (traitlet)
14
+ - _polygons_data: List of polygon dicts (traitlet)
15
+ - _points_data: List of point dicts (traitlet)
16
+ - selected_annotation_id: Selected annotation ID (traitlet)
17
+ - selected_annotation_type: Selected annotation type (traitlet)
18
+ """
19
+
20
+ @property
21
+ def rois_df(self) -> pd.DataFrame:
22
+ """Get ROIs as a pandas DataFrame.
23
+
24
+ Returns:
25
+ DataFrame with columns: id, x, y, width, height
26
+ """
27
+ if not self._rois_data:
28
+ return pd.DataFrame(columns=["id", "x", "y", "width", "height"])
29
+ return pd.DataFrame(self._rois_data)
30
+
31
+ @rois_df.setter
32
+ def rois_df(self, df: pd.DataFrame):
33
+ """Set ROIs from a pandas DataFrame.
34
+
35
+ Args:
36
+ df: DataFrame with columns: id, x, y, width, height
37
+ """
38
+ self._rois_data = df.to_dict("records")
39
+
40
+ @property
41
+ def polygons_df(self) -> pd.DataFrame:
42
+ """Get polygons as a pandas DataFrame.
43
+
44
+ Returns:
45
+ DataFrame with columns: id, points, num_vertices
46
+ where points is a list of {x, y} dicts
47
+ """
48
+ if not self._polygons_data:
49
+ return pd.DataFrame(columns=["id", "points", "num_vertices"])
50
+ data = []
51
+ for poly in self._polygons_data:
52
+ data.append({
53
+ "id": poly["id"],
54
+ "points": poly["points"],
55
+ "num_vertices": len(poly["points"])
56
+ })
57
+ return pd.DataFrame(data)
58
+
59
+ @polygons_df.setter
60
+ def polygons_df(self, df: pd.DataFrame):
61
+ """Set polygons from a pandas DataFrame.
62
+
63
+ Args:
64
+ df: DataFrame with columns: id, points
65
+ where points is a list of {x, y} dicts
66
+ """
67
+ records = df.to_dict("records")
68
+ self._polygons_data = [{"id": r["id"], "points": r["points"]} for r in records]
69
+
70
+ @property
71
+ def points_df(self) -> pd.DataFrame:
72
+ """Get points as a pandas DataFrame.
73
+
74
+ Returns:
75
+ DataFrame with columns: id, x, y
76
+ """
77
+ if not self._points_data:
78
+ return pd.DataFrame(columns=["id", "x", "y"])
79
+ return pd.DataFrame(self._points_data)
80
+
81
+ @points_df.setter
82
+ def points_df(self, df: pd.DataFrame):
83
+ """Set points from a pandas DataFrame.
84
+
85
+ Args:
86
+ df: DataFrame with columns: id, x, y
87
+ """
88
+ self._points_data = df.to_dict("records")
89
+
90
+ def clear_rois(self):
91
+ """Clear all rectangle ROIs."""
92
+ self._rois_data = []
93
+
94
+ def clear_polygons(self):
95
+ """Clear all polygons."""
96
+ self._polygons_data = []
97
+
98
+ def clear_points(self):
99
+ """Clear all points."""
100
+ self._points_data = []
101
+
102
+ def clear_all_annotations(self):
103
+ """Clear all annotations (ROIs, polygons, and points)."""
104
+ self.clear_rois()
105
+ self.clear_polygons()
106
+ self.clear_points()
107
+ self.selected_annotation_id = ""
108
+ self.selected_annotation_type = ""