RNotes | EBImage | Features

Basic | Haralick | Moment | Shape


The function computeFeatures.shape computes features that quantify object shape:

All shape features have a prefix “s.”.

library(EBImage)
computeFeatures.shape(x, properties=FALSE, xs, ...)

List properties of shape features

feature.properties <- computeFeatures.shape(properties=TRUE)
feature.properties
           name translation.invariant rotation.invariant
1        s.area                  TRUE               TRUE
2   s.perimeter                  TRUE               TRUE
3 s.radius.mean                  TRUE               TRUE
4   s.radius.sd                  TRUE               TRUE
5  s.radius.min                  TRUE               TRUE
6  s.radius.max                  TRUE               TRUE

Load and segment nucleus

par(mfrow=c(1,2))
y <- readImage(system.file("images", "nuclei.tif", package="EBImage"))[,,1]
x <- thresh(y, 10, 10, 0.05)
x <- opening(x, makeBrush(5, shape='disc'))
x <- bwlabel(x)

display(y, title="Cell nuclei")
display(x, title="Segmented nuclei")

Compute shape features

shapeFeatures <- computeFeatures.shape(x)
str(shapeFeatures)
 num [1:76, 1:6] 75 286 211 321 502 423 379 330 488 204 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:76] "1" "2" "3" "4" ...
  ..$ : chr [1:6] "s.area" "s.perimeter" "s.radius.mean" "s.radius.sd" ...
options(digits=4, width=100)
shapeFeatures
   s.area s.perimeter s.radius.mean s.radius.sd s.radius.min s.radius.max
1      75          40         5.385      2.5473       1.4631        9.599
2     286          95        11.914      6.2510       1.6595       22.734
3     211          61         8.464      2.8626       3.9931       12.369
4     321          56         9.782      1.6472       6.2745       12.270
5     502          80        13.183      4.1268       6.3982       19.601
6     423          70        11.193      2.0760       5.6671       14.562
7     379          62        10.641      1.6784       7.8951       13.529
8     330          61         9.993      1.7385       6.7248       13.442
9     488          81        12.307      3.3772       6.2079       18.125
10    204          60         7.874      2.8414       2.3778       12.207
11     44          19         3.332      0.4756       2.3140        4.096
12    311          67         9.494      3.0865       1.5623       13.654
13     44          19         3.306      0.3704       2.5004        3.865
14    420          67        11.123      1.2934       8.6474       13.258
15    389          62        10.703      1.1018       8.0866       12.705
16    621          87        13.992      2.7306       8.2129       18.504
17    361          75        10.111      3.3553       2.9636       14.539
18    357          64        10.244      1.8122       7.0147       13.038
19    435          69        11.306      1.1549       8.8330       13.835
20    129          36         5.981      0.9313       4.1970        7.498
21    298          58         9.361      2.0215       4.6040       12.788
22    193          55         8.005      2.7832       3.3462       13.494
23    518          77        12.851      1.7066       9.7697       16.372
24    375          66        10.605      1.6753       6.0521       13.708
25    296          60         9.569      2.7347       4.1163       13.240
26    293          59         9.326      2.1520       4.5921       12.679
27    319          59         9.593      1.5283       5.2950       11.936
28    298          53         9.331      0.8379       7.9463       11.175
29     41          24         3.426      1.3888       1.3077        5.631
30    420          71        11.239      2.0213       7.1682       15.389
31    426          71        11.499      3.2205       4.3185       16.412
32    527          78        12.594      2.7746       7.2046       17.093
33    320          65         9.969      3.3953       3.6403       14.971
34    394          63        10.876      1.6450       7.5136       13.660
35    207          46         8.142      2.1091       4.7038       11.354
36    225          49         8.117      1.8313       4.9459       11.163
37    397          60        10.974      1.5693       7.5465       13.719
38    136          36         6.158      0.7461       4.4466        7.641
39    348          65        10.110      2.8345       3.4815       13.568
40    281          54         9.075      1.5849       6.3138       11.906
41    376          70        11.072      2.7499       6.8124       16.162
42     75          26         4.487      0.7051       2.7847        5.608
43    429          72        11.360      2.5599       5.2519       15.312
44    436          74        11.583      3.0003       4.9134       16.382
45    111          56         7.362      3.6955       1.5642       13.581
46    464          70        11.964      2.3913       6.9747       15.853
47    485          76        12.036      2.2340       7.8180       15.559
48    315          60         9.620      1.9466       5.0364       12.745
49    320          56         9.733      1.2713       7.3639       11.878
50    368          70        10.637      2.4402       5.2174       14.981
51    390          79        11.034      3.5890       1.6093       15.952
52    390          93        10.406      4.0866       1.3027       16.319
53    319          64         9.871      2.7186       5.0637       14.533
54    339          59         9.941      0.9332       8.2735       11.655
55    536          77        12.688      2.3562       8.2421       16.448
56    342          66        10.050      2.9300       2.8931       14.155
57    507          81        12.527      3.2253       6.2176       17.870
58    248          53         8.553      1.7549       4.2935       11.441
59    345          69        10.566      3.4668       3.1461       15.804
60    351          65        10.169      2.1134       5.2726       13.820
61    421          73        11.224      3.0791       3.9369       16.264
62    358          60        10.230      0.7600       8.7452       11.632
63    364          63        10.598      2.2577       7.1605       15.150
64    207          49         7.727      1.1779       5.2081       10.220
65    380          82        11.864      5.1506       2.0894       19.864
66    582          85        13.019      2.5345       7.0552       16.636
67    309          58         9.501      1.4419       6.3927       11.828
68    408          87        11.064      4.1957       0.5892       16.865
69    273          54         8.890      1.4331       5.7807       11.056
70    315          75         8.612      3.1603       0.5259       12.310
71    352          82        10.428      4.4001       2.2640       17.451
72    400          66        11.139      2.3483       7.3767       15.325
73    262          53         8.669      0.9546       6.9193       10.277
74    345          68        10.415      3.3806       3.2596       15.656
75    321          74        10.504      3.7010       4.3515       17.612
76     16          12         1.833      0.6019       0.9718        2.635

Correlations of shape features

correlationMatrix <- cor(shapeFeatures)
correlationMatrix
##               s.area s.perimeter s.radius.mean s.radius.sd s.radius.min s.radius.max
## s.area        1.0000      0.8528        0.9604      0.3465       0.5639       0.8064
## s.perimeter   0.8528      1.0000        0.9155      0.7239       0.1861       0.9530
## s.radius.mean 0.9604      0.9155        1.0000      0.4820       0.5157       0.9086
## s.radius.sd   0.3465      0.7239        0.4820      1.0000      -0.4342       0.7864
## s.radius.min  0.5639      0.1861        0.5157     -0.4342       1.0000       0.1876
## s.radius.max  0.8064      0.9530        0.9086      0.7864       0.1876       1.0000

Heatmaps of correlation matrix

Color-coded display of correlation matrix

library(gplots)         # heatmap.2
library(RColorBrewer)   # brewer.pal
heatmap.2(correlationMatrix, dendrogram="none", Rowv=FALSE, symm=TRUE,
          cellnote=format(round(correlationMatrix,2)),
          main="Shape Features",
          scale="none", col=brewer.pal(11,"RdBu"), margins=c(9,9), trace="none")

Dendrograms show relationships in correlation matrix

heatmap.2(correlationMatrix, key=FALSE,
          cellnote=format(round(correlationMatrix,2)),
          main="Shape Features",
          scale="none", col=brewer.pal(11,"RdBu"), margins=c(9,9), trace="none")

A diverging palette from RColorBrewer is used for the heatmaps since correlations can range from -1 to +1. In the RdBu pallete, red is low and blue is high.


packageVersion("EBImage")
## [1] '4.8.2'
packageVersion("gplots")
## [1] '2.16.0'
packageVersion("RColorBrewer")
## [1] '1.1.2'

efg
2015-01-22 2315