Resample a shape to a different number of points.
Usage
coo_sample(x, ..., .cols = NULL, .ldk_col = NULL)
coo_sample_prop(x, ..., .cols = NULL, .ldk_col = NULL)Arguments
- x
A matrix (nx2), list of matrices, or tibble with coo columns.
- ...
Additional arguments (reserved for future use).
- .cols
Column name(s) to process when
xis a tibble. IfNULL, automatically detects columns containing coo objects.- .ldk_col
Character. Name of landmark column. If
NULL, usescolname_ldk.- n
Integer. Target number of points. Minimum is 3.
- prop
Numeric. Proportion of points to keep (0 to 1).
Value
If
xis a single matrix: returns the resampled matrixIf
xis a list: returns a list of resampled matricesIf
xis a tibble: returns the tibble with specified coo columns resampled
Details
coo_sample(): resample to exactly n points via arc-length interpolationcoo_sample_prop(): resample to a proportion of original points
These functions are landmark-aware: if landmarks are present, the outline is resampled segment-by-segment between landmarks, preserving landmark positions and distributing points proportionally across segments.
See also
get_coords_nb() for point count; coo_smooth() for smoothing; coo_sample_regular_radius() for radial sampling
Examples
# Resample to 64 points
coo_sample(shapes$cat, n = 64)
#> <xy [64 x 2]>
#> [,1] [,2]
#> [1,] 200.000 62.000
#> [2,] 200.492 55.836
#> [3,] 208.650 48.701
#> [4,] 200.457 43.000
#> [5,] 188.809 42.000
#> [6,] ... ...
#> [7,] 226.723 61.092
#> [8,] 231.086 52.257
#> [9,] 222.914 45.000
#> [10,] 212.045 48.146
#> [11,] 204.998 57.502
# Resample list
coo_sample(bot$coo, n = 100)
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> Warning: collapsing to unique 'x' values
#> $brahma
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 37.000 561.000
#> [2,] 40.000 536.074
#> [3,] 42.555 511.117
#> [4,] 46.152 486.238
#> [5,] 50.941 461.560
#> [6,] ... ...
#> [7,] 40.889 685.666
#> [8,] 35.006 661.279
#> [9,] 33.000 636.280
#> [10,] 33.612 611.156
#> [11,] 35.432 586.090
#>
#> $caney
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 53.000 535.000
#> [2,] 53.644 512.126
#> [3,] 53.568 489.322
#> [4,] 54.000 466.453
#> [5,] 54.000 443.563
#> [6,] ... ...
#> [7,] 92.842 640.094
#> [8,] 79.791 621.416
#> [9,] 69.320 601.155
#> [10,] 60.519 580.062
#> [11,] 55.547 557.737
#>
#> $chimay
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 49.000 333.000
#> [2,] 49.115 317.081
#> [3,] 50.000 301.211
#> [4,] 50.795 285.360
#> [5,] 50.000 269.483
#> [6,] ... ...
#> [7,] 71.106 407.766
#> [8,] 65.027 393.053
#> [9,] 58.675 378.479
#> [10,] 51.201 364.469
#> [11,] 48.111 348.886
#>
#> $corona
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 91.000 426.000
#> [2,] 90.601 407.627
#> [3,] 90.571 389.288
#> [4,] 91.000 370.928
#> [5,] 91.000 352.546
#> [6,] ... ...
#> [7,] 120.565 512.413
#> [8,] 113.738 495.346
#> [9,] 105.961 478.731
#> [10,] 99.376 461.592
#> [11,] 93.600 444.197
#>
#> $deusventrue
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 74.000 481.000
#> [2,] 65.525 461.932
#> [3,] 58.108 442.451
#> [4,] 51.165 422.774
#> [5,] 45.925 402.626
#> [6,] ... ...
#> [7,] 107.856 579.568
#> [8,] 101.417 559.722
#> [9,] 95.008 539.877
#> [10,] 87.771 520.312
#> [11,] 82.067 500.242
#>
#> $duvel
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 61.000 315.000
#> [2,] 61.000 299.906
#> [3,] 61.000 284.811
#> [4,] 59.000 269.915
#> [5,] 59.000 254.821
#> [6,] ... ...
#> [7,] 84.834 385.024
#> [8,] 76.439 372.484
#> [9,] 69.514 359.130
#> [10,] 64.449 344.967
#> [11,] 62.367 330.032
#>
#> $franziskaner
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 54.000 439.000
#> [2,] 54.000 419.152
#> [3,] 54.000 399.305
#> [4,] 54.000 379.457
#> [5,] 54.000 359.610
#> [6,] ... ...
#> [7,] 61.667 537.558
#> [8,] 59.332 517.971
#> [9,] 56.622 498.356
#> [10,] 54.000 478.695
#> [11,] 54.000 458.848
#>
#> $grimbergen
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 42.000 404.000
#> [2,] 40.000 385.723
#> [3,] 40.000 367.247
#> [4,] 40.000 348.772
#> [5,] 40.000 330.297
#> [6,] ... ...
#> [7,] 75.080 488.349
#> [8,] 64.396 473.280
#> [9,] 54.824 457.510
#> [10,] 48.356 440.246
#> [11,] 43.752 422.392
#>
#> $guiness
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 69.000 385.000
#> [2,] 69.000 367.331
#> [3,] 69.000 349.661
#> [4,] 69.000 331.992
#> [5,] 69.428 314.420
#> [6,] ... ...
#> [7,] 87.252 468.879
#> [8,] 78.326 453.651
#> [9,] 71.947 437.262
#> [10,] 67.572 420.146
#> [11,] 68.816 402.659
#>
#> $hoegardeen
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 42.000 544.000
#> [2,] 40.000 519.916
#> [3,] 40.000 495.680
#> [4,] 40.000 471.443
#> [5,] 40.000 447.207
#> [6,] ... ...
#> [7,] 71.206 661.168
#> [8,] 63.836 638.089
#> [9,] 56.755 614.955
#> [10,] 50.265 591.613
#> [11,] 45.984 567.907
#>
#> $jupiler
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 55.000 515.000
#> [2,] 54.000 492.709
#> [3,] 54.000 470.382
#> [4,] 54.000 448.055
#> [5,] 54.000 425.728
#> [6,] ... ...
#> [7,] 82.643 622.840
#> [8,] 75.657 601.640
#> [9,] 68.430 580.531
#> [10,] 62.835 558.924
#> [11,] 58.272 537.086
#>
#> $kingfisher
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 71.000 384.000
#> [2,] 71.000 367.668
#> [3,] 71.000 351.336
#> [4,] 71.000 335.004
#> [5,] 71.000 318.672
#> [6,] ... ...
#> [7,] 85.826 463.859
#> [8,] 82.196 447.980
#> [9,] 77.853 432.267
#> [10,] 74.023 416.409
#> [11,] 72.710 400.242
#>
#> $latrappe
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 26.000 389.000
#> [2,] 25.000 370.038
#> [3,] 25.000 351.035
#> [4,] 25.579 332.056
#> [5,] 26.000 313.070
#> [6,] ... ...
#> [7,] 34.813 482.393
#> [8,] 28.199 464.598
#> [9,] 25.418 445.986
#> [10,] 26.000 427.007
#> [11,] 26.000 408.003
#>
#> $lindemanskriek
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 60.000 427.000
#> [2,] 56.536 408.608
#> [3,] 54.000 389.959
#> [4,] 53.564 371.018
#> [5,] 54.000 352.137
#> [6,] ... ...
#> [7,] 86.638 517.913
#> [8,] 81.294 499.741
#> [9,] 75.895 481.579
#> [10,] 70.599 463.394
#> [11,] 65.348 445.184
#>
#> $nicechouffe
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 82.000 361.000
#> [2,] 79.203 345.362
#> [3,] 77.000 329.710
#> [4,] 75.363 313.903
#> [5,] 75.000 298.018
#> [6,] ... ...
#> [7,] 102.746 437.611
#> [8,] 97.609 422.559
#> [9,] 92.451 407.531
#> [10,] 88.530 392.119
#> [11,] 84.765 376.666
#>
#> $pecheresse
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 63.000 495.000
#> [2,] 61.000 473.864
#> [3,] 60.282 452.642
#> [4,] 58.368 431.494
#> [5,] 58.000 410.273
#> [6,] ... ...
#> [7,] 89.735 597.742
#> [8,] 85.107 577.022
#> [9,] 79.277 556.598
#> [10,] 73.809 536.074
#> [11,] 68.648 515.476
#>
#> $sierranevada
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 61.000 345.000
#> [2,] 61.000 329.168
#> [3,] 61.000 313.336
#> [4,] 61.000 297.504
#> [5,] 61.000 281.672
#> [6,] ... ...
#> [7,] 71.226 421.498
#> [8,] 63.404 407.741
#> [9,] 60.698 392.190
#> [10,] 59.904 376.573
#> [11,] 61.000 360.832
#>
#> $tanglefoot
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 48.000 367.000
#> [2,] 48.000 349.708
#> [3,] 48.320 332.437
#> [4,] 49.000 315.187
#> [5,] 49.000 297.895
#> [6,] ... ...
#> [7,] 65.520 449.432
#> [8,] 56.768 434.537
#> [9,] 50.317 418.512
#> [10,] 47.658 401.532
#> [11,] 47.000 384.261
#>
#> $tauro
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 56.000 515.000
#> [2,] 54.000 492.781
#> [3,] 54.000 470.397
#> [4,] 54.000 448.012
#> [5,] 54.000 425.628
#> [6,] ... ...
#> [7,] 82.154 623.307
#> [8,] 76.249 601.747
#> [9,] 69.368 580.471
#> [10,] 62.384 559.306
#> [11,] 58.895 537.196
#>
#> $westmalle
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 70.000 394.000
#> [2,] 68.349 376.646
#> [3,] 66.898 359.269
#> [4,] 66.000 341.798
#> [5,] 66.000 324.300
#> [6,] ... ...
#> [7,] 91.070 478.563
#> [8,] 86.223 461.757
#> [9,] 81.669 444.902
#> [10,] 76.572 428.286
#> [11,] 74.004 411.034
#>
#> $amrut
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 57.000 441.000
#> [2,] 57.000 420.985
#> [3,] 57.000 400.971
#> [4,] 57.000 380.956
#> [5,] 57.000 360.942
#> [6,] ... ...
#> [7,] 65.108 539.217
#> [8,] 57.924 520.620
#> [9,] 55.030 500.849
#> [10,] 57.000 481.029
#> [11,] 57.000 461.015
#>
#> $ballantines
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 38.000 357.000
#> [2,] 38.000 338.945
#> [3,] 38.000 320.891
#> [4,] 38.000 302.836
#> [5,] 38.000 284.782
#> [6,] ... ...
#> [7,] 38.000 447.273
#> [8,] 38.000 429.218
#> [9,] 38.000 411.164
#> [10,] 38.000 393.109
#> [11,] 38.000 375.055
#>
#> $bushmills
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 72.000 456.000
#> [2,] 72.000 435.283
#> [3,] 72.000 414.565
#> [4,] 72.010 393.848
#> [5,] 73.388 373.177
#> [6,] ... ...
#> [7,] 68.283 559.466
#> [8,] 69.614 538.792
#> [9,] 70.000 518.087
#> [10,] 70.000 497.370
#> [11,] 70.666 476.674
#>
#> $chivas
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 33.000 437.000
#> [2,] 29.637 417.414
#> [3,] 29.000 397.539
#> [4,] 29.086 377.629
#> [5,] 30.000 357.745
#> [6,] ... ...
#> [7,] 94.452 513.770
#> [8,] 79.466 500.658
#> [9,] 65.241 486.756
#> [10,] 52.267 471.690
#> [11,] 41.330 455.055
#>
#> $dalmore
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 52.000 371.000
#> [2,] 45.992 354.630
#> [3,] 42.582 337.490
#> [4,] 42.000 320.054
#> [5,] 42.000 302.569
#> [6,] ... ...
#> [7,] 108.311 436.884
#> [8,] 95.782 424.738
#> [9,] 82.660 413.188
#> [10,] 70.722 400.467
#> [11,] 60.996 385.993
#>
#> $famousgrouse
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 99.000 313.000
#> [2,] 99.000 298.807
#> [3,] 99.000 284.613
#> [4,] 99.000 270.420
#> [5,] 99.000 256.226
#> [6,] ... ...
#> [7,] 96.000 383.807
#> [8,] 96.043 369.616
#> [9,] 97.000 355.475
#> [10,] 97.000 341.282
#> [11,] 97.514 327.115
#>
#> $glendronach
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 73.000 435.000
#> [2,] 73.585 415.978
#> [3,] 74.000 396.948
#> [4,] 74.000 377.902
#> [5,] 74.000 358.855
#> [6,] ... ...
#> [7,] 83.201 528.103
#> [8,] 75.530 510.673
#> [9,] 72.000 492.098
#> [10,] 72.826 473.086
#> [11,] 73.000 454.047
#>
#> $glenmorangie
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 53.000 518.000
#> [2,] 54.000 495.182
#> [3,] 54.744 472.356
#> [4,] 57.000 449.633
#> [5,] 57.000 426.786
#> [6,] ... ...
#> [7,] 74.043 628.842
#> [8,] 65.119 607.838
#> [9,] 58.528 585.980
#> [10,] 53.804 563.672
#> [11,] 53.000 540.848
#>
#> $highlandpark
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 42.000 371.000
#> [2,] 42.000 353.206
#> [3,] 42.000 335.412
#> [4,] 42.000 317.617
#> [5,] 41.916 299.826
#> [6,] ... ...
#> [7,] 39.651 459.887
#> [8,] 40.919 442.138
#> [9,] 42.000 424.383
#> [10,] 42.000 406.588
#> [11,] 42.000 388.794
#>
#> $jackdaniels
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 63.000 414.000
#> [2,] 63.000 394.822
#> [3,] 63.000 375.643
#> [4,] 63.000 356.465
#> [5,] 63.000 337.286
#> [6,] ... ...
#> [7,] 74.468 508.516
#> [8,] 69.587 490.106
#> [9,] 66.210 471.244
#> [10,] 64.058 452.244
#> [11,] 64.471 433.122
#>
#> $jb
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 43.000 531.000
#> [2,] 42.000 507.276
#> [3,] 42.407 483.520
#> [4,] 43.000 459.773
#> [5,] 43.000 435.999
#> [6,] ... ...
#> [7,] 58.082 645.737
#> [8,] 46.944 624.990
#> [9,] 41.270 601.987
#> [10,] 42.294 578.532
#> [11,] 43.000 554.774
#>
#> $johnniewalker
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 133.000 175.000
#> [2,] 133.000 167.038
#> [3,] 133.487 159.106
#> [4,] 134.000 151.176
#> [5,] 134.000 143.214
#> [6,] ... ...
#> [7,] 132.000 214.688
#> [8,] 133.000 206.849
#> [9,] 133.000 198.886
#> [10,] 133.000 190.924
#> [11,] 133.000 182.962
#>
#> $magallan
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 78.000 397.000
#> [2,] 78.567 380.015
#> [3,] 80.000 363.152
#> [4,] 80.992 346.121
#> [5,] 81.000 329.058
#> [6,] ... ...
#> [7,] 75.000 482.164
#> [8,] 75.000 465.100
#> [9,] 75.000 448.036
#> [10,] 76.325 431.060
#> [11,] 77.225 414.046
#>
#> $makersmark
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 31.000 432.000
#> [2,] 19.654 414.263
#> [3,] 13.106 394.494
#> [4,] 8.979 373.856
#> [5,] 8.027 352.864
#> [6,] ... ...
#> [7,] 103.107 502.799
#> [8,] 88.242 489.844
#> [9,] 75.168 476.270
#> [10,] 61.963 460.402
#> [11,] 45.894 446.894
#>
#> $oban
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 74.000 457.000
#> [2,] 74.000 437.191
#> [3,] 74.000 417.382
#> [4,] 74.495 397.587
#> [5,] 75.000 377.793
#> [6,] ... ...
#> [7,] 79.508 555.021
#> [8,] 74.252 536.019
#> [9,] 72.073 516.347
#> [10,] 73.000 496.589
#> [11,] 73.000 476.780
#>
#> $oldpotrero
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 83.000 307.000
#> [2,] 74.301 295.401
#> [3,] 67.169 282.859
#> [4,] 61.511 269.534
#> [5,] 57.938 255.505
#> [6,] ... ...
#> [7,] 120.181 368.658
#> [8,] 115.376 355.077
#> [9,] 107.725 342.782
#> [10,] 99.542 330.813
#> [11,] 91.361 318.845
#>
#> $redbreast
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 105.000 233.000
#> [2,] 100.786 223.287
#> [3,] 98.000 213.094
#> [4,] 97.000 202.591
#> [5,] 97.000 191.989
#> [6,] ... ...
#> [7,] 143.396 268.792
#> [8,] 136.809 260.847
#> [9,] 128.530 254.224
#> [10,] 120.178 247.694
#> [11,] 112.044 240.924
#>
#> $tamdhu
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 49.000 552.000
#> [2,] 49.000 528.539
#> [3,] 49.000 505.077
#> [4,] 50.000 481.654
#> [5,] 50.000 458.193
#> [6,] ... ...
#> [7,] 54.754 667.737
#> [8,] 48.223 645.336
#> [9,] 45.509 622.055
#> [10,] 45.186 598.768
#> [11,] 47.129 575.387
#>
#> $wildturkey
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 18.000 569.000
#> [2,] 18.000 542.664
#> [3,] 18.000 516.328
#> [4,] 18.000 489.991
#> [5,] 18.000 463.655
#> [6,] ... ...
#> [7,] 46.172 691.005
#> [8,] 28.396 671.839
#> [9,] 19.446 647.396
#> [10,] 15.000 621.512
#> [11,] 15.194 595.186
#>
#> $yoichi
#> <xy [100 x 2]>
#> [,1] [,2]
#> [1,] 69.000 384.000
#> [2,] 69.000 366.510
#> [3,] 69.000 349.019
#> [4,] 69.000 331.529
#> [5,] 70.000 314.110
#> [6,] ... ...
#> [7,] 68.000 471.419
#> [8,] 68.000 453.928
#> [9,] 68.000 436.438
#> [10,] 68.137 418.952
#> [11,] 69.000 401.490
#>
#> attr(,"class")
#> [1] "out" "coo" "list"
# Resample with landmarks preserved
coo_sample(hearts, n = 200)
#> ✔ Updated landmarks in 'coo_ldk'
#> # A tibble: 40 × 4
#> img coo coo_ldk author
#> <path> <out> <named list> <fct>
#> 1 viodnwqb.jpg (200 x 2) <dbl [4]> ced
#> 2 ohmlpeqy.jpg (200 x 2) <dbl [4]> ced
#> 3 qleyuxan.jpg (200 x 2) <dbl [4]> ced
#> 4 esjuanpl.jpg (200 x 2) <dbl [4]> ced
#> 5 zjhldwkx.jpg (200 x 2) <dbl [4]> ced
#> 6 jgiurtke.jpg (200 x 2) <dbl [4]> jeya
#> 7 ctigzqxl.jpg (200 x 2) <dbl [4]> jeya
#> 8 azvxubnr.jpg (200 x 2) <dbl [4]> jeya
#> 9 pydkrcxh.jpg (200 x 2) <dbl [4]> jeya
#> 10 zxitnlfc.jpg (200 x 2) <dbl [4]> jeya
#> # ℹ 30 more rows
# Resample to 50% of points
coo_sample_prop(shapes$cat, prop = 0.5)
#> <xy [60 x 2]>
#> [,1] [,2]
#> [1,] 200.000 62.000
#> [2,] 201.234 55.589
#> [3,] 208.512 47.391
#> [4,] 198.136 42.689
#> [5,] 185.681 42.000
#> [6,] ... ...
#> [7,] 223.614 62.965
#> [8,] 231.912 55.220
#> [9,] 225.049 45.699
#> [10,] 213.069 46.977
#> [11,] 205.432 56.852
