Skip to content

Commit 241ee94

Browse files
committed
Adds flip function. Closes #36.
1 parent 6dead5d commit 241ee94

File tree

11 files changed

+347
-2
lines changed

11 files changed

+347
-2
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export(findNonZero)
7777
export(findTransformECC)
7878
export(findTransformORB)
7979
export(fitEllipse)
80+
export(flip)
8081
export(floodFill)
8182
export(fourcc)
8283
export(fps)

R/geometry.R

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,48 @@ resize <- function(image, height = NULL, width = NULL, fx = NULL, fy = NULL, int
9292
Lanczos = 4,
9393
exact = 5,
9494
stop("This is not a valid interpolation method.")))
95+
}
96+
97+
98+
#' @title Flip an \code{\link{Image}}
99+
#'
100+
#' @description \code{flip} returns a flipped version of an \code{\link{Image}}
101+
#' around one or both of its axes.
102+
#'
103+
#' @param image An \code{\link{Image}} object.
104+
#'
105+
#' @param type An integer indicating the type of flipping to be performed. If
106+
#' \code{type = 0} (the default), the image is flipped around its x-axis; if
107+
#' \code{type = 1} (or any positive value, then it is flipped around its y-axis;
108+
#' finally, if \code{type = -1} (or any negative value, then it is flipped
109+
#' around both axes.)
110+
#'
111+
#' @param in_place A logical indicating whether the change should be applied to
112+
#' the image itself (TRUE, faster but destructive) or to a copy of it (FALSE,
113+
#' the default, slower but non destructive).
114+
#'
115+
#' @return An \code{\link{Image}} object if \code{in_place=FALSE}. Otherwise, it
116+
#' returns nothing and modifies \code{image} in place.
117+
#'
118+
#' @author Simon Garnier, \email{garnier@@njit.edu}
119+
#'
120+
#' @seealso \code{\link{Image}}
121+
#'
122+
#' @examples
123+
#' balloon <- image(system.file("sample_img/balloon1.png", package = "Rvision"))
124+
#' balloon_flipped <- flip(balloon, -1)
125+
#' plot(balloon_flipped)
126+
#'
127+
#' @export
128+
flip <- function(image, type = 0, in_place = FALSE) {
129+
if (!isImage(image))
130+
stop("This is not an Image object.")
131+
132+
if (in_place == TRUE) {
133+
`_flip`(image, type)
134+
} else {
135+
out <- `_cloneImage`(image)
136+
`_flip`(out, type)
137+
out
138+
}
95139
}

docs/pkgdown.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ articles:
55
z1_install: z1_install.html
66
z2_io: z2_io.html
77
z3_basic: z3_basic.html
8-
last_built: 2021-02-05T17:53Z
8+
last_built: 2021-02-05T18:09Z
99
urls:
1010
reference: https://swarm-lab.github.io/ROpenCVLite//reference
1111
article: https://swarm-lab.github.io/ROpenCVLite//articles

docs/reference/flip-1.png

459 KB
Loading

docs/reference/flip.html

Lines changed: 246 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/index.html

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/sitemap.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@
159159
<url>
160160
<loc>https://swarm-lab.github.io/ROpenCVLite//reference/fitEllipse.html</loc>
161161
</url>
162+
<url>
163+
<loc>https://swarm-lab.github.io/ROpenCVLite//reference/flip.html</loc>
164+
</url>
162165
<url>
163166
<loc>https://swarm-lab.github.io/ROpenCVLite//reference/floodFill.html</loc>
164167
</url>

man/flip.Rd

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/geometry.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ Image _resize(Image image, int height, int width, double fx, double fy, int inte
33

44
cv::resize(image.image, out, cv::Size(width, height), fx, fy, interpolation);
55
return Image(out);
6+
}
7+
8+
void _flip(Image image, int flipCode) {
9+
cv::flip(image.image, image.image, flipCode);
610
}

src/shape.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ Rcpp::List _connectedComponents(Image image, int connectivity) {
8282
}
8383

8484
void _watershed(Image image, Image markers) {
85-
cv::Mat out;
8685
cv::watershed(image.image, markers.image);
8786
}
8887

0 commit comments

Comments
 (0)