\name{as.rip}
\alias{as.rip}
\alias{as.rip.rip}
\alias{as.rip.default}
\alias{as.rip.matrix}
\alias{as.rip.array}
\alias{as.rip.raster}
\alias{as.rip.nativeRaster}
\alias{as.raster.rip}
\alias{as.array.rip}
\title{Convert to and from rip objects}
\usage{
as.rip(x, ...)
\method{as.rip}{rip}(x, ...)
\method{as.rip}{default}(x, channel = 1, ...)
\method{as.rip}{matrix}(x, channel = 1, ...)
\method{as.rip}{array}(x, reverse.rgb = TRUE, ...)
\method{as.rip}{raster}(x, ...)
\method{as.rip}{nativeRaster}(x, ...)
\method{as.raster}{rip}(x, ..., rescale = TRUE, restrict = TRUE)
\method{as.array}{rip}(x, reverse.rgb = TRUE, ...)
}
\arguments{
  \item{x}{
    Matrix containing data of rip object. The default method handles
    matrix-like input, where data for multiple channels should be in
    successive columns.
  }
  \item{channel}{
    The number of channels in the rip object to be created.
  }
  \item{reverse.rgb}{
    Logical flag indicating whether the order of the channels is to be
    reversed, only in the case where the number of channels is 3. The
    default is chosen for the common case of 3-channel RGB images, where
    the RGB ordering is often more common elsewhere but the OpenCV
    default is BGR.
  }
  \item{rescale}{
    Logical flag indicating whether data should be rescaled to lie
    between 0 and 255. If \code{TRUE}, \code{min(x)} becomes 0 and
    \code{max(x)} becomes 255.
  }

  \item{restrict}{
    Logical flag indicating whether values outside of the range [0, 255]
    should be truncated to their nearest endpoints.
  }
  \item{...}{
    Additional arguments for compatibility with generic; ignored.
  }
}
\value{
  An object of the appropriate class. 
}
\description{
  Convert compatible data to and from \code{"rip"} objects.
}
\details{

  The various \code{as.rip} methods provide utilities to convert
  image-like objects to \code{"rip"} objects. This includes
  \code{\link[=as.raster]{raster}} objects as well as
  \code{"nativeRaster"} objects which allow efficient representation of
  8-bit RGBA images (e.g., see \code{\link[png]{readPNG}}).

  Conversely, the \code{as.raster} and \code{as.array} methods allow
  conversion from \code{"rip"} objects to representations more amenable
  to processing in R. For example, arrays support more intuitive
  row-column indexing for multi-channel images, and raster objects can
  be handled by R graphics.
}

\examples{

f <- system.file("sample/color.jpg", package = "rip.opencv", mustWork = TRUE)
x <- rip.import(f, type = "original")
x
## index via conversion to array
plot(as.array(x)[1:400, 1:400, ] |> as.rip())

}

\author{
  Kaustav Nandy and Deepayan Sarkar
}
