Image-class {EBImage} | R Documentation

## Defintion of class 'Image', its accessor methods

### Description

The class `Image` enables the storage and manipulation of image data for grayscale and true color (RGB) images in `R`. The class is based on (derived from) `array` and inherits all its properties and methods, e.g. mathematical operations, subsetting, histograms etc. Image processing and analysis routines are defined as S4 methods for objects of the class `Image`.

### Class Definition

The class is defined as follows:

    ## S4 class definition

    setClass( "Image",
      representation (
        colormode    = "integer",
        filename     = "character",
        compression  = "character",
        resolution   = "numeric",
        features     = "list"
      ),
      contains = "array"
    )

Additionally, two constants are defined and exported that can be used to specify or test image data type:

      Grayscale = as.integer(0)
      TrueColor = as.integer(1)

### Creating objects

Objects can be created using `new("Image")` supplying slot data as necessary. Additionally, wrapper functions are defined to simplify the construction of `Image` objects in different situations: the default constructor, `Image`, the `readImage` constructor that creates an object from reading image files and the `copy` constructor.

### Accessor methods

Accessor methods are class methods that are defined to retrieve data values from objects of a given class or to assigne those. These should be used instead of directly referring to the slots. Unfortunately, R does not have a concept of private or protected class members: all slots have "public" access in terms of other object-oriented languages. Therefore, data encapsulation in sense of hiding the particular structure of the class is impossible. At the same time, it is still recommended to use accessor functions instead of directly accessing slots. One can also assume that any slot that does not have an accessor method should not be accessed directly by the user.

The following accessor methods are defined as S4 methods for class `Image`:

`colorMode(x)`, `colorMode(x) <- value`
  Gets and sets image color mode. `value` is one of the constants above. Default: `Grayscale`.
`compression(x)`, `compression(x) <- value`
  Gets and sets compression algorithm used when image saved in a format supporting compression. For exapmple, TIFF images support ZIP and LZW lossless compressions, whereas JPEG uses JPEG compression by default. Possible values of type `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)`
  Is a read only method that returns a `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`
  Gets and sets the file name. When reading images this value is updated, when writing it can be used as default if no alternative is specified. When reading a stack, the first file name in the list of stack images will be assigned. Default: `'no-name'`.
`imageData(x)`, `imageData(x) <- value`
  Gets and sets image data. Image data is a 3D array with the last dimension matching the number of 2D images in a stack. The atomic type of the array is defined by `colorMode()`.
`resolution(x)`, `resolution(x) <- value`
  Gets and sets values of image resoultion: a numeric vector of two values of resolution in `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.

### Details

Image data are stored as 3D arrays with first two dimensions specifying frame size and third the number of frames. A single 2D image has the number of frames 1. In subsetting, the value of `drop` parameter is set to `FALSE`, thus image dimensionality is preserved at 3.

`Image` is derived from `array`, therefore, the data is stored in arrays. `Image` can store either grayscale or true color data at the moment. Grayscale data is stored in `numeric` arrays, whereas true color data is stored in `integer` arrays. Correspondingly, the data is created with `array(as.numeric(val),dim(val))` for grayscale and `array(as.integer(val),dim(val))` for true color images. Grayscale values are assumed to be in the range `[0,1]`, although this is not a requirement in sense of data storage. Although, many image processing functions will assume data in this range or will generate invalid results for the data out of this range.

### Author(s)

Oleg Sklyar, osklyar@ebi.ac.uk, 2005-2007

### See Also

`Image, IndexedImage, display, channel, image,Image-method, show,Image-method,`

### Examples

      ## New Grayscale image of a black-to-white vertical gradient
      w <- 120
      a <- Image((0:(w^2))/w^2, c(w,w))
      if ( interactive() ) display(a)
      print(a)

      ## Converts image to TrueColor
      b <- a
      colorMode(b) <- TrueColor
      print(b)

      ## Fills values with intensities over 0.5 (50%) with red
      b[ a > 0.5 ] = as.integer(255)
      if ( interactive() ) display(b)

[Package EBImage version 2.4.0 Index]