EBImage is a Bioc package (but since it will not compile properly on a Mac running Yosemite) I failed in my initial efforts to explore this problem. On this machine running Lion I am able to demonstrate how to look at items of formal class "Image" and how to pick them apart. (I'm using a commercial file that was attached to one of my emails as my test case, and it is only 142 x 69 pixels so I used a smaller "window"
> Image <- Image[75:100, 25:50,]
> display(Image)
> str(Image)
Formal class 'Image' [package "EBImage"] with 2 slots
..@ .Data : num [1:21, 1:31, 1:3] 1 1 1 1 1 ...
..@ colormode: int 2
So the .Data
component of this S4 object is a 21 x 31 x 3 R array. There are presumably a red, green and blue layer although I'm not an image expert and there might be other color schems. This will let you "see" the upper left corner of the first layer:
> Image@.Data[ 1:5,1:5 , 1]
[,1] [,2] [,3] [,4] [,5]
[1,] 1 0.9882353 1.0000000 1.0000000 1.0000000
[2,] 1 1.0000000 1.0000000 1.0000000 1.0000000
[3,] 1 1.0000000 1.0000000 0.9803922 0.8470588
[4,] 1 1.0000000 0.9960784 0.8588235 0.6627451
[5,] 1 1.0000000 0.9607843 0.8470588 0.6901961
Notice the at-sign rather than the dollar sign as the infix extraction operator. This will provide a mechanism for calculating the sum of layer values with the coefficients and squaring you requested:
> Y <- 0.2126*Image@.Data[ , , 1]^2 + 0.7152*Image@.Data[ , , 2]^2 + 0.0722*Image@.Data[ , , 3]^2
> str(Y)
num [1:21, 1:31] 0.974 0.956 0.957 0.963 0.97 ...
The result is an R matrix of "intensities" of the same dimensions as the projected RGB layers (if that are what .jpg files are using.)