summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2018-03-22 11:20:58 +0100
committerMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2018-03-22 11:20:58 +0100
commit4aeee141dfb2094f4cf82ea564693897593a7cd2 (patch)
treea40b5d2a3ccf9f1d55bb7592af243f25c07ebcbc
parent421003292bf3148581224cfa746a2faaab70af53 (diff)
downloadufo-filters-4aeee141dfb2094f4cf82ea564693897593a7cd2.tar.gz
ufo-filters-4aeee141dfb2094f4cf82ea564693897593a7cd2.tar.bz2
ufo-filters-4aeee141dfb2094f4cf82ea564693897593a7cd2.tar.xz
ufo-filters-4aeee141dfb2094f4cf82ea564693897593a7cd2.zip
Add unsplit task
-rw-r--r--docs/filters.rst14
-rw-r--r--src/kernels/meson.build1
-rw-r--r--src/kernels/split.cl32
-rw-r--r--src/meson.build1
-rw-r--r--src/ufo-unsplit-task.c165
-rw-r--r--src/ufo-unsplit-task.h53
6 files changed, 266 insertions, 0 deletions
diff --git a/docs/filters.rst b/docs/filters.rst
index 3a2765d..f1ad494 100644
--- a/docs/filters.rst
+++ b/docs/filters.rst
@@ -658,6 +658,20 @@ Color mapping
green and blue color channels using the Viridis color map.
+Splitting channels
+------------------
+
+.. gobj:class:: unsplit
+
+ Turns a three-dimensional image into two-dimensional image by interleaving
+ the third dimension, i.e. [[[XXX],[YYY],[ZZZ]]] is turned into
+ [[XYZ],[XYZ],[XYZ]]. This is useful to merge a separate multi-channel RGB
+ image into a "regular" RGB image that can be shown with ``cv-show``.
+
+ This task adds the ``channels`` key to the output buffer containing the
+ original depth of the input buffer.
+
+
Fourier domain
==============
diff --git a/src/kernels/meson.build b/src/kernels/meson.build
index bb88681..542b5bb 100644
--- a/src/kernels/meson.build
+++ b/src/kernels/meson.build
@@ -35,6 +35,7 @@ kernel_files = [
'rm-outliers.cl',
'rotate.cl',
'segment.cl',
+ 'split.cl',
'swap-quadrants.cl',
'transpose.cl',
'zeropad.cl'
diff --git a/src/kernels/split.cl b/src/kernels/split.cl
new file mode 100644
index 0000000..5a9bb07
--- /dev/null
+++ b/src/kernels/split.cl
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2011-2018 Karlsruhe Institute of Technology
+ *
+ * This file is part of Ufo.
+ *
+ * This library is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+kernel void
+unsplit (global float *input,
+ global float *output)
+{
+ size_t idx = get_global_id (0);
+ size_t idy = get_global_id (1);
+ size_t idz = get_global_id (2);
+ size_t width = get_global_size (0);
+ size_t height = get_global_size (1);
+ size_t depth = get_global_size (2);
+
+ output[idy * width * depth + idx * depth + idz] = input[idz * width * height + idy * width + idx];
+}
diff --git a/src/meson.build b/src/meson.build
index cc7a5a4..34f5934 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -70,6 +70,7 @@ plugins = [
'transpose-projections',
'swap-quadrants',
'subtract',
+ 'unsplit',
'volume-render',
'zeropad',
]
diff --git a/src/ufo-unsplit-task.c b/src/ufo-unsplit-task.c
new file mode 100644
index 0000000..05cd9c4
--- /dev/null
+++ b/src/ufo-unsplit-task.c
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2011-2015 Karlsruhe Institute of Technology
+ *
+ * This file is part of Ufo.
+ *
+ * This library is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef __APPLE__
+#include <OpenCL/cl.h>
+#else
+#include <CL/cl.h>
+#endif
+
+#include "ufo-unsplit-task.h"
+
+
+struct _UfoUnsplitTaskPrivate {
+ cl_kernel kernel;
+};
+
+static void ufo_task_interface_init (UfoTaskIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (UfoUnsplitTask, ufo_unsplit_task, UFO_TYPE_TASK_NODE,
+ G_IMPLEMENT_INTERFACE (UFO_TYPE_TASK,
+ ufo_task_interface_init))
+
+#define UFO_UNSPLIT_TASK_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), UFO_TYPE_UNSPLIT_TASK, UfoUnsplitTaskPrivate))
+
+UfoNode *
+ufo_unsplit_task_new (void)
+{
+ return UFO_NODE (g_object_new (UFO_TYPE_UNSPLIT_TASK, NULL));
+}
+
+static void
+ufo_unsplit_task_setup (UfoTask *task,
+ UfoResources *resources,
+ GError **error)
+{
+ UfoUnsplitTaskPrivate *priv;
+
+ priv = UFO_UNSPLIT_TASK_GET_PRIVATE (task);
+ priv->kernel = ufo_resources_get_kernel (resources, "split.cl", "unsplit", error);
+
+ if (priv->kernel != NULL)
+ UFO_RESOURCES_CHECK_CLERR (clRetainKernel (priv->kernel));
+}
+
+static void
+ufo_unsplit_task_get_requisition (UfoTask *task,
+ UfoBuffer **inputs,
+ UfoRequisition *requisition)
+{
+ ufo_buffer_get_requisition (inputs[0], requisition);
+ requisition->n_dims = 2;
+ requisition->dims[0] *= requisition->dims[2];
+}
+
+static guint
+ufo_unsplit_task_get_num_inputs (UfoTask *task)
+{
+ return 1;
+}
+
+static guint
+ufo_unsplit_task_get_num_dimensions (UfoTask *task,
+ guint input)
+{
+ return 3;
+}
+
+static UfoTaskMode
+ufo_unsplit_task_get_mode (UfoTask *task)
+{
+ return UFO_TASK_MODE_PROCESSOR | UFO_TASK_MODE_GPU;
+}
+
+static gboolean
+ufo_unsplit_task_process (UfoTask *task,
+ UfoBuffer **inputs,
+ UfoBuffer *output,
+ UfoRequisition *requisition)
+{
+ UfoUnsplitTaskPrivate *priv;
+ UfoGpuNode *node;
+ UfoProfiler *profiler;
+ UfoRequisition in_req;
+ cl_command_queue cmd_queue;
+ cl_mem in_mem;
+ cl_mem out_mem;
+ GValue channels = {0,};
+
+ priv = UFO_UNSPLIT_TASK_GET_PRIVATE (task);
+ node = UFO_GPU_NODE (ufo_task_node_get_proc_node (UFO_TASK_NODE (task)));
+ cmd_queue = ufo_gpu_node_get_cmd_queue (node);
+ in_mem = ufo_buffer_get_device_array (inputs[0], cmd_queue);
+ out_mem = ufo_buffer_get_device_array (output, cmd_queue);
+
+ UFO_RESOURCES_CHECK_CLERR (clSetKernelArg (priv->kernel, 0, sizeof (cl_mem), &in_mem));
+ UFO_RESOURCES_CHECK_CLERR (clSetKernelArg (priv->kernel, 1, sizeof (cl_mem), &out_mem));
+
+ ufo_buffer_get_requisition (inputs[0], &in_req);
+ profiler = ufo_task_node_get_profiler (UFO_TASK_NODE (task));
+ ufo_profiler_call (profiler, cmd_queue, priv->kernel, 3, in_req.dims, NULL);
+
+ g_value_init (&channels, G_TYPE_UINT);
+ g_value_set_uint (&channels, in_req.dims[2]);
+ ufo_buffer_set_metadata (output, "channels", &channels);
+
+ return TRUE;
+}
+
+static void
+ufo_unsplit_task_finalize (GObject *object)
+{
+ UfoUnsplitTaskPrivate *priv;
+
+ priv = UFO_UNSPLIT_TASK_GET_PRIVATE (object);
+
+ if (priv->kernel) {
+ UFO_RESOURCES_CHECK_CLERR (clReleaseKernel (priv->kernel));
+ priv->kernel = NULL;
+ }
+
+ G_OBJECT_CLASS (ufo_unsplit_task_parent_class)->finalize (object);
+}
+
+static void
+ufo_task_interface_init (UfoTaskIface *iface)
+{
+ iface->setup = ufo_unsplit_task_setup;
+ iface->get_num_inputs = ufo_unsplit_task_get_num_inputs;
+ iface->get_num_dimensions = ufo_unsplit_task_get_num_dimensions;
+ iface->get_mode = ufo_unsplit_task_get_mode;
+ iface->get_requisition = ufo_unsplit_task_get_requisition;
+ iface->process = ufo_unsplit_task_process;
+}
+
+static void
+ufo_unsplit_task_class_init (UfoUnsplitTaskClass *klass)
+{
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+
+ oclass->finalize = ufo_unsplit_task_finalize;
+
+ g_type_class_add_private (oclass, sizeof(UfoUnsplitTaskPrivate));
+}
+
+static void
+ufo_unsplit_task_init(UfoUnsplitTask *self)
+{
+ self->priv = UFO_UNSPLIT_TASK_GET_PRIVATE(self);
+}
diff --git a/src/ufo-unsplit-task.h b/src/ufo-unsplit-task.h
new file mode 100644
index 0000000..d15bc4b
--- /dev/null
+++ b/src/ufo-unsplit-task.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2011-2013 Karlsruhe Institute of Technology
+ *
+ * This file is part of Ufo.
+ *
+ * This library is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __UFO_UNSPLIT_TASK_H
+#define __UFO_UNSPLIT_TASK_H
+
+#include <ufo/ufo.h>
+
+G_BEGIN_DECLS
+
+#define UFO_TYPE_UNSPLIT_TASK (ufo_unsplit_task_get_type())
+#define UFO_UNSPLIT_TASK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), UFO_TYPE_UNSPLIT_TASK, UfoUnsplitTask))
+#define UFO_IS_UNSPLIT_TASK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), UFO_TYPE_UNSPLIT_TASK))
+#define UFO_UNSPLIT_TASK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), UFO_TYPE_UNSPLIT_TASK, UfoUnsplitTaskClass))
+#define UFO_IS_UNSPLIT_TASK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), UFO_TYPE_UNSPLIT_TASK))
+#define UFO_UNSPLIT_TASK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), UFO_TYPE_UNSPLIT_TASK, UfoUnsplitTaskClass))
+
+typedef struct _UfoUnsplitTask UfoUnsplitTask;
+typedef struct _UfoUnsplitTaskClass UfoUnsplitTaskClass;
+typedef struct _UfoUnsplitTaskPrivate UfoUnsplitTaskPrivate;
+
+struct _UfoUnsplitTask {
+ UfoTaskNode parent_instance;
+
+ UfoUnsplitTaskPrivate *priv;
+};
+
+struct _UfoUnsplitTaskClass {
+ UfoTaskNodeClass parent_class;
+};
+
+UfoNode *ufo_unsplit_task_new (void);
+GType ufo_unsplit_task_get_type (void);
+
+G_END_DECLS
+
+#endif