Skip to content

Commit 63bf2ea

Browse files
authored
fix: Merge pull request #139 from UniversalDataTool/image-seg-fix
Fix image segmentation multi-sample support
2 parents b35a666 + 8bbda20 commit 63bf2ea

File tree

1 file changed

+24
-14
lines changed
  • src/components/ImageSegmentation

1 file changed

+24
-14
lines changed

src/components/ImageSegmentation/index.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,24 @@ export default ({
2929
iface.labels = iface.availableLabels
3030
}
3131

32-
const [selectedIndex] = useState(0)
32+
const [selectedIndex, changeSelectedIndex] = useState(0)
3333
const [showTags, changeShowTags] = useState(true)
3434
const [selectedTool, changeSelectedTool] = useState("select")
3535

3636
const { regionTypesAllowed = ["bounding-box"] } = iface
3737

3838
const isClassification = !Boolean(iface.multipleRegionLabels)
3939

40+
const saveCurrentIndexAnnotation = useEventCallback((output) => {
41+
const img = output.images[selectedIndex]
42+
onSaveTaskOutputItem(
43+
selectedIndex,
44+
multipleRegions
45+
? (img.regions || []).map(convertFromRIARegionFmt)
46+
: convertToRIAImageFmt((img.regions || [])[0])
47+
)
48+
})
49+
4050
const labelProps = useMemo(
4151
() =>
4252
isClassification
@@ -57,26 +67,26 @@ export default ({
5767
iface.multipleRegions || iface.multipleRegions === undefined
5868

5969
const onExit = useEventCallback((output, nextAction) => {
60-
const regionMat = (output.images || [])
61-
.map((img) => img.regions)
62-
.map((riaRegions) => (riaRegions || []).map(convertFromRIARegionFmt))
63-
64-
for (let i = 0; i < regionMat.length; i++) {
65-
if (multipleRegions) {
66-
onSaveTaskOutputItem(i, regionMat[i])
67-
} else {
68-
onSaveTaskOutputItem(i, regionMat[i][0])
69-
}
70-
}
70+
saveCurrentIndexAnnotation(output)
7171
changeShowTags(output.showTags)
7272
changeSelectedTool(output.selectedTool)
7373
if (containerProps.onExit) containerProps.onExit(nextAction)
7474
})
7575
const onNextImage = useEventCallback((output) => {
76-
onExit(output, "go-to-next")
76+
if (selectedIndex + 1 >= samples.length) {
77+
onExit(output, "go-to-next")
78+
} else {
79+
saveCurrentIndexAnnotation(output)
80+
changeSelectedIndex(selectedIndex + 1)
81+
}
7782
})
7883
const onPrevImage = useEventCallback((output) => {
79-
onExit(output, "go-to-previous")
84+
if (selectedIndex - 1 < 0) {
85+
onExit(output, "go-to-previous")
86+
} else {
87+
saveCurrentIndexAnnotation(output)
88+
changeSelectedIndex(selectedIndex - 1)
89+
}
8090
})
8191

8292
const images = useMemo(

0 commit comments

Comments
 (0)