Skip to content

Commit d313a8e

Browse files
committed
bounding box mask support
1 parent c183777 commit d313a8e

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

src/FullImageSegmentationAnnotator/index.story.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,34 @@ storiesOf("FullImageSegmentationAnnotator.Basic", module)
2323
// src: "https://i.imgur.com/Dv5lkQZ.png",
2424
src: orange,
2525
regions: [
26-
[0, 100, 125],
27-
[0, 100, 150],
2826
[1, 40, 280],
2927
[1, 10, 10],
3028
[1, 240, 300],
31-
].map(([cls, y, x], i) => ({
32-
cls: ["fg", "bg"][cls],
33-
color: "hsl(162,100%,50%)",
34-
editingLabels: false,
35-
highlighted: false,
36-
id: "a" + i,
37-
type: "point",
38-
x: x / 320,
39-
y: y / 249,
40-
})),
29+
]
30+
.map(([cls, y, x], i) => ({
31+
cls: ["fg", "bg"][cls],
32+
color: "hsl(162,100%,50%)",
33+
editingLabels: false,
34+
highlighted: false,
35+
id: "a" + i,
36+
type: "point",
37+
x: x / 320,
38+
y: y / 249,
39+
}))
40+
.concat([
41+
{
42+
cls: "fg",
43+
color: "hsl(162,100%,50%)",
44+
editingLabels: false,
45+
highlighted: false,
46+
id: "bb",
47+
type: "box",
48+
x: 0.3,
49+
y: 0.25,
50+
w: 0.35,
51+
h: 0.38,
52+
},
53+
]),
4154
},
4255
]}
4356
regionClsList={["bg", "fg"]}

src/ImageMask/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const ImageMask = ({
3737
if (hide) return
3838
if (!canvasRef) return
3939
if (!sampleImageData) return
40-
if (regions.filter((cp) => cp.cls).length < 3) return
40+
if (regions.filter((cp) => cp.cls).length < 2) return
4141
if (!mmgc.setImageSize) return
4242
const context = canvasRef.getContext("2d")
4343

@@ -88,6 +88,19 @@ export const ImageMask = ({
8888
)
8989
}
9090
const classPolygons = regions
91+
.map((r) => {
92+
if (r.type !== "box") return r
93+
return {
94+
...r,
95+
type: "polygon",
96+
points: [
97+
[r.x, r.y],
98+
[r.x + r.w, r.y],
99+
[r.x + r.w, r.y + r.h],
100+
[r.x, r.y + r.h],
101+
],
102+
}
103+
})
91104
.filter((r) => r.type === "polygon")
92105
.filter((r) => r.cls)
93106
for (const polygon of classPolygons) {

0 commit comments

Comments
 (0)