\HeaderA{Image-class}{Defintion of class 'Image', its accessor methods}{Image.Rdash.class}
\aliasA{colorMode}{Image-class}{colorMode}
\aliasA{colorMode<\Rdash}{Image-class}{colorMode<.Rdash.}
\aliasA{compression}{Image-class}{compression}
\aliasA{compression<\Rdash}{Image-class}{compression<.Rdash.}
\aliasA{fileName}{Image-class}{fileName}
\aliasA{fileName<\Rdash}{Image-class}{fileName<.Rdash.}
\aliasA{Grayscale}{Image-class}{Grayscale}
\aliasA{imageData}{Image-class}{imageData}
\aliasA{imageData<\Rdash}{Image-class}{imageData<.Rdash.}
\aliasA{resolution}{Image-class}{resolution}
\aliasA{resolution<\Rdash}{Image-class}{resolution<.Rdash.}
\aliasA{TrueColor}{Image-class}{TrueColor}
\keyword{methods}{Image-class}
\keyword{classes}{Image-class}
\begin{Description}\relax
The class \code{Image} enables the storage and manipulation of image data for
grayscale and true color (RGB) images in \code{R}. The class is based on 
(derived from) \code{\LinkA{array}{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 \code{Image}.
\end{Description}
\begin{Section}{Class Definition}
The class is defined as follows:

\begin{alltt}
\#\# S4 class definition

setClass( "Image",
  representation (
    colormode    = "integer", 
    filename     = "character",
    compression  = "character", 
    resolution   = "numeric",   
    features     = "list"
  ),
  contains = "array"
)
\end{alltt}

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

\begin{alltt}
  Grayscale = as.integer(0)
  TrueColor = as.integer(1)
\end{alltt}
\end{Section}
\begin{Section}{Creating objects}
Objects can be created using \code{\LinkA{new}{new}("Image")} supplying slot data
as necessary. Additionally, wrapper functions are defined to simplify the
construction of \code{Image} objects in different situations: the default 
constructor, \code{\LinkA{Image}{Image}}, the \code{\LinkA{readImage}{readImage}} constructor that
creates an object from reading image files and the \code{\LinkA{copy}{copy}} constructor.
\end{Section}
\begin{Section}{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 \code{Image}:

\describe{

\item[\code{colorMode(x)}, \code{colorMode(x) <- value}] Gets and
sets image color mode. \code{value} is one of the constants above.
Default: \code{Grayscale}. 

\item[\code{compression(x)}, \code{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 \code{\LinkA{character}{character}} are \code{'NONE', 'LZW',
      'ZIP', 'JPEG', 'BZIP'} and \code{'GROUP4'}. Some of these may be
unavailable on your system if \code{ImageMagick} was compiles without
their support. Default: \code{'LZW'}. 

\item[\code{features(x)}] Is a read only method that returns a
\code{\LinkA{list}{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: \code{list()}. 

\item[\code{fileName(x)}, \code{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: \code{'no-name'}. 

\item[\code{imageData(x)}, \code{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 \code{colorMode()}. 

\item[\code{resolution(x)}, \code{resolution(x) <- value}] Gets
and sets values of image resoultion: a numeric vector of two values
of resolution in \code{x} and \code{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. 

}
\end{Section}
\begin{Section}{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 \code{drop} parameter is set to 
\code{FALSE}, thus image dimensionality is preserved at 3.

\code{Image} is derived from \code{\LinkA{array}{array}}, therefore, the data is stored
in arrays. \code{Image} can store either grayscale or true color data at the
moment. Grayscale data is stored in \code{\LinkA{numeric}{numeric}} arrays, whereas true
color data is stored in \code{\LinkA{integer}{integer}} arrays. Correspondingly, the data 
is created with \code{array(as.numeric(val),dim(val))} for grayscale and
\code{array(as.integer(val),dim(val))} for true color images. Grayscale values
are assumed to be in the range \code{[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.
\end{Section}
\begin{Author}\relax
Oleg Sklyar, \email{osklyar@ebi.ac.uk}, 2005-2007
\end{Author}
\begin{SeeAlso}\relax
\code{
  \LinkA{Image}{Image}, \LinkA{Image}{Image}, \LinkA{Image}{Image}, \LinkA{Image}{Image}, 
  \LinkA{Image}{Image}, \LinkA{Image}{Image}, 
}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}

  ## 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)
\end{ExampleCode}
\end{Examples}

