summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomas Farago <sensej007@email.cz>2019-12-11 16:05:10 +0100
committerTomas Farago <sensej007@email.cz>2020-02-05 10:33:57 +0100
commitfd1dbaaab5bb182c2fc660992449fee954bc35b3 (patch)
tree6b9dfd0aeb74c0dd159fe902329b7484d540f1c5
parent613273cbf1cbf681d19d4649c86b593aea7f2df3 (diff)
downloadufo-filters-fd1dbaaab5bb182c2fc660992449fee954bc35b3.tar.gz
ufo-filters-fd1dbaaab5bb182c2fc660992449fee954bc35b3.tar.bz2
ufo-filters-fd1dbaaab5bb182c2fc660992449fee954bc35b3.tar.xz
ufo-filters-fd1dbaaab5bb182c2fc660992449fee954bc35b3.zip
find-large-spots: add spot-threshold-mode property
which enables users to choose if pixels below or above the threshold should be selected, or if the absolute value of the pixel should be taken for comparison.
-rw-r--r--src/kernels/morphology.cl18
-rw-r--r--src/ufo-find-large-spots-task.c33
2 files changed, 46 insertions, 5 deletions
diff --git a/src/kernels/morphology.cl b/src/kernels/morphology.cl
index 2f0c38d..af76b58 100644
--- a/src/kernels/morphology.cl
+++ b/src/kernels/morphology.cl
@@ -17,14 +17,26 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * Set mask to 1 if value exceeds threshold. If sgn is -1, value has to be below
+ * threshold, if it is 1 it has to be above threshold, if it is 0 absolute value
+ * is compared.
+ */
kernel void
-set_abs_above_threshold (global float *input,
+set_above_threshold (global float *input,
global float *output,
- const float threshold)
+ const float threshold,
+ const int sgn)
{
int index = get_global_id (1) * get_global_size (0) + get_global_id (0);
+ float value = input[index];
+ if (!sgn) {
+ value = fabs (value) - threshold;
+ } else {
+ value = sgn * (value - threshold);
+ }
- output[index] = fabs (input[index]) > threshold ? 1 : 0;
+ output[index] = value > 0 ? 1 : 0;
}
kernel void
diff --git a/src/ufo-find-large-spots-task.c b/src/ufo-find-large-spots-task.c
index d9b055a..9875ffc 100644
--- a/src/ufo-find-large-spots-task.c
+++ b/src/ufo-find-large-spots-task.c
@@ -27,9 +27,22 @@
#include "common/ufo-addressing.h"
#include "common/ufo-common.h"
+typedef enum {
+ SPOT_THRESHOLD_BELOW = -1,
+ SPOT_THRESHOLD_ABSOLUTE,
+ SPOT_THRESHOLD_ABOVE
+} SpotThresholdMode;
+
+static GEnumValue spot_threshold_mode_values[] = {
+ { SPOT_THRESHOLD_BELOW, "SPOT_THRESHOLD_BELOW", "below" },
+ { SPOT_THRESHOLD_ABSOLUTE, "SPOT_THRESHOLD_ABSOLUTE", "absolute" },
+ { SPOT_THRESHOLD_ABOVE, "SPOT_THRESHOLD_ABOVE", "above" },
+ { 0, NULL, NULL}
+};
struct _UfoFindLargeSpotsTaskPrivate {
gfloat spot_threshold;
+ SpotThresholdMode spot_threshold_mode;
gfloat grow_threshold;
cl_context context;
cl_kernel set_ones_kernel, set_threshold_kernel, grow_kernel, holes_kernel, convolution_kernel, sum_kernel;
@@ -48,6 +61,7 @@ G_DEFINE_TYPE_WITH_CODE (UfoFindLargeSpotsTask, ufo_find_large_spots_task, UFO_T
enum {
PROP_0,
+ PROP_SPOT_THRESHOLD_MODE,
PROP_SPOT_THRESHOLD,
PROP_GROW_THRESHOLD,
PROP_ADDRESSING_MODE,
@@ -74,7 +88,7 @@ ufo_find_large_spots_task_setup (UfoTask *task,
UFO_RESOURCES_CHECK_SET_AND_RETURN (clRetainContext (priv->context), error);
priv->set_ones_kernel = ufo_resources_get_kernel (resources, "morphology.cl", "set_to_ones", NULL, error);
- priv->set_threshold_kernel = ufo_resources_get_kernel (resources, "morphology.cl", "set_abs_above_threshold", NULL, error);
+ priv->set_threshold_kernel = ufo_resources_get_kernel (resources, "morphology.cl", "set_above_threshold", NULL, error);
priv->grow_kernel = ufo_resources_get_kernel (resources, "morphology.cl", "grow_region_above_threshold", NULL, error);
priv->holes_kernel = ufo_resources_get_kernel (resources, "morphology.cl", "fill_holes", NULL, error);
priv->convolution_kernel = ufo_resources_get_kernel (resources, "estimate-noise.cl", "convolve_abs_laplacian_diff", NULL, error);
@@ -208,6 +222,7 @@ ufo_find_large_spots_task_process (UfoTask *task,
UFO_RESOURCES_CHECK_CLERR (clSetKernelArg (priv->set_threshold_kernel, 0, sizeof (cl_mem), &in_mem));
UFO_RESOURCES_CHECK_CLERR (clSetKernelArg (priv->set_threshold_kernel, 1, sizeof (cl_mem), &priv->aux_mem[0]));
UFO_RESOURCES_CHECK_CLERR (clSetKernelArg (priv->set_threshold_kernel, 2, sizeof (cl_int), &priv->spot_threshold));
+ UFO_RESOURCES_CHECK_CLERR (clSetKernelArg (priv->set_threshold_kernel, 3, sizeof (cl_int), &priv->spot_threshold_mode));
ufo_profiler_call (profiler, cmd_queue, priv->set_threshold_kernel, 2, requisition->dims, NULL);
UFO_RESOURCES_CHECK_CLERR (clEnqueueCopyBuffer (cmd_queue,
priv->aux_mem[0],
@@ -302,6 +317,9 @@ ufo_find_large_spots_task_set_property (GObject *object,
case PROP_SPOT_THRESHOLD:
priv->spot_threshold = g_value_get_float (value);
break;
+ case PROP_SPOT_THRESHOLD_MODE:
+ priv->spot_threshold_mode = g_value_get_enum (value);
+ break;
case PROP_GROW_THRESHOLD:
priv->grow_threshold = g_value_get_float (value);
break;
@@ -326,6 +344,9 @@ ufo_find_large_spots_task_get_property (GObject *object,
case PROP_SPOT_THRESHOLD:
g_value_set_float (value, priv->spot_threshold);
break;
+ case PROP_SPOT_THRESHOLD_MODE:
+ g_value_set_enum (value, priv->spot_threshold_mode);
+ break;
case PROP_GROW_THRESHOLD:
g_value_set_float (value, priv->grow_threshold);
break;
@@ -413,9 +434,16 @@ ufo_find_large_spots_task_class_init (UfoFindLargeSpotsTaskClass *klass)
g_param_spec_float ("spot-threshold",
"Pixels with grey value larger than this are considered as spots",
"Pixels with grey value larger than this are considered as spots",
- 0.0f, G_MAXFLOAT, 0.0f,
+ -G_MAXFLOAT, G_MAXFLOAT, 0.0f,
G_PARAM_READWRITE);
+ properties[PROP_SPOT_THRESHOLD_MODE] =
+ g_param_spec_enum ("spot-threshold-mode",
+ "Pixels must be either \"below\", \"above\" the spot threshold, or their \"absolute\" value can be compared",
+ "Pixels must be either \"below\", \"above\" the spot threshold, or their \"absolute\" value can be compared",
+ g_enum_register_static ("spot-threshold-mode", spot_threshold_mode_values),
+ SPOT_THRESHOLD_ABSOLUTE, G_PARAM_READWRITE);
+
properties[PROP_GROW_THRESHOLD] =
g_param_spec_float ("grow-threshold",
"Spot growing threshold",
@@ -443,5 +471,6 @@ ufo_find_large_spots_task_init(UfoFindLargeSpotsTask *self)
self->priv = UFO_FIND_LARGE_SPOTS_TASK_GET_PRIVATE(self);
self->priv->spot_threshold = 0.0f;
self->priv->grow_threshold = 0.0f;
+ self->priv->spot_threshold_mode = SPOT_THRESHOLD_ABSOLUTE;
self->priv->addressing_mode = CL_ADDRESS_MIRRORED_REPEAT;
}