RNotes | EBImage | Features

Basic | Haralick | Moment | Shape


The function computeFeatures.moment computes features related to object image moments, which can be computed with or without reference intensities:

All moment features have a prefix “m.”.

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

List properties of moment features

moment.properties <- computeFeatures.moment(properties=TRUE)
moment.properties
            name translation.invariant rotation.invariant
1           m.cx                 FALSE               TRUE
2           m.cy                 FALSE               TRUE
3    m.majoraxis                  TRUE               TRUE
4 m.eccentricity                  TRUE               TRUE
5        m.theta                  TRUE              FALSE

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 moment features

momentFeatures <- computeFeatures.moment(x, y)
str(momentFeatures)
 num [1:76, 1:5] 121.9 209.5 498 15.6 355.2 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:76] "1" "2" "3" "4" ...
  ..$ : chr [1:5] "m.cx" "m.cy" "m.majoraxis" "m.eccentricity" ...
options(digits=4)
momentFeatures
     m.cx    m.cy m.majoraxis m.eccentricity   m.theta
1  121.91   2.157      18.933         0.9724  0.014261
2  209.51   4.526      44.864         0.9686 -0.123709
3  497.96   5.021      26.230         0.9130 -0.166041
4   15.58  21.895      23.258         0.7179  0.662312
5  355.23  40.674      37.345         0.9113 -0.717877
6  201.10  50.334      26.362         0.6709 -1.154433
7  270.05  48.010      24.900         0.7202 -0.564551
8  103.05  59.029      23.259         0.7137  0.680846
9  220.77  73.953      33.362         0.8462  1.567322
10  20.26  74.290      25.234         0.8933 -1.231533
11  12.78  66.938       8.743         0.6998  0.566899
12  54.81  86.256      25.996         0.8133 -1.470879
13 239.20  89.861       8.230         0.5990  0.469316
14 428.32 106.267      25.112         0.6460 -0.030111
15 172.20 110.430      24.354         0.6024  1.200462
16 281.82 113.338      35.778         0.7672 -0.533530
17 482.92 144.828      30.164         0.8537 -0.883514
18 184.73 143.261      25.748         0.7552  0.030404
19 369.87 148.018      24.347         0.5243  1.096711
20 451.99 146.245      15.066         0.7075  1.364882
21  42.24 159.111      23.001         0.7568  1.426966
22 506.50 160.000      23.456         0.9061  1.459597
23 139.86 166.999      29.286         0.6145 -0.308636
24  75.34 167.560      25.531         0.6965  1.141134
25 440.96 176.292      26.576         0.8752  0.364926
26  57.59 198.806      23.128         0.7651  1.184429
27 456.83 204.478      22.199         0.6342  1.416205
28 486.60 206.825      19.309         0.4124  0.944504
29 508.79 203.315      11.876         0.9348  1.564039
30 379.92 225.597      25.384         0.6511  0.890749
31 328.06 237.697      31.250         0.8567 -0.525820
32  54.27 247.514      31.600         0.7939 -0.158137
33 176.79 255.942      29.427         0.9020  0.415912
34 422.01 266.012      25.451         0.7212 -0.871303
35 301.22 271.590      22.787         0.8791 -0.752424
36 483.97 275.367      20.989         0.8176  1.342576
37  79.54 291.901      25.321         0.7001 -0.576820
38 473.04 286.354      14.290         0.6340  0.463487
39  31.17 294.880      27.860         0.8405 -0.686989
40 309.90 292.537      22.653         0.7656 -0.205252
41 371.41 298.269      28.635         0.8394  0.942737
42 197.18 291.857      11.335         0.7414 -0.643245
43 243.35 300.628      29.396         0.7667 -1.413595
44 181.03 303.410      31.531         0.8277  0.152831
45 508.58 312.034      27.822         0.9838  1.565088
46 114.46 320.400      30.927         0.8084  0.973710
47 471.65 320.981      29.382         0.7673 -0.034360
48 329.83 326.653      24.555         0.7737  0.611664
49 303.95 337.434      22.384         0.6613  0.690330
50 201.87 354.075      26.968         0.7424 -0.391856
51  51.58 359.930      31.114         0.8229 -0.985669
52 144.43 362.656      33.487         0.8537 -0.429950
53 311.13 375.855      26.932         0.8553  1.323322
54 376.98 375.372      22.005         0.6021 -0.650564
55 247.96 386.266      31.341         0.7673 -1.431498
56  76.63 391.192      27.365         0.8243 -0.351000
57 109.19 403.318      33.330         0.8466  1.361160
58 494.03 394.894      20.988         0.7547  1.106236
59 424.44 399.577      30.787         0.8970  1.008747
60 215.43 412.916      24.307         0.7062 -1.512068
61 321.89 425.129      30.923         0.8439 -1.369627
62 366.18 419.180      21.840         0.4960  0.519304
63 288.52 425.301      26.334         0.7948 -1.106772
64 504.76 427.122      17.689         0.6208  1.332573
65 465.08 462.048      40.198         0.9492  0.785035
66 230.22 466.403      31.922         0.7507 -0.001315
67 140.64 471.566      21.893         0.6498 -0.156718
68 344.90 474.795      33.999         0.8344  0.385281
69  46.31 469.468      20.912         0.7006 -0.054880
70 185.78 490.943      24.141         0.7092  1.126549
71 409.80 488.483      34.496         0.8977  0.141176
72  66.14 492.366      28.173         0.8015 -0.683923
73 119.92 493.233      17.559         0.1772 -0.594441
74 282.36 496.915      30.712         0.8838 -0.597230
75 355.95 504.768      31.333         0.9026  0.221729
76 456.56 509.302       6.278         0.8778  0.007986

Correlations of moment features

correlationMatrix <- cor(momentFeatures)
correlationMatrix
##                    m.cx     m.cy m.majoraxis m.eccentricity  m.theta
## m.cx            1.00000  0.10868    -0.07982        0.08037  0.28069
## m.cy            0.10868  1.00000     0.06952       -0.04376 -0.07203
## m.majoraxis    -0.07982  0.06952     1.00000        0.42718 -0.20672
## m.eccentricity  0.08037 -0.04376     0.42718        1.00000 -0.03487
## m.theta         0.28069 -0.07203    -0.20672       -0.03487  1.00000

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="Moment 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="Moment 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 2326