Skip to content

Commit

Permalink
Adds flip function. Closes #36.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjmgarnier committed Feb 5, 2021
1 parent 6dead5d commit 241ee94
Show file tree
Hide file tree
Showing 11 changed files with 347 additions and 2 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export(findNonZero)
export(findTransformECC)
export(findTransformORB)
export(fitEllipse)
export(flip)
export(floodFill)
export(fourcc)
export(fps)
Expand Down
44 changes: 44 additions & 0 deletions R/geometry.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,48 @@ resize <- function(image, height = NULL, width = NULL, fx = NULL, fy = NULL, int
Lanczos = 4,
exact = 5,
stop("This is not a valid interpolation method.")))
}


#' @title Flip an \code{\link{Image}}
#'
#' @description \code{flip} returns a flipped version of an \code{\link{Image}}
#' around one or both of its axes.
#'
#' @param image An \code{\link{Image}} object.
#'
#' @param type An integer indicating the type of flipping to be performed. If
#' \code{type = 0} (the default), the image is flipped around its x-axis; if
#' \code{type = 1} (or any positive value, then it is flipped around its y-axis;
#' finally, if \code{type = -1} (or any negative value, then it is flipped
#' around both axes.)
#'
#' @param in_place A logical indicating whether the change should be applied to
#' the image itself (TRUE, faster but destructive) or to a copy of it (FALSE,
#' the default, slower but non destructive).
#'
#' @return An \code{\link{Image}} object if \code{in_place=FALSE}. Otherwise, it
#' returns nothing and modifies \code{image} in place.
#'
#' @author Simon Garnier, \email{garnier@@njit.edu}
#'
#' @seealso \code{\link{Image}}
#'
#' @examples
#' balloon <- image(system.file("sample_img/balloon1.png", package = "Rvision"))
#' balloon_flipped <- flip(balloon, -1)
#' plot(balloon_flipped)
#'
#' @export
flip <- function(image, type = 0, in_place = FALSE) {
if (!isImage(image))
stop("This is not an Image object.")

if (in_place == TRUE) {
`_flip`(image, type)
} else {
out <- `_cloneImage`(image)
`_flip`(out, type)
out
}
}
2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ articles:
z1_install: z1_install.html
z2_io: z2_io.html
z3_basic: z3_basic.html
last_built: 2021-02-05T17:53Z
last_built: 2021-02-05T18:09Z
urls:
reference: https://swarm-lab.github.io/ROpenCVLite//reference
article: https://swarm-lab.github.io/ROpenCVLite//articles
Expand Down
Binary file added docs/reference/flip-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
246 changes: 246 additions & 0 deletions docs/reference/flip.html

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

6 changes: 6 additions & 0 deletions docs/reference/index.html

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

3 changes: 3 additions & 0 deletions docs/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@
<url>
<loc>https://swarm-lab.github.io/ROpenCVLite//reference/fitEllipse.html</loc>
</url>
<url>
<loc>https://swarm-lab.github.io/ROpenCVLite//reference/flip.html</loc>
</url>
<url>
<loc>https://swarm-lab.github.io/ROpenCVLite//reference/floodFill.html</loc>
</url>
Expand Down
41 changes: 41 additions & 0 deletions man/flip.Rd

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

4 changes: 4 additions & 0 deletions src/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ Image _resize(Image image, int height, int width, double fx, double fy, int inte

cv::resize(image.image, out, cv::Size(width, height), fx, fy, interpolation);
return Image(out);
}

void _flip(Image image, int flipCode) {
cv::flip(image.image, image.image, flipCode);
}
1 change: 0 additions & 1 deletion src/shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ Rcpp::List _connectedComponents(Image image, int connectivity) {
}

void _watershed(Image image, Image markers) {
cv::Mat out;
cv::watershed(image.image, markers.image);
}

Expand Down
Loading

0 comments on commit 241ee94

Please sign in to comment.