[arrayfire] 221/284: Added tranform coordinates functionality

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:35 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/experimental
in repository arrayfire.

commit 323bf75b44731c11eeee3c7ba866e6803bfab9b4
Author: Peter Andreas Entschev <peter at arrayfire.com>
Date:   Fri Jan 15 23:41:34 2016 -0500

    Added tranform coordinates functionality
---
 include/af/image.h                    | 25 +++++++++
 src/api/c/transform_coordinates.cpp   | 96 +++++++++++++++++++++++++++++++++++
 src/api/cpp/transform_coordinates.cpp | 24 +++++++++
 3 files changed, 145 insertions(+)

diff --git a/include/af/image.h b/include/af/image.h
index ad56cfc..d25f64f 100644
--- a/include/af/image.h
+++ b/include/af/image.h
@@ -224,6 +224,18 @@ AFAPI array rotate(const array& in, const float theta, const bool crop=true, con
 AFAPI array transform(const array& in, const array& transform, const dim_t odim0 = 0, const dim_t odim1 = 0, const interpType method=AF_INTERP_NEAREST, const bool inverse=true);
 
 /**
+    C++ Interface for transforming coordinates
+
+    \param[in] tf is transformation matrix
+    \param[in] d0 is the first input dimension
+    \param[in] d1 is the second input dimension
+    \return the transformed coordinates
+
+    \ingroup transform_func_coordinates
+*/
+AFAPI array transformCoordinates(const array& tf, const float d0, const float d1);
+
+/**
     C++ Interface for translating an image
 
     \param[in] in is input image
@@ -854,6 +866,19 @@ extern "C" {
                               const af_interp_type method, const bool inverse);
 
     /**
+       C Interface for transforming an image
+       C++ Interface for transforming coordinates
+
+       \param[out] out the transformed coordinates
+       \param[in] tf is transformation matrix
+       \param[in] d0 is the first input dimension
+       \param[in] d1 is the second input dimension
+
+       \ingroup transform_func_coordinates
+    */
+    AFAPI af_err af_transform_coordinates(af_array *out, const af_array tf, const float d0, const float d1);
+
+    /**
        C Interface for rotating an image
 
        \param[out] out will contain the image \p in rotated by \p theta
diff --git a/src/api/c/transform_coordinates.cpp b/src/api/c/transform_coordinates.cpp
new file mode 100644
index 0000000..79b448d
--- /dev/null
+++ b/src/api/c/transform_coordinates.cpp
@@ -0,0 +1,96 @@
+/*******************************************************
+ * Copyright (c) 2015, ArrayFire
+ * All rights reserved.
+ *
+ * This file is distributed under 3-clause BSD license.
+ * The complete license agreement can be obtained at:
+ * http://arrayfire.com/licenses/BSD-3-Clause
+ ********************************************************/
+
+#include <af/dim4.hpp>
+#include <af/defines.h>
+#include <af/vision.h>
+#include <af/image.h>
+#include <af/arith.h>
+#include <af/blas.h>
+#include <af/data.h>
+#include <err_common.hpp>
+#include <backend.hpp>
+#include <handle.hpp>
+#include <convolve.hpp>
+#include <arith.hpp>
+
+using af::dim4;
+using namespace detail;
+
+template<typename T>
+static af_array transform_coordinates(const af_array& tf, const float d0, const float d1)
+{
+    dim_t in_dims[2] = { 4, 3 };
+    T h_in[4*3] = { (T)0, (T)0,  (T)d1, (T)d1,
+                    (T)0, (T)d0, (T)d0, (T)0,
+                    (T)1, (T)1,  (T)1,  (T)1 };
+
+    af_array in  = 0;
+    af_array w   = 0;
+    af_array tmp = 0;
+    af_array xt  = 0;
+    af_array yt  = 0;
+    af_array t   = 0;
+
+    AF_CHECK(af_create_array(&in, h_in, 2, in_dims, (af_dtype) af::dtype_traits<T>::af_type));
+
+    af_array tfIdx = 0;
+    af_index_t tfIndexs[2];
+    tfIndexs[0].isSeq = true;
+    tfIndexs[1].isSeq = true;
+    tfIndexs[0].idx.seq = af_make_seq(0, 2, 1);
+    tfIndexs[1].idx.seq = af_make_seq(2, 2, 1);
+    AF_CHECK(af_index_gen(&tfIdx, tf, 2, tfIndexs));
+
+    AF_CHECK(af_matmul(&tmp, in, tfIdx, AF_MAT_NONE, AF_MAT_NONE));
+    T h_w[4] = { 1, 1, 1, 1 };
+    dim_t w_dims = 4;
+    AF_CHECK(af_create_array(&w, h_w, 1, &w_dims, (af_dtype) af::dtype_traits<T>::af_type));
+    AF_CHECK(af_div(&w, w, tmp, false));
+
+    tfIndexs[1].idx.seq = af_make_seq(0, 0, 1);
+    AF_CHECK(af_index_gen(&tfIdx, tf, 2, tfIndexs));
+    AF_CHECK(af_matmul(&tmp, in, tfIdx, AF_MAT_NONE, AF_MAT_NONE));
+    AF_CHECK(af_mul(&xt, tmp, w, false));
+
+    tfIndexs[1].idx.seq = af_make_seq(1, 1, 1);
+    AF_CHECK(af_index_gen(&tfIdx, tf, 2, tfIndexs));
+    AF_CHECK(af_matmul(&tmp, in, tfIdx, AF_MAT_NONE, AF_MAT_NONE));
+    AF_CHECK(af_mul(&yt, tmp, w, false));
+
+    AF_CHECK(af_join(&t, 1, xt, yt));
+
+    AF_CHECK(af_release_array(w));
+    AF_CHECK(af_release_array(tmp));
+    AF_CHECK(af_release_array(xt));
+    AF_CHECK(af_release_array(yt));
+
+    return t;
+}
+
+af_err af_transform_coordinates(af_array *out, const af_array tf, const float d0, const float d1)
+{
+    try {
+        ArrayInfo tfInfo = getInfo(tf);
+        dim4 tfDims = tfInfo.dims();
+        ARG_ASSERT(1, (tfDims[0]==3 && tfDims[1]==3 && tfDims.ndims()==2));
+
+        af_array output;
+        af_dtype type  = tfInfo.getType();
+        switch(type) {
+            case f32: output = transform_coordinates<float >(tf, d0, d1); break;
+            case f64: output = transform_coordinates<double>(tf, d0, d1); break;
+            default : TYPE_ERROR(1, type);
+        }
+        std::swap(*out, output);
+    }
+    CATCHALL;
+
+    return AF_SUCCESS;
+}
diff --git a/src/api/cpp/transform_coordinates.cpp b/src/api/cpp/transform_coordinates.cpp
new file mode 100644
index 0000000..4d896e7
--- /dev/null
+++ b/src/api/cpp/transform_coordinates.cpp
@@ -0,0 +1,24 @@
+/*******************************************************
+ * Copyright (c) 2014, ArrayFire
+ * All rights reserved.
+ *
+ * This file is distributed under 3-clause BSD license.
+ * The complete license agreement can be obtained at:
+ * http://arrayfire.com/licenses/BSD-3-Clause
+ ********************************************************/
+
+#include <af/image.h>
+#include <af/array.h>
+#include "error.hpp"
+
+namespace af
+{
+
+array transformCoordinates(const array& tf, const float d0, const float d1)
+{
+    af_array out = 0;
+    AF_THROW(af_transform_coordinates(&out, tf.get(), d0, d1));
+    return array(out);
+}
+
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git



More information about the debian-science-commits mailing list