RNotes | EBImage | Features

Basic | Haralick | Moment | Shape


library(EBImage)

Image Object Features

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

fts <- computeFeatures.shape(x)
str(fts)
##  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" ...
fts
##    s.area s.perimeter s.radius.mean s.radius.sd s.radius.min s.radius.max
## 1      75          40      5.384756   2.5473087    1.4630875     9.598991
## 2     286          95     11.914279   6.2510079    1.6594562    22.733608
## 3     211          61      8.463546   2.8625585    3.9930738    12.369067
## 4     321          56      9.781896   1.6472487    6.2744674    12.269780
## 5     502          80     13.182665   4.1268371    6.3981687    19.601315
## 6     423          70     11.193220   2.0760003    5.6671268    14.562252
## 7     379          62     10.640572   1.6783868    7.8950748    13.529297
## 8     330          61      9.992652   1.7385299    6.7247892    13.441793
## 9     488          81     12.307053   3.3772075    6.2079250    18.124605
## 10    204          60      7.874377   2.8414135    2.3777908    12.207398
## 11     44          19      3.332189   0.4755575    2.3139945     4.095806
## 12    311          67      9.494065   3.0864776    1.5623237    13.654335
## 13     44          19      3.305533   0.3703584    2.5004155     3.864749
## 14    420          67     11.123299   1.2934341    8.6474474    13.257580
## 15    389          62     10.703034   1.1018437    8.0865505    12.705296
## 16    621          87     13.992169   2.7306336    8.2129473    18.503919
## 17    361          75     10.111333   3.3552681    2.9636314    14.539479
## 18    357          64     10.244403   1.8122203    7.0146679    13.037899
## 19    435          69     11.305686   1.1548827    8.8329856    13.834683
## 20    129          36      5.980610   0.9313067    4.1970191     7.498405
## 21    298          58      9.361134   2.0215001    4.6039648    12.788327
## 22    193          55      8.004665   2.7831936    3.3462450    13.494008
## 23    518          77     12.850968   1.7065512    9.7696871    16.372055
## 24    375          66     10.605399   1.6752607    6.0521153    13.707692
## 25    296          60      9.568764   2.7346801    4.1162618    13.240479
## 26    293          59      9.326125   2.1519705    4.5920944    12.679326
## 27    319          59      9.592548   1.5283310    5.2950031    11.936404
## 28    298          53      9.330598   0.8379296    7.9462864    11.174941
## 29     41          24      3.425799   1.3888233    1.3076962     5.631169
## 30    420          71     11.239198   2.0212645    7.1682393    15.389424
## 31    426          71     11.499226   3.2205048    4.3185267    16.412005
## 32    527          78     12.593632   2.7746344    7.2046491    17.092787
## 33    320          65      9.968671   3.3952696    3.6402744    14.971436
## 34    394          63     10.875879   1.6449716    7.5135722    13.660037
## 35    207          46      8.142217   2.1090645    4.7037973    11.353780
## 36    225          49      8.116555   1.8312625    4.9458964    11.162650
## 37    397          60     10.974379   1.5693077    7.5465408    13.719218
## 38    136          36      6.157999   0.7461044    4.4466141     7.640909
## 39    348          65     10.110098   2.8345070    3.4814810    13.567975
## 40    281          54      9.075496   1.5849007    6.3138101    11.906011
## 41    376          70     11.071847   2.7499368    6.8124286    16.161967
## 42     75          26      4.486989   0.7050572    2.7846791     5.607740
## 43    429          72     11.359828   2.5598612    5.2518552    15.312442
## 44    436          74     11.583097   3.0002508    4.9133656    16.382442
## 45    111          56      7.362079   3.6954862    1.5642082    13.581117
## 46    464          70     11.963935   2.3913054    6.9746626    15.853442
## 47    485          76     12.036427   2.2339630    7.8179711    15.559382
## 48    315          60      9.620033   1.9466415    5.0364229    12.744890
## 49    320          56      9.732844   1.2712755    7.3639012    11.877886
## 50    368          70     10.636651   2.4402276    5.2173963    14.980695
## 51    390          79     11.033786   3.5889820    1.6093382    15.952305
## 52    390          93     10.405770   4.0866145    1.3026739    16.318674
## 53    319          64      9.871016   2.7185802    5.0637055    14.532846
## 54    339          59      9.941373   0.9332251    8.2734958    11.655066
## 55    536          77     12.687949   2.3561859    8.2420786    16.448169
## 56    342          66     10.049837   2.9300224    2.8931460    14.155221
## 57    507          81     12.527034   3.2253364    6.2175786    17.870011
## 58    248          53      8.552597   1.7548511    4.2934790    11.441401
## 59    345          69     10.565709   3.4667560    3.1461295    15.804499
## 60    351          65     10.169064   2.1134302    5.2726154    13.820292
## 61    421          73     11.224041   3.0790975    3.9368729    16.263845
## 62    358          60     10.230394   0.7600282    8.7451733    11.632342
## 63    364          63     10.597760   2.2577422    7.1604897    15.149611
## 64    207          49      7.727419   1.1778694    5.2080817    10.220110
## 65    380          82     11.863925   5.1505547    2.0893558    19.863548
## 66    582          85     13.019464   2.5345198    7.0551853    16.635515
## 67    309          58      9.500583   1.4418692    6.3927166    11.827988
## 68    408          87     11.064216   4.1956813    0.5892416    16.864643
## 69    273          54      8.889901   1.4330635    5.7806557    11.055804
## 70    315          75      8.611755   3.1603344    0.5259489    12.309750
## 71    352          82     10.428098   4.4000913    2.2639941    17.451083
## 72    400          66     11.139322   2.3482859    7.3767342    15.324505
## 73    262          53      8.669239   0.9545777    6.9192824    10.276785
## 74    345          68     10.415186   3.3805793    3.2596012    15.656468
## 75    321          74     10.503623   3.7010085    4.3515402    17.611904
## 76     16          12      1.833022   0.6018740    0.9718253     2.635231

Put heatmap of correlations here.

Features computed by computeFeatures.shape are prefixed with “s.” and all are measured in pixels.

compute features

ft <- computeFeatures(x, y, xname="nucleus")
cat("median features are:\n")
## median features are:
apply(ft, 2, median)
##            nucleus.0.m.cx            nucleus.0.m.cy 
##              2.760080e+02              2.917190e+02 
##     nucleus.0.m.majoraxis  nucleus.0.m.eccentricity 
##              2.716022e+01              7.799645e-01 
##         nucleus.0.m.theta          nucleus.0.s.area 
##              6.983438e-02              3.450000e+02 
##     nucleus.0.s.perimeter   nucleus.0.s.radius.mean 
##              6.450000e+01              1.019973e+01 
##     nucleus.0.s.radius.sd    nucleus.0.s.radius.min 
##              2.245853e+00              5.135894e+00 
##    nucleus.0.s.radius.max          nucleus.a.b.mean 
##              1.365719e+01              5.537696e-01 
##            nucleus.a.b.sd           nucleus.a.b.mad 
##              1.184311e-01              1.162824e-01 
##          nucleus.a.b.q001          nucleus.a.b.q005 
##              3.151373e-01              3.598039e-01 
##           nucleus.a.b.q05          nucleus.a.b.q095 
##              5.647059e-01              7.411765e-01 
##          nucleus.a.b.q099            nucleus.a.m.cx 
##              7.681569e-01              2.759344e+02 
##            nucleus.a.m.cy     nucleus.a.m.majoraxis 
##              2.918791e+02              2.563950e+01 
##  nucleus.a.m.eccentricity         nucleus.a.m.theta 
##              7.673224e-01              2.233263e-02 
##        nucleus.a.h.asm.s1        nucleus.a.h.con.s1 
##              2.238844e-02              3.645172e+00 
##        nucleus.a.h.cor.s1        nucleus.a.h.var.s1 
##              8.512804e-01              1.240606e+01 
##        nucleus.a.h.idm.s1        nucleus.a.h.sav.s1 
##              5.039755e-01              3.630086e+01 
##        nucleus.a.h.sva.s1        nucleus.a.h.sen.s1 
##              1.269986e+03              1.339942e+00 
##        nucleus.a.h.ent.s1        nucleus.a.h.dva.s1 
##              1.816435e+00              3.645172e+00 
##        nucleus.a.h.den.s1        nucleus.a.h.f12.s1 
##              6.324399e-01              2.786244e-01 
##        nucleus.a.h.f13.s1        nucleus.a.h.asm.s2 
##              6.659335e-01              1.982790e-02 
##        nucleus.a.h.con.s2        nucleus.a.h.cor.s2 
##              9.450356e+00              6.010386e-01 
##        nucleus.a.h.var.s2        nucleus.a.h.idm.s2 
##              1.226194e+01              3.643872e-01 
##        nucleus.a.h.sav.s2        nucleus.a.h.sva.s2 
##              3.686993e+01              1.302210e+03 
##        nucleus.a.h.sen.s2        nucleus.a.h.ent.s2 
##              1.294284e+00              1.858567e+00 
##        nucleus.a.h.dva.s2        nucleus.a.h.den.s2 
##              9.450356e+00              8.014289e-01 
##        nucleus.a.h.f12.s2        nucleus.a.h.f13.s2 
##              1.731739e-01              5.477548e-01 
##         nucleus.Ba.b.mean           nucleus.Ba.b.sd 
##              6.112350e-01              2.347311e-01 
##          nucleus.Ba.b.mad         nucleus.Ba.b.q001 
##              2.489820e-01              1.576757e-01 
##         nucleus.Ba.b.q005          nucleus.Ba.b.q05 
##              2.603433e-01              6.334505e-01 
##         nucleus.Ba.b.q095         nucleus.Ba.b.q099 
##              1.033540e+00              1.132751e+00 
##           nucleus.Ba.m.cx           nucleus.Ba.m.cy 
##              2.759874e+02              2.918643e+02 
##    nucleus.Ba.m.majoraxis nucleus.Ba.m.eccentricity 
##              2.727524e+01              7.903687e-01 
##        nucleus.Ba.m.theta       nucleus.Ba.h.asm.s1 
##              8.621972e-03              1.065775e-02 
##       nucleus.Ba.h.con.s1       nucleus.Ba.h.cor.s1 
##              2.245891e+01              7.043244e-01 
##       nucleus.Ba.h.var.s1       nucleus.Ba.h.idm.s1 
##              4.250613e+01              3.103933e-01 
##       nucleus.Ba.h.sav.s1       nucleus.Ba.h.sva.s1 
##              4.025579e+01              1.637727e+03 
##       nucleus.Ba.h.sen.s1       nucleus.Ba.h.ent.s1 
##              1.568549e+00              2.330354e+00 
##       nucleus.Ba.h.dva.s1       nucleus.Ba.h.den.s1 
##              2.245891e+01              9.647075e-01 
##       nucleus.Ba.h.f12.s1       nucleus.Ba.h.f13.s1 
##              1.800243e-01              5.919088e-01 
##       nucleus.Ba.h.asm.s2       nucleus.Ba.h.con.s2 
##              9.993056e-03              5.253647e+01 
##       nucleus.Ba.h.cor.s2       nucleus.Ba.h.var.s2 
##              3.220357e-01              4.363279e+01 
##       nucleus.Ba.h.idm.s2       nucleus.Ba.h.sav.s2 
##              2.085173e-01              4.089912e+01 
##       nucleus.Ba.h.sva.s2       nucleus.Ba.h.sen.s2 
##              1.646988e+03              1.489651e+00 
##       nucleus.Ba.h.ent.s2       nucleus.Ba.h.dva.s2 
##              2.186038e+00              5.253647e+01 
##       nucleus.Ba.h.den.s2       nucleus.Ba.h.f12.s2 
##              1.126337e+00              1.735806e-01 
##       nucleus.Ba.h.f13.s2 
##              5.638763e-01

The function computeFeatures.basic computes spatial-independent statistics on pixel intensities that have a “b.” prefix: b.mean, b.sd, b.mad, b.q*. Intensity values range from 0.0 to 1.0.

The function computeFeatures.moment computes features related to object image moments, which can be computed with or without reference intensities, and have a prefix “m.”:

  • center of mass: m.cx, m.cy [pixels]
  • elliptical fit major axis: m.majoraxis [pixels]
  • elliptical eccentricity: m.eccentricity [dimensionless] (0=circle, 1=straight line)
  • object angle [radians]: m.theta

The function computeFeatures.haralick computes features that quantify pixel texture. Features are named according to Haralick’s original paper, Textural Features for Image Classification. Haralick texture features have a prefix “h.”.

Texture features in EBImage are calculated according to a Gray-Level Co-occurrence Matrix (GLCM) using the mean intensity of the pixel’s 4 neighboring pixels (0°, 45°, 90°, and 135°) according to Aleksi Räsänen et al: The GLCM features estimate different features of pixel brightness value combinations from the neighboring pixels. Overall, 13 GLCM features given by Haralick et al. (1973) were calculated: angular second moment (asm), contrast (con), correlation (cor), variance (var), inverse difference moment (idm), sum average (sav), sum variance (sva), sum entropy (sen), entropy (ent), difference variance (dva), difference entropy (den), and two measures of correlation (f12 and f13). For the GLCM calculations, the pixel brightness values were quantized to 16 gray levels using equal intervals.

compute feature properties

ftp <- computeFeatures(x, y, properties=TRUE, xname="nucleus")
ftp
##                         name translation.invariant rotation.invariant
## 1             nucleus.0.m.cx                 FALSE               TRUE
## 2             nucleus.0.m.cy                 FALSE               TRUE
## 3      nucleus.0.m.majoraxis                  TRUE               TRUE
## 4   nucleus.0.m.eccentricity                  TRUE               TRUE
## 5          nucleus.0.m.theta                  TRUE              FALSE
## 6           nucleus.0.s.area                  TRUE               TRUE
## 7      nucleus.0.s.perimeter                  TRUE               TRUE
## 8    nucleus.0.s.radius.mean                  TRUE               TRUE
## 9      nucleus.0.s.radius.sd                  TRUE               TRUE
## 10    nucleus.0.s.radius.min                  TRUE               TRUE
## 11    nucleus.0.s.radius.max                  TRUE               TRUE
## 12          nucleus.a.b.mean                  TRUE               TRUE
## 13            nucleus.a.b.sd                  TRUE               TRUE
## 14           nucleus.a.b.mad                  TRUE               TRUE
## 15          nucleus.a.b.q001                  TRUE               TRUE
## 16          nucleus.a.b.q005                  TRUE               TRUE
## 17           nucleus.a.b.q05                  TRUE               TRUE
## 18          nucleus.a.b.q095                  TRUE               TRUE
## 19          nucleus.a.b.q099                  TRUE               TRUE
## 20            nucleus.a.m.cx                 FALSE               TRUE
## 21            nucleus.a.m.cy                 FALSE               TRUE
## 22     nucleus.a.m.majoraxis                  TRUE               TRUE
## 23  nucleus.a.m.eccentricity                  TRUE               TRUE
## 24         nucleus.a.m.theta                  TRUE              FALSE
## 25        nucleus.a.h.asm.s1                  TRUE               TRUE
## 26        nucleus.a.h.con.s1                  TRUE               TRUE
## 27        nucleus.a.h.cor.s1                  TRUE               TRUE
## 28        nucleus.a.h.var.s1                  TRUE               TRUE
## 29        nucleus.a.h.idm.s1                  TRUE               TRUE
## 30        nucleus.a.h.sav.s1                  TRUE               TRUE
## 31        nucleus.a.h.sva.s1                  TRUE               TRUE
## 32        nucleus.a.h.sen.s1                  TRUE               TRUE
## 33        nucleus.a.h.ent.s1                  TRUE               TRUE
## 34        nucleus.a.h.dva.s1                  TRUE               TRUE
## 35        nucleus.a.h.den.s1                  TRUE               TRUE
## 36        nucleus.a.h.f12.s1                  TRUE               TRUE
## 37        nucleus.a.h.f13.s1                  TRUE               TRUE
## 38        nucleus.a.h.asm.s2                  TRUE               TRUE
## 39        nucleus.a.h.con.s2                  TRUE               TRUE
## 40        nucleus.a.h.cor.s2                  TRUE               TRUE
## 41        nucleus.a.h.var.s2                  TRUE               TRUE
## 42        nucleus.a.h.idm.s2                  TRUE               TRUE
## 43        nucleus.a.h.sav.s2                  TRUE               TRUE
## 44        nucleus.a.h.sva.s2                  TRUE               TRUE
## 45        nucleus.a.h.sen.s2                  TRUE               TRUE
## 46        nucleus.a.h.ent.s2                  TRUE               TRUE
## 47        nucleus.a.h.dva.s2                  TRUE               TRUE
## 48        nucleus.a.h.den.s2                  TRUE               TRUE
## 49        nucleus.a.h.f12.s2                  TRUE               TRUE
## 50        nucleus.a.h.f13.s2                  TRUE               TRUE
## 51         nucleus.Ba.b.mean                  TRUE               TRUE
## 52           nucleus.Ba.b.sd                  TRUE               TRUE
## 53          nucleus.Ba.b.mad                  TRUE               TRUE
## 54         nucleus.Ba.b.q001                  TRUE               TRUE
## 55         nucleus.Ba.b.q005                  TRUE               TRUE
## 56          nucleus.Ba.b.q05                  TRUE               TRUE
## 57         nucleus.Ba.b.q095                  TRUE               TRUE
## 58         nucleus.Ba.b.q099                  TRUE               TRUE
## 59           nucleus.Ba.m.cx                 FALSE               TRUE
## 60           nucleus.Ba.m.cy                 FALSE               TRUE
## 61    nucleus.Ba.m.majoraxis                  TRUE               TRUE
## 62 nucleus.Ba.m.eccentricity                  TRUE               TRUE
## 63        nucleus.Ba.m.theta                  TRUE              FALSE
## 64       nucleus.Ba.h.asm.s1                  TRUE               TRUE
## 65       nucleus.Ba.h.con.s1                  TRUE               TRUE
## 66       nucleus.Ba.h.cor.s1                  TRUE               TRUE
## 67       nucleus.Ba.h.var.s1                  TRUE               TRUE
## 68       nucleus.Ba.h.idm.s1                  TRUE               TRUE
## 69       nucleus.Ba.h.sav.s1                  TRUE               TRUE
## 70       nucleus.Ba.h.sva.s1                  TRUE               TRUE
## 71       nucleus.Ba.h.sen.s1                  TRUE               TRUE
## 72       nucleus.Ba.h.ent.s1                  TRUE               TRUE
## 73       nucleus.Ba.h.dva.s1                  TRUE               TRUE
## 74       nucleus.Ba.h.den.s1                  TRUE               TRUE
## 75       nucleus.Ba.h.f12.s1                  TRUE               TRUE
## 76       nucleus.Ba.h.f13.s1                  TRUE               TRUE
## 77       nucleus.Ba.h.asm.s2                  TRUE               TRUE
## 78       nucleus.Ba.h.con.s2                  TRUE               TRUE
## 79       nucleus.Ba.h.cor.s2                  TRUE               TRUE
## 80       nucleus.Ba.h.var.s2                  TRUE               TRUE
## 81       nucleus.Ba.h.idm.s2                  TRUE               TRUE
## 82       nucleus.Ba.h.sav.s2                  TRUE               TRUE
## 83       nucleus.Ba.h.sva.s2                  TRUE               TRUE
## 84       nucleus.Ba.h.sen.s2                  TRUE               TRUE
## 85       nucleus.Ba.h.ent.s2                  TRUE               TRUE
## 86       nucleus.Ba.h.dva.s2                  TRUE               TRUE
## 87       nucleus.Ba.h.den.s2                  TRUE               TRUE
## 88       nucleus.Ba.h.f12.s2                  TRUE               TRUE
## 89       nucleus.Ba.h.f13.s2                  TRUE               TRUE

Related: Slides 13-22 in Wolfgang Huber’s presentation Machine learning in high-throughput screening and automated phenotyping [~35 MB].


packageVersion("EBImage")
## [1] '4.8.2'

efg
2015-01-19 1926