R/egg.pixels.R

Defines functions egg.pixels

Documented in egg.pixels

#' Extract egg pixels
#'
#' Extracts egg pixels from the current image
#'
#' @param egg.image a raster image of an egg
#' @param egg an object of class \code{egg.fit}
#' @param lower.theta the lower limit from which to extract pixels around the horizontal axis
#' @param upper.theta the upper limit from which to extract pixels around the horizontal axis
#' @param lower.phi the lower limit from which to extract pixels around the vertical axis
#' @param upper.phi the upper limit from which to extract pixels around the vertical axis
#'
#' @return An object of class \code{egg.pixels} containing the speherical coordinates (\code{coords}) and colour (\code{col}) of each pixel
#'
#' @examples
#' stop()
#'
#' @export
egg.pixels = function(egg.image, egg, lower.theta=0, upper.theta=pi, lower.phi=0, upper.phi=pi) {
  dim = attributes(egg.image)$dim
  sph = matrix(NaN, dim[1]*dim[2], 3)
  if(length(dim) != 3) {
    egg.image = array(egg.image, c(dim[1],dim[2],3))
  }
  rgb = matrix(0, dim[1]*dim[2], 3)
  n = 1
  for(i in 1:dim[1]) {
    for(j in 1:dim[2]) {
      s = get.sph(j, dim[1]-i, egg)
      if(!any(is.nan(s))) {
        if((s[2] > lower.theta) && (s[2] < upper.theta)) {
          if((s[3] > lower.phi) && (s[3] < upper.phi)) {
            sph[n,] = get.sph(j, dim[1]-i, egg)
            rgb[n,] = egg.image[i,j,]
          }
        }
      }
      n = n + 1
    }
  }
  rgb = rgb[complete.cases(sph),]
  sph = sph[complete.cases(sph),]
  out = list(coords=sph, col=rgb(rgb))
  class(out) = "egg.pixels"
  return(out)
}

Try the egg package in your browser

Any scripts or data that you put into this service are public.

egg documentation built on May 2, 2019, 5:55 p.m.