Image-class {EBImage} | R Documentation |
Image
is the base class to hold data and parameters of grayscale and
RGB images in R
. The class is derived from array
and
inherits all of its properties and methods, e.g. mathematical operations
on arrays, subsetting, histograms etc. Image processing routines are
defined additionally as S4 methods for objects of this class. In many cases
they also return objects of class Image
.
The following constant are defined in the package and should be used everywhere where image color mode needs to be specified.
Grayscale = as.integer(0) TrueColor = as.integer(1)
# S4 methods for class 'Image':
colorMode(x)
, colorMode(x) <- value
value
is one of the constants above.
Default: Grayscale
. compression(x)
, compression(x) <- value
character
are 'NONE', 'LZW',
'ZIP', 'JPEG', 'BZIP'
and 'GROUP4'
. Some of these may be
unavailable on your system if ImageMagick
was compiles without
their support. Default: 'LZW'
. features(x)
list
or matrices with descriptors of detected objects.
If object detection was executed on the image, an empty list is
returned. Otherwise, the number of elements matches the number of
frames in the image. Default: list()
. fileName(x)
, fileName(x) <- value
'no-name'
. imageData(x)
, imageData(x) <- value
colorMode()
. resolution(x)
, resolution(x) <- value
x
and y
dimensions. Generally resolution
is understood in pixel-per-inch (ppi) or dots-per-inch (dpi), however
some microscopes can save these values in images in different units.
It is the responsibility of the user to identify the unit and keep the
units comparable between different images in the same project if
required: the package does not take care of this. The default values
are equal for both directions, 2.5e+6 dpi. sampleFilter(x)
, sampleFilter(x) <- value
resize
and other image transformation routines. Possibly
this value will be removed and supplied as argument to the
corresponding function. At the moment, possible values include:
'point', 'box', 'triangle', 'hermite', 'hanning', 'hamming',
'blackman', 'gaussian', 'quadratic', 'cubic', 'catrom', 'mitchell',
'lanczos', 'bessel'
and 'sinc'
. Default: 'lanczos'
. R does not have a concept of private/public class members, therefore, the following cannot be enforced and are just recommendations: use only accessor methods to get/set slot data; and consequently – everything that does not have an accessor method should not be accessed directly by the user. For this reason, we do not describe slots here: consider all slots as private. Package developers can have a look at the code and see the full object structure.
Objects can be created using new("Image")
supplying slot data
if necessary. Additionally, wrapper functions are defined to simplify the
construction of Image
objects in different situations.
See Image
constructor and read.image
function on
details how to create images or read images from disk or network.
Image data are stored as 3D arrays,
with first two dimensions specifying image/frame size and third – number
of frames. A single 2D image will have the number of frames 1. In subsetting,
the value of drop
parameter is set to FALSE
, thus image
dimensionality is preserved at 3.
At the moment, images can store data either as grayscale values or true color values.
Grayscale values are stored in numeric
or double
arrays, whereas true color data are stored as integer
arrays.
I.e. the type of image array with grayscale data can be tested as:
is.array(x) && is.numeric(x) && !is.integer(x)
whereas for true color
data the test would look like: is.array(x) && is.integer(x)
.
Correspondingly, the data slots are created with
array(as.numeric(val),...)
for grayscales and
array(as.integer(val),...)
for true color images. Grayscale values are
assumed to be in the range [0,1]
, although this is not a requirement.
However, many image processing functions will also assume data in this range
or will generate wrong results if the data do not fit the range.
Copyright (c) 2005-2006 Oleg Sklyar : osklyar@ebi.ac.uk, LGPL >= 2.1
Image, image.Image, display, channel
if ( interactive() ) { ## Not run: creates a new Grayscale image of shifted stripes a <- Image( (0:100)*0.01, c(60,60) ) display( a ) print( a ) ## Not run: converts image mode to TrueColor, compare print's b <- a colorMode( b ) <- TrueColor print( b ) ## Not run: fills values with brightness > 50% with red b[ a > 0.5 ] = as.integer( 255 ) display( b ) }