Skip to content

Commit 4685ac3

Browse files
authored
fix: Merge pull request #211 from UniversalDataTool/feat/transform-image-segments-into-samples
Introduce transform image segments to image samples
2 parents 91e6795 + 2b49791 commit 4685ac3

File tree

3 files changed

+76
-1
lines changed
  • src/components

3 files changed

+76
-1
lines changed

src/components/TransformImageSamplesIntoSegmentsDialog/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ const ErrorBox = styled("pre")({
1616

1717
const splitOptions = [
1818
{ label: "2x2", value: "2x2" },
19+
{ label: "1x2 (columns)", value: "1x2" },
1920
{ label: "3x3", value: "3x3" },
21+
{ label: "1x2 (columns)", value: "1x2" },
22+
{ label: "1x3 (columns)", value: "1x3" },
23+
{ label: "2x3 (2 rows)", value: "2x3" },
2024
{ label: "4x4", value: "4x4" },
21-
{ label: "3x4", value: "3x4" },
25+
{ label: "3x4 (3 rows)", value: "3x4" },
2226
]
2327

2428
export default ({ open, onChangeDataset, onClose, dataset }) => {

src/components/TransformPage/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import TransformVideoFramesToImagesDialog from "../TransformVideoFramesToImagesD
1717
import usePosthog from "../../utils/use-posthog"
1818
import TransformLocalFilesToWebURLs from "../TransformLocalFilesToWebURLs"
1919
import TransformImageSamplesIntoSegmentsDialog from "../TransformImageSamplesIntoSegmentsDialog"
20+
import TransformSegmentsIntoImageSamplesDialog from "../TransformSegmentsIntoImageSamplesDialog"
2021

2122
import ComputerIcon from "@material-ui/icons/Computer"
2223
import LanguageIcon from "@material-ui/icons/Language"
@@ -149,6 +150,13 @@ export default ({ dataset, onChangeDataset }) => {
149150
>
150151
Split Image Samples into Segments
151152
</Button>
153+
<Button
154+
dialog="combine-segments-into-image-samples"
155+
Icon1={GridOnIcon}
156+
Icon2={CheckBoxOutlineBlankIcon}
157+
>
158+
Combine Segments into Image Samples
159+
</Button>
152160
<TransformVideoKeyframesDialog
153161
open={selectedDialog === "convert-keyframes-to-samples"}
154162
onClose={closeDialog}
@@ -185,6 +193,12 @@ export default ({ dataset, onChangeDataset }) => {
185193
onClose={closeDialog}
186194
onChangeDataset={onChangeDataset}
187195
></TransformImageSamplesIntoSegmentsDialog>
196+
<TransformSegmentsIntoImageSamplesDialog
197+
dataset={dataset}
198+
open={selectedDialog === "combine-segments-into-image-samples"}
199+
onClose={closeDialog}
200+
onChangeDataset={onChangeDataset}
201+
></TransformSegmentsIntoImageSamplesDialog>
188202
</div>
189203
</SelectDialogContext.Provider>
190204
)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// @flow weak
2+
3+
import React, { useState } from "react"
4+
import SimpleDialog from "../SimpleDialog"
5+
import { styled } from "@material-ui/core/styles"
6+
import { setIn } from "seamless-immutable"
7+
8+
const ErrorBox = styled("pre")({
9+
color: "red",
10+
whiteSpace: "prewrap",
11+
fontSize: 11,
12+
})
13+
14+
export default ({ open, onChangeDataset, onClose, dataset }) => {
15+
const [errors, setErrors] = useState("")
16+
return (
17+
<SimpleDialog
18+
open={open}
19+
onClose={onClose}
20+
title="Convert Segments to Image Samples"
21+
actions={[
22+
{
23+
text: "Convert Segments to Image Samples",
24+
onClick: async () => {
25+
try {
26+
const imageUrls = Array.from(
27+
new Set(dataset.samples.map((s) => s.imageUrl))
28+
)
29+
const newSamples = []
30+
for (const imageUrl of imageUrls) {
31+
const pieces = dataset.samples.filter(
32+
(s) => s.imageUrl === imageUrl
33+
)
34+
newSamples.push({
35+
imageUrl,
36+
annotation: pieces
37+
.flatMap((p) => p.annotation)
38+
.filter(Boolean),
39+
})
40+
}
41+
onChangeDataset(setIn(dataset, ["samples"], newSamples))
42+
onClose()
43+
} catch (e) {
44+
setErrors(e.toString())
45+
}
46+
},
47+
},
48+
]}
49+
>
50+
This transformation will take image samples that have been split into
51+
segments (each with an allowedArea), and combine them into one image
52+
sample again. This is typically executed after a splitting operation when
53+
the samples are to be recombined.
54+
{errors && <ErrorBox>{errors}</ErrorBox>}
55+
</SimpleDialog>
56+
)
57+
}

0 commit comments

Comments
 (0)