Skip to content

Commit

Permalink
Merge pull request #55 from swarm-lab/develop
Browse files Browse the repository at this point in the history
Add grabCut documentation. Update website.
  • Loading branch information
sjmgarnier authored Jun 10, 2022
2 parents 1bd0cf7 + 8354f20 commit d395340
Show file tree
Hide file tree
Showing 14 changed files with 811 additions and 175 deletions.
60 changes: 60 additions & 0 deletions R/transform.R
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,66 @@ histEq <- function(image, target = "new") {
}


#' @title Segmentation with GrabCut Algorithm
#'
#' @description \code{grabCut} performs image segmentation (i.e., partition of
#' the image into coherent regions) using the GrabCut method.
#'
#' @param image An 8-bit (8U), 3-channel \code{\link{Image}} object to segment.
#'
#' @param mask An 8-bit (8U), single-channel \code{\link{Image}} object. Each
#' pixel can take any of the following 4 values:
#' \itemize{
#' \item{0: }{an obvious background pixels.}
#' \item{1: }{an obvious foreground (object) pixel.}
#' \item{2: }{a possible background pixel.}
#' \item{3: }{a possible foreground pixel.}
#' }
#'
#' @param rect A vector defining the region of interest containing a segmented
#' object. The pixels outside of the region of interest are marked as "obvious
#' background". \code{rect} must be a 4-element numeric vector which elements
#' correspond to - in this order - the x and y coordinates of the bottom left
#' corner of the region of interest, and to its width and height. The parameter
#' is only used when \code{mode="RECT"} (default: rep(1, 4)).
#'
#' @param bgdModel A 1x65, single-channel, 64-bit (64F) \code{\link{Image}}
#' object to set and store the parameters of the background model.
#'
#' @param fgdModel A 1x65, single-channel, 64-bit (64F) \code{\link{Image}}
#' object to set and store the parameters of the foreground model.
#'
#' @param iter Number of iterations (default: 1) the algorithm should make
#' before returning the result. Note that the result can be refined with
#' further calls with \code{mode="MASK"} or \code{mode="MASK"}.
#'
#' @param mode A character string indicating the operation mode of the function.
#' It can be any of the following:
#' \itemize{
#' \item{"RECT": }{The function initializes the state and the mask using the
#' provided \code{rect}. After that it runs \code{iter} iterations of the
#' algorithm.}
#' \item{"MASK":}{The function initializes the state using the provided
#' \code{mask}.}
#' \item{"EVAL":}{The value means that the function should just resume.}
#' \item{"FREEZE":}{The value means that the function should just run the
#' grabCut algorithm (a single iteration) with the fixed model.}
#' }
#'
#' @return This function returns nothing. It modifies in place \code{mask},
#' \code{bgdModel}, and \code{fgdModel}.
#'
#' @author Simon Garnier, \email{garnier@@njit.edu}
#'
#' @seealso \code{\link{Image}}
#'
#' @examples
#' balloon <- image(system.file("sample_img/balloon1.png", package = "Rvision"))
#' mask <- zeros(nrow(balloon), ncol(balloon), 1)
#' bgdModel <- zeros(1, 65, 1, "64F")
#' fgdModel <- zeros(1, 65, 1, "64F")
#' grabCut(balloon, mask, c(290, 170, 160, 160), bgdModel, fgdModel, iter = 5, mode = "RECT")
#'
#' @export
grabCut <- function(image, mask, rect = rep(1, 4), bgdModel, fgdModel, iter = 1,
mode = "EVAL") {
Expand Down
2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ articles:
z4_inplace: z4_inplace.html
z5_gpu: z5_gpu.html
z6_queue: z6_queue.html
last_built: 2022-06-06T14:07Z
last_built: 2022-06-10T08:57Z
urls:
reference: https://swarm-lab.github.io/ROpenCVLite/reference
article: https://swarm-lab.github.io/ROpenCVLite/articles
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/convexHull.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

140 changes: 46 additions & 94 deletions docs/reference/convexityDefects.html

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/reference/fitEllipse.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d395340

Please sign in to comment.