Crop
This layer (crop) is used to crop part of image with its annotations. This layer has several modes: it may crop fixed given part of image or random one.

Crop specific part of image

1
{
2
"action": "crop",
3
"src": ["$data1"],
4
"dst": "$data2",
5
"settings": {
6
"sides": {
7
"top":"30%",
8
"left":"100px",
9
"right":"100px",
10
"bottom":"0px"
11
}
12
}
13
}
Copied!

Settings

sides fields define how many pixels or percents will be cropped from each image side. Values in pixels are defined with px suffix, and percents are defined with % suffix.

Example

1
{
2
"action": "crop",
3
"src": ["$data1"],
4
"dst": "$data2",
5
"settings": {
6
"sides": {
7
"left":"100px",
8
"top":"50px",
9
"right":"100px",
10
"bottom":"50px"
11
}
12
}
13
}
Copied!
To better understand what the field sides mean let me show you an image.
Here is the full export config for this example:
1
[
2
{
3
"dst": "$data1",
4
"src": [
5
"docs/ds1"
6
],
7
"action": "data",
8
"settings": {
9
"classes_mapping": "default"
10
}
11
},
12
{
13
"dst": "$data2",
14
"src": [
15
"$data1"
16
],
17
"action": "crop",
18
"settings": {
19
"sides": {
20
"top": "50px",
21
"left": "100px",
22
"right": "100px",
23
"bottom": "50px"
24
}
25
}
26
},
27
{
28
"dst": "demo_crop_sides",
29
"src": [
30
"$data2"
31
],
32
"action": "supervisely",
33
"settings": {}
34
}
35
]
Copied!

Crop random part of image

1
{
2
"action": "crop",
3
"src": ["$data1"],
4
"dst": "$data2",
5
"settings": {
6
"random_part": {
7
"height":{
8
"min_percent":10,
9
"max_percent":40
10
},
11
"width":{
12
"min_percent":30,
13
"max_percent":80
14
},
15
"keep_aspect_ratio": false
16
}
17
}
18
}
Copied!

Settings

  • height
    • min_percent โ€” minimum height of resulting crop (in percent wrt to image height)
    • max_percent โ€” maximum height of resulting crop (in percent wrt to image height)
  • width
    • min_percent โ€” minimum width of resulting crop (in percent wrt to image width)
    • max_percent โ€” maximum width of resulting crop (in percent wrt to image width)
  • keep_aspect_ratio โ€” should resulting random crop have the same aspect ratio as a source image

Example

Let's consider following example: get all images from myproj/ds1, duplicate each image three times, apply random crop to each image and then save the results to project demo_crop.
1
[
2
{
3
"dst": "$data1",
4
"src": [
5
"myproj/ds1"
6
],
7
"action": "data",
8
"settings": {
9
"classes_mapping": "default"
10
}
11
},
12
{
13
"dst": "$data2",
14
"src": [
15
"$data1"
16
],
17
"action": "multiply",
18
"settings": {
19
"multiply": 3
20
}
21
},
22
{
23
"dst": "$data3",
24
"src": [
25
"$data2"
26
],
27
"action": "crop",
28
"settings": {
29
"random_part": {
30
"width": {
31
"max_percent": 80,
32
"min_percent": 30
33
},
34
"height": {
35
"max_percent": 40,
36
"min_percent": 10
37
},
38
"keep_aspect_ratio": false
39
}
40
}
41
},
42
{
43
"dst": "demo_crop",
44
"src": [
45
"$data3"
46
],
47
"action": "supervisely",
48
"settings": {}
49
}
50
]
Copied!
Here is the visualization of computational graph:
Here are the results of export for this example:
Last modified 1yr ago