Get label statistics from image.

labelStats(image, labelImage)

Arguments

image

Image to calculate statistics from.

labelImage

Label image.

Value

Data frame with one row per label (including zero) and columns : LabelValues, Mean, Min, Max, Variance, Count, Volume

Examples


img <- antsImageRead(getANTsRData("r16"), 2)
img <- resampleImage(img, c(64, 64), 1, 0)
mask <- getMask(img)
segs1 <- kmeansSegmentation(img, 3)
labelStats(img, segs1$segmentation)
#>   LabelValue        Mean Min Max   Variance Count Volume   Mass        x
#> 4          0   0.1475076   0 163   11.53692  2949  47184      0   0.0000
#> 3          1  73.7428571   0 125 1535.97657   140   2240  10324 131.2857
#> 2          2 166.1126126 127 191  259.86088   444   7104  73754 125.6937
#> 1          3 216.2557726 191 253  221.33660   563   9008 121752 124.4618
#>          y  z  t
#> 4   0.0000 NA NA
#> 3 128.9714 NA NA
#> 2 126.0541 NA NA
#> 1 131.7300 NA NA
testthat::expect_error(labelStats(img, as.array(segs1$segmentation)))
testthat::expect_error(labelStats(img, as.array(segs1$segmentation)))
sub_seg <- segs1$segmentation
sub_seg <- as.antsImage(sub_seg[1:62, 1:62], reference = sub_seg)
testthat::expect_error(labelStats(img, sub_seg))