Function for converting box coordinates to/from min/max representation from/to centroids/width

convertCoordinates(boxes, type = c("minmax2centroids", "centroids2minmax"))

Arguments

boxes

A vector or 2-D array where each row corresponds to a single box consisting of the format (xmin,xmax,ymin,ymax) or (centerx,centery,width,height) for 2-D vs. (xmin,xmax,ymin,ymax,zmin,zmax) or (centerx,centery,centerz,width,height,depth) for 3-D.

type

either 'minmax2centroids' or 'centroids2minmax'

Value

a vector or 2-D array with the converted coordinates

Author

Tustison NJ

Examples

vec2d = c(1, 10, 1, 10) convertCoordinates(vec2d)
#> [1] 5.5 5.5 9.0 9.0
convertCoordinates(vec2d, type = "centroids2minmax")
#> [1] 0.5 1.5 5.0 15.0
convertCoordinates(rbind( vec2d, vec2d, vec2d))
#> [,1] [,2] [,3] [,4] #> vec2d 5.5 5.5 9 9 #> vec2d 5.5 5.5 9 9 #> vec2d 5.5 5.5 9 9
convertCoordinates(rbind( vec2d, vec2d, vec2d), "centroids2minmax")
#> [,1] [,2] [,3] [,4] #> vec2d 0.5 1.5 5 15 #> vec2d 0.5 1.5 5 15 #> vec2d 0.5 1.5 5 15
vec3d = c(1, 10, 1, 10, 1, 10) convertCoordinates(vec3d)
#> [1] 5.5 5.5 5.5 9.0 9.0 9.0
convertCoordinates(vec3d, type = "centroids2minmax")
#> [1] -4.0 6.0 9.5 10.5 -4.0 6.0
convertCoordinates(rbind( vec3d, vec3d, vec3d))
#> [,1] [,2] [,3] [,4] [,5] [,6] #> vec3d 5.5 5.5 5.5 9 9 9 #> vec3d 5.5 5.5 5.5 9 9 9 #> vec3d 5.5 5.5 5.5 9 9 9
convertCoordinates(rbind( vec3d, vec3d, vec3d), type = "centroids2minmax")
#> [,1] [,2] [,3] [,4] [,5] [,6] #> vec3d -4 6 9.5 10.5 -4 6 #> vec3d -4 6 9.5 10.5 -4 6 #> vec3d -4 6 9.5 10.5 -4 6