From 9f3ee13478f0ff39e109a8016db430faf38774d6 Mon Sep 17 00:00:00 2001 From: Simon Garnier Date: Mon, 12 Sep 2022 09:46:04 -0400 Subject: [PATCH] Document polarToCart and cartToPolar. Update NEWS. --- NEWS.md | 17 +++ R/arithmetic.R | 110 +++++++++++++++++- docs/news/index.html | 16 +++ docs/pkgdown.yml | 2 +- docs/reference/cartToPolar.html | 199 ++++++++++++++++++++++++++++++++ docs/reference/convexHull.html | 2 +- docs/reference/fitEllipse.html | 8 +- docs/reference/index.html | 8 ++ docs/reference/minAreaRect.html | 8 +- docs/reference/polarToCart.html | 199 ++++++++++++++++++++++++++++++++ docs/sitemap.xml | 6 + man/cartToPolar.Rd | 64 ++++++++++ man/polarToCart.Rd | 64 ++++++++++ 13 files changed, 687 insertions(+), 16 deletions(-) create mode 100644 docs/reference/cartToPolar.html create mode 100644 docs/reference/polarToCart.html create mode 100644 man/cartToPolar.Rd create mode 100644 man/polarToCart.Rd diff --git a/NEWS.md b/NEWS.md index 0bff1604..acdbeba7 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,20 @@ +# Rvision 0.6.3 + +## New features + +* Some Hu moment invariants were missing. +* OpenCV DLLs are now copied from ROpenCVLite on installation on Windows. +* New functions to compute square root, logarithm, exponential, and powers. +* New function to compute Gabor kernels for image filtering. +* New function to convert vector fields to polar coordinates and back. + +## Minor improvements and fixes + +* The documentation has been fixed/improved in several places. +* Minor bug fixes here and there. + +--- + # Rvision 0.6.2 ## New features diff --git a/R/arithmetic.R b/R/arithmetic.R index f9195a71..0138260c 100755 --- a/R/arithmetic.R +++ b/R/arithmetic.R @@ -171,14 +171,63 @@ addWeighted <- function(e1, e2, weight = c(0.5, 0.5), target = "new") { } +#' @title Convert Cartesian Coordinates to Polar +#' +#' @description \code{cartToPolar} converts the x and y coordinates of a vector +#' field (for instance, as generated by \code{\link{spatialGradient}}) and +#' computes their polar representation (magnitude and angle). +#' +#' @param x A 32- or 64-bit (32F or 64F) \code{\link{Image}} object +#' corresponding to the x coordinates of the vector field. +#' +#' @param y A 32- or 64-bit (32F or 64F) \code{\link{Image}} object +#' corresponding to the y coordinates of the vector field. +#' +#' @param magnitude The location where the magnitude should be stored. It can +#' take 2 values: +#' \itemize{ +#' \item{"new":}{a new \code{\link{Image}} object is created and the results +#' are stored inside (the default).} +#' \item{An \code{\link{Image}} object:}{the results are stored in another +#' existing \code{\link{Image}} object. Note that an error will be thrown if +#' \code{magnitude} does not have the same dimensions, number of channels, +#' and bit depth as \code{x} and \code{y}.} +#' } +#' +#' @param angle The location where the angle should be stored. It can take 2 +#' values: +#' \itemize{ +#' \item{"new":}{a new \code{\link{Image}} object is created and the results +#' are stored inside (the default).} +#' \item{An \code{\link{Image}} object:}{the results are stored in another +#' existing \code{\link{Image}} object. Note that an error will be thrown if +#' \code{angle} does not have the same dimensions, number of channels, +#' and bit depth as \code{x} and \code{y}.} +#' } +#' +#' @param degree A logical indicating whether the angles are measured in radians +#' (the default) or degrees. +#' +#' @return If \code{magnitude="new"} and \code{angle="new"}, the function returns +#' a list containing two \code{\link{Image}} objects. If \code{magnitude} and +#' \code{angle} are \code{\link{Image}} objects, the function returns nothing +#' and modifies these \code{\link{Image}} objects in place. +#' +#' @author Simon Garnier, \email{garnier@@njit.edu} +#' +#' @seealso \code{\link{polarToCart}}, \code{\link{spatialGradient}} +#' +#' @examples +#' balloon <- image(system.file("sample_img/balloon1.png", package = "Rvision")) +#' field <- spatialGradient(balloon) +#' lapply(field, changeBitDepth, bitdepth = "32F", target = "self") +#' field_converted <- cartToPolar(field$dx, field$dy) +#' #' @export cartToPolar <- function(x, y, magnitude = "new", angle = "new", degree = FALSE) { if (!isImage(x) | !isImage(y)) stop("x and y must be Image objects.") - if (x$nchan() != 1 | y$nchan() != 1) - stop("x and y must be single-channel Image objects.") - if (x$depth() != "32F" & x$depth() != "64F") stop("x must be a 32F or 64F image object.") @@ -219,14 +268,63 @@ cartToPolar <- function(x, y, magnitude = "new", angle = "new", degree = FALSE) } +#' @title Convert Polar Coordinates to Cartesian +#' +#' @description \code{polarToCart} calculates x and y coordinates of vector +#' field from their polar representation (magnitude and angle). +#' +#' @param magnitude A 32- or 64-bit (32F or 64F) \code{\link{Image}} +#' object corresponding to the magnitudes of the vector field. +#' +#' @param angle A 32- or 64-bit (32F or 64F) \code{\link{Image}} +#' object corresponding to the angles of the vector field. +#' +#' @param x The location where the x coordinates should be stored. It can take 2 +#' values: +#' \itemize{ +#' \item{"new":}{a new \code{\link{Image}} object is created and the results +#' are stored inside (the default).} +#' \item{An \code{\link{Image}} object:}{the results are stored in another +#' existing \code{\link{Image}} object. Note that an error will be thrown if +#' \code{x} does not have the same dimensions, number of channels, and bit +#' depth as \code{magnitude} and \code{angle}.} +#' } +#' +#' @param y The location where the y coordinates should be stored. It can take 2 +#' values: +#' \itemize{ +#' \item{"new":}{a new \code{\link{Image}} object is created and the results +#' are stored inside (the default).} +#' \item{An \code{\link{Image}} object:}{the results are stored in another +#' existing \code{\link{Image}} object. Note that an error will be thrown if +#' \code{y} does not have the same dimensions, number of channels, and bit +#' depth as \code{magnitude} and \code{angle}.} +#' } +#' +#' @param degree A logical indicating whether the angles are measured in radians +#' (the default) or degrees. +#' +#' @return If \code{x="new"} and \code{y="new"}, the function returns a list +#' containing two \code{\link{Image}} objects. If \code{x} and \code{y} are +#' \code{\link{Image}} objects, the function returns nothing and modifies these +#' \code{\link{Image}} objects in place. +#' +#' @author Simon Garnier, \email{garnier@@njit.edu} +#' +#' @seealso \code{\link{polarToCart}}, \code{\link{spatialGradient}} +#' +#' @examples +#' balloon <- image(system.file("sample_img/balloon1.png", package = "Rvision")) +#' field <- spatialGradient(balloon) +#' lapply(field, changeBitDepth, bitdepth = "32F", target = "self") +#' field_converted <- cartToPolar(field$dx, field$dy) +#' field_deconverted <- polarToCart(field_converted$magnitude, field_converted$angle) +#' #' @export polarToCart <- function(magnitude, angle, x = "new", y = "new", degree = FALSE) { if (!isImage(magnitude) | !isImage(angle)) stop("magnitude and angle must be Image objects.") - if (magnitude$nchan() != 1 | angle$nchan() != 1) - stop("magnitude and angle must be single-channel Image objects.") - if (magnitude$depth() != "32F" & magnitude$depth() != "64F") stop("magnitude must be a 32F or 64F image object.") diff --git a/docs/news/index.html b/docs/news/index.html index 1808adcb..60f2e9c6 100755 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -77,6 +77,22 @@

Changelog

Source: NEWS.md +
+ +
+

New features

+
  • Some Hu moment invariants were missing.
  • +
  • OpenCV DLLs are now copied from ROpenCVLite on installation on Windows.
  • +
  • New functions to compute square root, logarithm, exponential, and powers.
  • +
  • New function to compute Gabor kernels for image filtering.
  • +
  • New function to convert vector fields to polar coordinates and back.
  • +
+
+

Minor improvements and fixes

+
  • The documentation has been fixed/improved in several places.
  • +
  • Minor bug fixes here and there.
  • +

+
diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 51157746..cde294b7 100755 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -8,7 +8,7 @@ articles: z4_inplace: z4_inplace.html z5_gpu: z5_gpu.html z6_queue: z6_queue.html -last_built: 2022-09-12T12:43Z +last_built: 2022-09-12T13:43Z urls: reference: https://swarm-lab.github.io/ROpenCVLite/reference article: https://swarm-lab.github.io/ROpenCVLite/articles diff --git a/docs/reference/cartToPolar.html b/docs/reference/cartToPolar.html new file mode 100644 index 00000000..3ceb7319 --- /dev/null +++ b/docs/reference/cartToPolar.html @@ -0,0 +1,199 @@ + +Convert Cartesian Coordinates to Polar — cartToPolar • Rvision + + +
+
+ + + +
+
+ + +
+

cartToPolar converts the x and y coordinates of a vector + field (for instance, as generated by spatialGradient) and + computes their polar representation (magnitude and angle).

+
+ +
+
cartToPolar(x, y, magnitude = "new", angle = "new", degree = FALSE)
+
+ +
+

Arguments

+
x
+

A 32- or 64-bit (32F or 64F) Image object +corresponding to the x coordinates of the vector field.

+ + +
y
+

A 32- or 64-bit (32F or 64F) Image object +corresponding to the y coordinates of the vector field.

+ + +
magnitude
+

The location where the magnitude should be stored. It can +take 2 values:

  • "new":a new Image object is created and the results + are stored inside (the default).

  • +
  • An Image object:the results are stored in another + existing Image object. Note that an error will be thrown if + magnitude does not have the same dimensions, number of channels, + and bit depth as x and y.

  • +
+ + +
angle
+

The location where the angle should be stored. It can take 2 +values:

  • "new":a new Image object is created and the results + are stored inside (the default).

  • +
  • An Image object:the results are stored in another + existing Image object. Note that an error will be thrown if + angle does not have the same dimensions, number of channels, + and bit depth as x and y.

  • +
+ + +
degree
+

A logical indicating whether the angles are measured in radians +(the default) or degrees.

+ +
+
+

Value

+ + +

If magnitude="new" and angle="new", the function returns + a list containing two Image objects. If magnitude and

+

+

angle are Image objects, the function returns nothing + and modifies these Image objects in place.

+
+
+

See also

+ +
+
+

Author

+

Simon Garnier, garnier@njit.edu

+
+ +
+

Examples

+
balloon <- image(system.file("sample_img/balloon1.png", package = "Rvision"))
+field <- spatialGradient(balloon)
+lapply(field, changeBitDepth, bitdepth = "32F", target = "self")
+#> $dx
+#> NULL
+#> 
+#> $dy
+#> NULL
+#> 
+field_converted <- cartToPolar(field$dx, field$dy)
+
+
+
+
+ +
+ + +
+ + + + diff --git a/docs/reference/convexHull.html b/docs/reference/convexHull.html index 225bc052..ab04d9ce 100755 --- a/docs/reference/convexHull.html +++ b/docs/reference/convexHull.html @@ -117,7 +117,7 @@

Author

Examples

convexHull(rnorm(100), rnorm(100))
-#>  [1] 53 69 57 43 39 44 51 71 19 62
+#> [1] 55 93 26 92 60 84  8 46  9
 
 
diff --git a/docs/reference/fitEllipse.html b/docs/reference/fitEllipse.html index ae9f5674..cd1ac7d6 100755 --- a/docs/reference/fitEllipse.html +++ b/docs/reference/fitEllipse.html @@ -138,16 +138,16 @@

Author

Examples

fitEllipse(rnorm(100), rnorm(100))
 #> $angle
-#> [1] 21.42243
+#> [1] 125.4933
 #> 
 #> $height
-#> [1] 4.132697
+#> [1] 4.964257
 #> 
 #> $width
-#> [1] 3.300217
+#> [1] 3.469742
 #> 
 #> $center
-#> [1] 0.05263774 0.03447743
+#> [1] 0.5572369 0.1967185
 #> 
 
 
diff --git a/docs/reference/index.html b/docs/reference/index.html index c6a99cb3..6d54b855 100755 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -164,6 +164,10 @@

All functions capacity()

Capacity of a Queue

+ +

cartToPolar()

+ +

Convert Cartesian Coordinates to Polar

cc_table

@@ -540,6 +544,10 @@

All functions plotOF()

Plot Optical Flow Arrays

+ +

polarToCart()

+ +

Convert Polar Coordinates to Cartesian

pset()

diff --git a/docs/reference/minAreaRect.html b/docs/reference/minAreaRect.html index 106dd8e8..ca74ea13 100755 --- a/docs/reference/minAreaRect.html +++ b/docs/reference/minAreaRect.html @@ -119,16 +119,16 @@

Author

Examples

minAreaRect(rnorm(100), rnorm(100))
 #> $angle
-#> [1] 60.10006
+#> [1] 44.36209
 #> 
 #> $height
-#> [1] 5.224181
+#> [1] 4.222581
 #> 
 #> $width
-#> [1] 5.027547
+#> [1] 4.798254
 #> 
 #> $center
-#> [1]  0.4003776 -0.1817951
+#> [1]  0.23615944 -0.03735304
 #> 
 
 
diff --git a/docs/reference/polarToCart.html b/docs/reference/polarToCart.html new file mode 100644 index 00000000..5ab56c92 --- /dev/null +++ b/docs/reference/polarToCart.html @@ -0,0 +1,199 @@ + +Convert Polar Coordinates to Cartesian — polarToCart • Rvision + + +
+
+ + + +
+
+ + +
+

polarToCart calculates x and y coordinates of vector + field from their polar representation (magnitude and angle).

+
+ +
+
polarToCart(magnitude, angle, x = "new", y = "new", degree = FALSE)
+
+ +
+

Arguments

+
magnitude
+

A 32- or 64-bit (32F or 64F) Image +object corresponding to the magnitudes of the vector field.

+ + +
angle
+

A 32- or 64-bit (32F or 64F) Image +object corresponding to the angles of the vector field.

+ + +
x
+

The location where the x coordinates should be stored. It can take 2 +values:

  • "new":a new Image object is created and the results + are stored inside (the default).

  • +
  • An Image object:the results are stored in another + existing Image object. Note that an error will be thrown if + x does not have the same dimensions, number of channels, and bit + depth as magnitude and angle.

  • +
+ + +
y
+

The location where the y coordinates should be stored. It can take 2 +values:

  • "new":a new Image object is created and the results + are stored inside (the default).

  • +
  • An Image object:the results are stored in another + existing Image object. Note that an error will be thrown if + y does not have the same dimensions, number of channels, and bit + depth as magnitude and angle.

  • +
+ + +
degree
+

A logical indicating whether the angles are measured in radians +(the default) or degrees.

+ +
+
+

Value

+ + +

If x="new" and y="new", the function returns a list + containing two Image objects. If x and y are

+

+

Image objects, the function returns nothing and modifies these

+

+

Image objects in place.

+
+
+

See also

+

polarToCart, spatialGradient

+
+
+

Author

+

Simon Garnier, garnier@njit.edu

+
+ +
+

Examples

+
balloon <- image(system.file("sample_img/balloon1.png", package = "Rvision"))
+field <- spatialGradient(balloon)
+lapply(field, changeBitDepth, bitdepth = "32F", target = "self")
+#> $dx
+#> NULL
+#> 
+#> $dy
+#> NULL
+#> 
+field_converted <- cartToPolar(field$dx, field$dy)
+field_deconverted <- polarToCart(field_converted$magnitude, field_converted$angle)
+
+
+
+
+ +
+ + +
+ + + + diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 5a53403b..dd934721 100755 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -129,6 +129,9 @@ https://swarm-lab.github.io/ROpenCVLite/reference/capacity.html + + https://swarm-lab.github.io/ROpenCVLite/reference/cartToPolar.html + https://swarm-lab.github.io/ROpenCVLite/reference/cc_table.html @@ -423,6 +426,9 @@ https://swarm-lab.github.io/ROpenCVLite/reference/plotOF.html + + https://swarm-lab.github.io/ROpenCVLite/reference/polarToCart.html + https://swarm-lab.github.io/ROpenCVLite/reference/pset.html diff --git a/man/cartToPolar.Rd b/man/cartToPolar.Rd new file mode 100644 index 00000000..6edb839e --- /dev/null +++ b/man/cartToPolar.Rd @@ -0,0 +1,64 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/arithmetic.R +\name{cartToPolar} +\alias{cartToPolar} +\title{Convert Cartesian Coordinates to Polar} +\usage{ +cartToPolar(x, y, magnitude = "new", angle = "new", degree = FALSE) +} +\arguments{ +\item{x}{A 32- or 64-bit (32F or 64F) \code{\link{Image}} object +corresponding to the x coordinates of the vector field.} + +\item{y}{A 32- or 64-bit (32F or 64F) \code{\link{Image}} object +corresponding to the y coordinates of the vector field.} + +\item{magnitude}{The location where the magnitude should be stored. It can +take 2 values: +\itemize{ + \item{"new":}{a new \code{\link{Image}} object is created and the results + are stored inside (the default).} + \item{An \code{\link{Image}} object:}{the results are stored in another + existing \code{\link{Image}} object. Note that an error will be thrown if + \code{magnitude} does not have the same dimensions, number of channels, + and bit depth as \code{x} and \code{y}.} +}} + +\item{angle}{The location where the angle should be stored. It can take 2 +values: +\itemize{ + \item{"new":}{a new \code{\link{Image}} object is created and the results + are stored inside (the default).} + \item{An \code{\link{Image}} object:}{the results are stored in another + existing \code{\link{Image}} object. Note that an error will be thrown if + \code{angle} does not have the same dimensions, number of channels, + and bit depth as \code{x} and \code{y}.} +}} + +\item{degree}{A logical indicating whether the angles are measured in radians +(the default) or degrees.} +} +\value{ +If \code{magnitude="new"} and \code{angle="new"}, the function returns + a list containing two \code{\link{Image}} objects. If \code{magnitude} and + \code{angle} are \code{\link{Image}} objects, the function returns nothing + and modifies these \code{\link{Image}} objects in place. +} +\description{ +\code{cartToPolar} converts the x and y coordinates of a vector + field (for instance, as generated by \code{\link{spatialGradient}}) and + computes their polar representation (magnitude and angle). +} +\examples{ +balloon <- image(system.file("sample_img/balloon1.png", package = "Rvision")) +field <- spatialGradient(balloon) +lapply(field, changeBitDepth, bitdepth = "32F", target = "self") +field_converted <- cartToPolar(field$dx, field$dy) + +} +\seealso{ +\code{\link{polarToCart}}, \code{\link{spatialGradient}} +} +\author{ +Simon Garnier, \email{garnier@njit.edu} +} diff --git a/man/polarToCart.Rd b/man/polarToCart.Rd new file mode 100644 index 00000000..a8f415f5 --- /dev/null +++ b/man/polarToCart.Rd @@ -0,0 +1,64 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/arithmetic.R +\name{polarToCart} +\alias{polarToCart} +\title{Convert Polar Coordinates to Cartesian} +\usage{ +polarToCart(magnitude, angle, x = "new", y = "new", degree = FALSE) +} +\arguments{ +\item{magnitude}{A 32- or 64-bit (32F or 64F) \code{\link{Image}} +object corresponding to the magnitudes of the vector field.} + +\item{angle}{A 32- or 64-bit (32F or 64F) \code{\link{Image}} +object corresponding to the angles of the vector field.} + +\item{x}{The location where the x coordinates should be stored. It can take 2 +values: +\itemize{ + \item{"new":}{a new \code{\link{Image}} object is created and the results + are stored inside (the default).} + \item{An \code{\link{Image}} object:}{the results are stored in another + existing \code{\link{Image}} object. Note that an error will be thrown if + \code{x} does not have the same dimensions, number of channels, and bit + depth as \code{magnitude} and \code{angle}.} +}} + +\item{y}{The location where the y coordinates should be stored. It can take 2 +values: +\itemize{ + \item{"new":}{a new \code{\link{Image}} object is created and the results + are stored inside (the default).} + \item{An \code{\link{Image}} object:}{the results are stored in another + existing \code{\link{Image}} object. Note that an error will be thrown if + \code{y} does not have the same dimensions, number of channels, and bit + depth as \code{magnitude} and \code{angle}.} +}} + +\item{degree}{A logical indicating whether the angles are measured in radians +(the default) or degrees.} +} +\value{ +If \code{x="new"} and \code{y="new"}, the function returns a list + containing two \code{\link{Image}} objects. If \code{x} and \code{y} are + \code{\link{Image}} objects, the function returns nothing and modifies these + \code{\link{Image}} objects in place. +} +\description{ +\code{polarToCart} calculates x and y coordinates of vector + field from their polar representation (magnitude and angle). +} +\examples{ +balloon <- image(system.file("sample_img/balloon1.png", package = "Rvision")) +field <- spatialGradient(balloon) +lapply(field, changeBitDepth, bitdepth = "32F", target = "self") +field_converted <- cartToPolar(field$dx, field$dy) +field_deconverted <- polarToCart(field_converted$magnitude, field_converted$angle) + +} +\seealso{ +\code{\link{polarToCart}}, \code{\link{spatialGradient}} +} +\author{ +Simon Garnier, \email{garnier@njit.edu} +}