rvimage 0.0.1__tar.gz → 0.1.0__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.
rvimage-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.4
2
+ Name: rvimage
3
+ Version: 0.1.0
4
+ Summary: Pydantic types to facilitate writing prediction APIs integrated into the image annotation tool RV Image
5
+ Project-URL: Repository, https://github.com/bertiqwerty/rvimage
6
+ Requires-Python: >=3.12
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: numpy>=2.3.0
9
+ Requires-Dist: opencv-python-headless>=4.11.0.86
10
+ Requires-Dist: pydantic>=2.11.7
11
+ Requires-Dist: scipy>=1.15.3
12
+
13
+ # RV Image
14
+
15
+ This package contains Pydantic types to facilitate writing prediction APIs integrated into the image annotation tool
16
+ [RV Image](https://github.com/bertiqwerty/rvimage).
@@ -0,0 +1,4 @@
1
+ # RV Image
2
+
3
+ This package contains Pydantic types to facilitate writing prediction APIs integrated into the image annotation tool
4
+ [RV Image](https://github.com/bertiqwerty/rvimage).
@@ -0,0 +1,16 @@
1
+ [project]
2
+ name = "rvimage"
3
+ version = "0.1.0"
4
+ description = "Pydantic types to facilitate writing prediction APIs integrated into the image annotation tool RV Image"
5
+ readme = "README.md"
6
+ requires-python = ">=3.12"
7
+ dependencies = [
8
+ "numpy>=2.3.0",
9
+ "opencv-python-headless>=4.11.0.86",
10
+ "pydantic>=2.11.7",
11
+ "scipy>=1.15.3",
12
+ ]
13
+ [project.urls]
14
+ Repository = "https://github.com/bertiqwerty/rvimage"
15
+ [dependency-groups]
16
+ dev = ["pytest>=8.4.1"]
@@ -1,5 +1,5 @@
1
1
  from typing import Self
2
- from pydantic import BaseModel
2
+ from pydantic import BaseModel, model_serializer, model_validator
3
3
  import numpy as np
4
4
  from rvimage.converters import (
5
5
  extract_polys_from_mask,
@@ -11,11 +11,6 @@ from rvimage.converters import (
11
11
  from rvimage.domain import BbF, BbI, Poly, enclosing_bb, find_ccs
12
12
 
13
13
 
14
- class GeoFig(BaseModel):
15
- bbox: BbF | None = None
16
- poly: Poly | None = None
17
-
18
-
19
14
  class Labelinfo(BaseModel):
20
15
  new_label: str
21
16
  labels: list[str]
@@ -26,10 +21,31 @@ class Labelinfo(BaseModel):
26
21
 
27
22
 
28
23
  class BboxAnnos(BaseModel):
29
- elts: list[GeoFig]
24
+ elts: list[BbF | Poly]
30
25
  cat_idxs: list[int]
31
26
  selected_mask: list[bool]
32
27
 
28
+ @model_validator(mode="before")
29
+ @classmethod
30
+ def resolve_bb_poly(cls, data: dict) -> dict:
31
+ # remove the type-info from the dict
32
+ data["elts"] = [next(v for v in d.values()) for d in data["elts"]]
33
+ return data
34
+
35
+ @model_serializer()
36
+ def serialize_model(self):
37
+ elts = [
38
+ {"BB": elt.model_dump()}
39
+ if isinstance(elt, BbF)
40
+ else {"Poly": elt.model_dump()}
41
+ for elt in self.elts
42
+ ]
43
+ return {
44
+ "cat_idxs": self.cat_idxs,
45
+ "selected_mask": self.selected_mask,
46
+ "elts": elts,
47
+ }
48
+
33
49
  @classmethod
34
50
  def from_mask(cls, mask: np.ndarray, cat_idx: int) -> "BboxAnnos":
35
51
  """
@@ -40,7 +56,7 @@ class BboxAnnos(BaseModel):
40
56
 
41
57
  return cls(
42
58
  elts=[
43
- GeoFig(poly=Poly(points=points, enclosing_bb=enclosing_bb(points)))
59
+ Poly(points=points, enclosing_bb=enclosing_bb(points))
44
60
  for points in polys
45
61
  ],
46
62
  cat_idxs=cat_idxs,
@@ -60,9 +76,9 @@ class BboxAnnos(BaseModel):
60
76
  def fill_mask(self, im_mask: np.ndarray, cat_idx: int):
61
77
  fill_polys_on_mask(
62
78
  polygons=(
63
- elt.poly.points
79
+ elt.points
64
80
  for elt, cat_idx_ in zip(self.elts, self.cat_idxs)
65
- if cat_idx == cat_idx_ and elt.poly is not None
81
+ if cat_idx == cat_idx_ and isinstance(elt, Poly)
66
82
  ),
67
83
  value=1,
68
84
  im_mask=im_mask,
@@ -70,9 +86,9 @@ class BboxAnnos(BaseModel):
70
86
  )
71
87
  fill_bbs_on_mask(
72
88
  bbs=(
73
- elt.bbox
89
+ elt
74
90
  for elt, cat_idx_ in zip(self.elts, self.cat_idxs)
75
- if cat_idx == cat_idx_ and elt.bbox is not None
91
+ if cat_idx == cat_idx_ and isinstance(elt, BbF)
76
92
  ),
77
93
  value=1,
78
94
  im_mask=im_mask,
@@ -125,10 +141,10 @@ class BrushData(BaseModel):
125
141
 
126
142
 
127
143
  class InputAnnotationData(BaseModel):
128
- bbox: BboxData
129
- brush: BrushData
144
+ bbox: BboxData | None
145
+ brush: BrushData | None
130
146
 
131
147
 
132
148
  class OutputAnnotationData(BaseModel):
133
- bbox: BboxAnnos
134
- brush: BrushAnnos
149
+ bbox: BboxAnnos | None
150
+ brush: BrushAnnos | None
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.4
2
+ Name: rvimage
3
+ Version: 0.1.0
4
+ Summary: Pydantic types to facilitate writing prediction APIs integrated into the image annotation tool RV Image
5
+ Project-URL: Repository, https://github.com/bertiqwerty/rvimage
6
+ Requires-Python: >=3.12
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: numpy>=2.3.0
9
+ Requires-Dist: opencv-python-headless>=4.11.0.86
10
+ Requires-Dist: pydantic>=2.11.7
11
+ Requires-Dist: scipy>=1.15.3
12
+
13
+ # RV Image
14
+
15
+ This package contains Pydantic types to facilitate writing prediction APIs integrated into the image annotation tool
16
+ [RV Image](https://github.com/bertiqwerty/rvimage).
@@ -1,3 +1,4 @@
1
+ numpy>=2.3.0
1
2
  opencv-python-headless>=4.11.0.86
2
3
  pydantic>=2.11.7
3
4
  scipy>=1.15.3
@@ -1,4 +1,6 @@
1
+ import json
1
2
  import numpy as np
3
+ from rvimage.collection_types import BboxAnnos, BrushAnnos
2
4
  from rvimage.converters import extract_polys_from_mask, fill_polys_on_mask
3
5
  from rvimage.converters import rle_to_mask, mask_to_rle
4
6
  from rvimage.domain import Point
@@ -39,6 +41,28 @@ def test_polygon():
39
41
  assert np.allclose(mask, mask_converted), "Masks are not equal after conversion"
40
42
 
41
43
 
44
+ def test_validation():
45
+ annos = {
46
+ "elts": [{"BB": {"x": 0.0, "y": 0.0, "w": 5.0, "h": 5.0}}],
47
+ "cat_idxs": [1],
48
+ "selected_mask": [False],
49
+ }
50
+ BboxAnnos.model_validate(annos)
51
+ with open("../rvimage/resources/test_data/rvprj_v4-0.json", "r") as f:
52
+ data_loaded = json.load(f)
53
+
54
+ def get_data(tool):
55
+ for d, _ in data_loaded["tools_data_map"][tool]["specifics"][tool][
56
+ "annotations_map"
57
+ ].values():
58
+ yield d
59
+
60
+ for brush_data in get_data("Brush"):
61
+ BrushAnnos.model_validate(brush_data)
62
+ for bbox_data in get_data("Bbox"):
63
+ BboxAnnos.model_validate(bbox_data)
64
+
65
+
42
66
  if __name__ == "__main__":
43
67
  test_rle()
44
68
  test_polygon()
rvimage-0.0.1/PKG-INFO DELETED
@@ -1,9 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: rvimage
3
- Version: 0.0.1
4
- Summary: Add your description here
5
- Requires-Python: >=3.12
6
- Description-Content-Type: text/markdown
7
- Requires-Dist: opencv-python-headless>=4.11.0.86
8
- Requires-Dist: pydantic>=2.11.7
9
- Requires-Dist: scipy>=1.15.3
rvimage-0.0.1/README.md DELETED
File without changes
@@ -1,11 +0,0 @@
1
- [project]
2
- name = "rvimage"
3
- version = "0.0.1"
4
- description = "Add your description here"
5
- readme = "README.md"
6
- requires-python = ">=3.12"
7
- dependencies = [
8
- "opencv-python-headless>=4.11.0.86",
9
- "pydantic>=2.11.7",
10
- "scipy>=1.15.3",
11
- ]
@@ -1,9 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: rvimage
3
- Version: 0.0.1
4
- Summary: Add your description here
5
- Requires-Python: >=3.12
6
- Description-Content-Type: text/markdown
7
- Requires-Dist: opencv-python-headless>=4.11.0.86
8
- Requires-Dist: pydantic>=2.11.7
9
- Requires-Dist: scipy>=1.15.3
File without changes
File without changes
File without changes