diff --git a/README.md b/README.md index 65bdecc..6d3d34f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # clij-opencl-kernels -This repository contains a collection of [OpenCL](https://www.khronos.org/opencl/) [kernels for generic image -processing](https://github.com/clij/clij-opencl-kernels/tree/master/src/main/java/net/haesleinhuepf/clij/kernels). +This repository contains a collection of [OpenCL](https://www.khronos.org/opencl/) kernels for [image +processing](https://github.com/clij/clij-opencl-kernels/tree/development/src/main/java/net/haesleinhuepf/clij/kernels). The [CLIJ](https://clij.github.io) is build on top of it allowing [ImageJ](https://imagej.nih.gov/ij/) / [Fiji](https://fiji.sc) users in doing GPU-accelerated image processing without the need for learning OpenCL. @@ -11,7 +11,7 @@ GPU-accelerated image processing without the need for learning OpenCL. Robert Haase, Loic Alain Royer, Peter Steinbach, Deborah Schmidt, Alexandr Dibrov, Uwe Schmidt, Martin Weigert, Nicola Maghelli, Pavel Tomancak, Florian Jug, Eugene W Myers. -*CLIJ: GPU-accelerated image processing for everyone*. BioRxiv preprint. [https://doi.org/10.1101/660704](https://doi.org/10.1101/660704) +*CLIJ: GPU-accelerated image processing for everyone*. [Nat Methods (2019) doi:10.1038/s41592-019-0650-1](https://doi.org/10.1038/s41592-019-0650-1) ## Why a custom OpenCL-dialect? @@ -20,10 +20,10 @@ Theoretically, one has to write OpenCL-kernels specifically for given input- and adding images of type `float` resulting in a `float` image and a kernel for adding image of type `uint8` resulting in an image of type `float`. Furthermore, OpenCL defines images and buffers. However, as both are arrays of pixel intensities in memory, we wanted to access them in a unified way. As this would result in a ridiculous large number of individual kernel implementations, we used -a dialect where placeholders such as `DTYPE_OUT` represent the pixel type of the output image. +a dialect where placeholders such as `IMAGE_src_PIXEL_TYPE` represent the pixel type of the output image. ## List of placeholders -The following list of placeholders are used at the moment: +The following list of placeholders are used at the moment. The name `imagename` must contain `src` or `dst` to differentiate `readonly` and `writeonly` images. @@ -32,8 +32,8 @@ The following list of placeholders are used at the moment: - - + - - - - - - - - - + - + - - - - - - - - - - - + - - + - - - - + - + - + - + - + + + + + + + + + + + + - - - - - - + - - - - -
CONVERT_DTYPE_IN
+
CONVERT_imagename_PIXEL_TYPE
 clij_convert_char_sat
 clij_convert_uchar_sat
 clij_convert_short_sat
@@ -43,50 +43,14 @@ The following list of placeholders are used at the moment:
 clij_convert_float_sat
 
Convert any number to a given type.
CONVERT_DTYPE_OUT
DTYPE_IMAGE_IN_2D
-__read_only image2d_t
-__global char*
-__global uchar*
-__global short*
-__global ushort*
-__global float*
-
Two dimensional input image type definitionConvert any number to a given type.
DTYPE_IMAGE_IN_3D
IMAGE_imagename_TYPE
 __read_only image3d_t
-__global char*
-__global uchar*
-__global short*
-__global ushort*
-__global float*
-
Three dimensional input image type definition
DTYPE_IMAGE_OUT_2D
+__read_only image2d_t
 __write_only image2d_t
-__global char*
-__global uchar*
-__global short*
-__global ushort*
-__global float*
-
Two dimensional output image type definition
DTYPE_IMAGE_OUT_3D
 __write_only image3d_t
 __global char*
 __global uchar*
@@ -94,55 +58,57 @@ __global short*
 __global ushort*
 __global float*
 
Three dimensional output image type definitionTwo dimensional input image type definition.
DTYPE_IN
+
IMAGE_imagename_PIXEL_TYPE
 char
 uchar
 short
 ushort
 float
 
Pixel type definition
DTYPE_OUT
Pixel type definition
GET_IMAGE_DEPTH
GET_IMAGE_DEPTH(imagename)
constant number Image size in Z
GET_IMAGE_HEIGHT
GET_IMAGE_HEIGHT(imagename)
constant number Image size in Y
GET_IMAGE_WIDTH
GET_IMAGE_WIDTH(imagename)
constant number Image size in X
READ_IMAGE_2D
POS_imagename_TYPE
int2
int4
Type of coordinate
POS_imagename_INSTANCE(pos0,pos1,pos2,pos3)
int2(pos0, pos1)
int4(pos0,pos1,pos2,pos3)
instantiate variable of coordinate
READ_imagename_IMAGE
-read_imageui
-read_imagef
+read_imageui (2d)
+read_imagef (2d)
 read_buffer2dc
 read_buffer2duc
 read_buffer2di
 read_buffer2dui
 read_buffer2df
-
Read pixel intensity from a given position
READ_IMAGE_3D
-read_imageui
-read_imagef
+read_imageui (3d)
+read_imagef (3d)
 read_buffer3dc
 read_buffer3duc
 read_buffer3di
@@ -152,23 +118,17 @@ float
 
Read pixel intensity from a given position
WRITE_IMAGE_2D
WRITE_imagename_IMAGE
-write_imageui
-write_imagef
+write_imageui (2d)
+write_imagef (2d)
 write_buffer2dc
 write_buffer2duc
 write_buffer2di
 write_buffer2dui
 write_buffer2df
-
Write pixel intensity to a given position
WRITE_IMAGE_3D
-write_imageui
-write_imagef
+write_imageui (3d)
+write_imagef (3d)
 write_buffer3dc
 write_buffer3duc
 write_buffer3di
@@ -181,17 +141,5 @@ float
 
## Known issues -* The described OpenCL dialect has a drawback: Input images all need to be of the same type and output images have to be -of the same type. As this assumption might be violated in practice, we are working on an new version of the dialect to -be release in summer 2020. -* Some of the placeholders represent image size in x/y/z. This results in performance drop in case many images of -different size are processed as individual kernels need to be implemented. We have this in mind for the summer 2020 -update of the OpenCL-dialect. * Image dimensionality is limited to three dimensions. -## Deprecation note -The opencl-kernels presented here will be replaced by Summer 2020. Background -is an upcoming update of the used OpenCL dialect. If you plan to build your -software directly on our OpenCL kernels, you should consider waiting for this -update. You can follow development live on the -[development branch](https://github.com/clij/clij-opencl-kernels/tree/development/src/main/java/net/haesleinhuepf/clij/kernels). diff --git a/license.txt b/license.txt index b91e155..c8d5ba1 100644 --- a/license.txt +++ b/license.txt @@ -1,5 +1,7 @@ -Copyright 2019 Robert Haase, Nico Stuurman, Max Planck Institute for Molecular Cell Biology -and Genetics Dresden, Regents of the Univeristy of California +Copyright 2019 Robert Haase, Nico Stuurman, Deborah Schmidt, Uwe Schmidt, Martin Weigert, Peter Haub, Fabrice P. Cordelières +Max Planck Institute for Molecular Cell Biology +and Genetics Dresden, University of Virginia, +Regents of the Univeristy of California Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/pom.xml b/pom.xml index d923652..56a3cff 100644 --- a/pom.xml +++ b/pom.xml @@ -8,13 +8,13 @@ net.haesleinhuepf clij-parent-pom - 1.4.1 + 2.0.0.10 net.haesleinhuepf clij-opencl-kernels - 1.4.1 + 2.0.0.10 clij-opencl-kernels clij-opencl-kernels @@ -49,9 +49,17 @@ - + Nico Stuurman + + Peter Haub + iwbh15 + + + Ruth Whelan-Jeans + ruthwj + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/absolute_2d.cl b/src/main/java/net/haesleinhuepf/clij/kernels/absolute_2d_x.cl similarity index 58% rename from src/main/java/net/haesleinhuepf/clij/kernels/absolute_2d.cl rename to src/main/java/net/haesleinhuepf/clij/kernels/absolute_2d_x.cl index 557dadf..08d853a 100644 --- a/src/main/java/net/haesleinhuepf/clij/kernels/absolute_2d.cl +++ b/src/main/java/net/haesleinhuepf/clij/kernels/absolute_2d_x.cl @@ -1,7 +1,7 @@ __constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; -__kernel void absolute_2d(DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_OUT_2D dst +__kernel void absolute_2d(IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst ) { const int x = get_global_id(0); @@ -9,10 +9,10 @@ __kernel void absolute_2d(DTYPE_IMAGE_IN_2D src, const int2 pos = (int2){x,y}; - float value = READ_IMAGE_2D(src, sampler, pos).x; + float value = READ_src_IMAGE(src, sampler, pos).x; if ( value < 0 ) { value = -1 * value; } - WRITE_IMAGE_2D (dst, pos, CONVERT_DTYPE_OUT(value)); + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value)); } \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/absolute_3d.cl b/src/main/java/net/haesleinhuepf/clij/kernels/absolute_3d_x.cl similarity index 61% rename from src/main/java/net/haesleinhuepf/clij/kernels/absolute_3d.cl rename to src/main/java/net/haesleinhuepf/clij/kernels/absolute_3d_x.cl index 0915608..3141682 100644 --- a/src/main/java/net/haesleinhuepf/clij/kernels/absolute_3d.cl +++ b/src/main/java/net/haesleinhuepf/clij/kernels/absolute_3d_x.cl @@ -1,7 +1,7 @@ __constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; -__kernel void absolute_3d(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst +__kernel void absolute_3d(IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst ) { const int x = get_global_id(0); @@ -10,10 +10,10 @@ __kernel void absolute_3d(DTYPE_IMAGE_IN_3D src, const int4 pos = (int4){x,y,z,0}; - float value = READ_IMAGE_3D(src, sampler, pos).x; + float value = READ_src_IMAGE(src, sampler, pos).x; if ( value < 0 ) { value = -1 * value; } - WRITE_IMAGE_3D (dst, pos, CONVERT_DTYPE_OUT(value)); + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value)); } \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/addWeightedPixelwise_2d.cl b/src/main/java/net/haesleinhuepf/clij/kernels/addWeightedPixelwise_2d.cl deleted file mode 100644 index 96a185b..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/addWeightedPixelwise_2d.cl +++ /dev/null @@ -1,19 +0,0 @@ -__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - -__kernel void addWeightedPixelwise_2d(DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_IN_2D src1, - float factor, - float factor1, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(READ_IMAGE_2D(src, sampler, pos).x * factor + READ_IMAGE_2D(src1, sampler, pos).x * factor1); - - WRITE_IMAGE_2D (dst, pos, value); -} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/addWeightedPixelwise_3d.cl b/src/main/java/net/haesleinhuepf/clij/kernels/addWeightedPixelwise_3d.cl deleted file mode 100644 index 839cc42..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/addWeightedPixelwise_3d.cl +++ /dev/null @@ -1,19 +0,0 @@ -__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - -__kernel void addWeightedPixelwise_3d(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_IN_3D src1, - float factor, - float factor1, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(READ_IMAGE_3D(src, sampler, pos).x * factor + READ_IMAGE_3D(src1, sampler, pos).x * factor1); - - WRITE_IMAGE_3D (dst, pos, value); -} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/add_image_and_scalar_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/add_image_and_scalar_2d_x.cl new file mode 100644 index 0000000..b460995 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/add_image_and_scalar_2d_x.cl @@ -0,0 +1,17 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void add_image_and_scalar_2d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst, + float scalar +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(READ_src_IMAGE(src, sampler, pos).x + scalar); + + WRITE_dst_IMAGE (dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/add_image_and_scalar_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/add_image_and_scalar_3d_x.cl new file mode 100644 index 0000000..72ec97d --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/add_image_and_scalar_3d_x.cl @@ -0,0 +1,18 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void add_image_and_scalar_3d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst, + float scalar +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(READ_src_IMAGE(src, sampler, pos).x + scalar); + + WRITE_dst_IMAGE(dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/add_images_weighted_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/add_images_weighted_2d_x.cl new file mode 100644 index 0000000..8f624d4 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/add_images_weighted_2d_x.cl @@ -0,0 +1,20 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + +__kernel void add_images_weighted_2d( +IMAGE_src_TYPE src, +IMAGE_src1_TYPE src1, +IMAGE_dst_TYPE dst, +float factor, +float factor1 +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(READ_src_IMAGE(src, sampler, pos).x * factor + READ_src1_IMAGE(src1, sampler, pos).x * factor1); + + WRITE_dst_IMAGE (dst, pos, value); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/add_images_weighted_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/add_images_weighted_3d_x.cl new file mode 100644 index 0000000..6a5fbfa --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/add_images_weighted_3d_x.cl @@ -0,0 +1,23 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void add_images_weighted_3d( +IMAGE_src_TYPE src, +IMAGE_src1_TYPE src1, +IMAGE_dst_TYPE dst, +float factor, +float factor1 +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4)(x,y,z,0); + + const float value1 = factor * ((float)(READ_IMAGE(src, sampler, pos).x)); + const float value2 = factor1 * ((float)(READ_IMAGE(src1, sampler, pos).x)); + + float value = value1 + value2; + + WRITE_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE( value)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/affineTransforms_interpolate2D.cl b/src/main/java/net/haesleinhuepf/clij/kernels/affine_transform_2d_interpolate_x.cl similarity index 89% rename from src/main/java/net/haesleinhuepf/clij/kernels/affineTransforms_interpolate2D.cl rename to src/main/java/net/haesleinhuepf/clij/kernels/affine_transform_2d_interpolate_x.cl index d869028..9b2f70c 100644 --- a/src/main/java/net/haesleinhuepf/clij/kernels/affineTransforms_interpolate2D.cl +++ b/src/main/java/net/haesleinhuepf/clij/kernels/affine_transform_2d_interpolate_x.cl @@ -41,9 +41,10 @@ #define SAMPLER_ADDRESS CLK_ADDRESS_CLAMP #endif -__kernel void affine_interpolate2D(DTYPE_IMAGE_IN_2D input, - DTYPE_IMAGE_OUT_2D output, - __constant float * mat) +__kernel void affine_transform_2d_interpolate( + IMAGE_input_TYPE input, + IMAGE_output_TYPE output, + IMAGE_mat_TYPE mat) { const sampler_t sampler = CLK_NORMALIZED_COORDS_TRUE| @@ -63,9 +64,9 @@ __kernel void affine_interpolate2D(DTYPE_IMAGE_IN_2D input, float2 coord_norm = (float2)(x2/Nx,y2/Ny); - float pix = (float)(READ_IMAGE_2D(input, sampler, coord_norm).x); + float pix = (float)(READ_input_IMAGE(input, sampler, coord_norm).x); int2 pos = (int2){i, j}; - WRITE_IMAGE_2D(output, pos, (DTYPE_OUT) CONVERT_DTYPE_OUT(pix)); + WRITE_output_IMAGE(output, pos, CONVERT_output_PIXEL_TYPE(pix)); } \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/affineTransforms2D.cl b/src/main/java/net/haesleinhuepf/clij/kernels/affine_transform_2d_x.cl similarity index 89% rename from src/main/java/net/haesleinhuepf/clij/kernels/affineTransforms2D.cl rename to src/main/java/net/haesleinhuepf/clij/kernels/affine_transform_2d_x.cl index 48408a3..6eb8a4b 100644 --- a/src/main/java/net/haesleinhuepf/clij/kernels/affineTransforms2D.cl +++ b/src/main/java/net/haesleinhuepf/clij/kernels/affine_transform_2d_x.cl @@ -41,9 +41,10 @@ #define SAMPLER_ADDRESS CLK_ADDRESS_CLAMP #endif -__kernel void affine_2D(DTYPE_IMAGE_IN_2D input, - DTYPE_IMAGE_OUT_2D output, - __constant float * mat) +__kernel void affine_transform_2d( + IMAGE_input_TYPE input, + IMAGE_output_TYPE output, + IMAGE_mat_TYPE mat) { const sampler_t sampler = CLK_NORMALIZED_COORDS_TRUE| @@ -67,11 +68,11 @@ __kernel void affine_2D(DTYPE_IMAGE_IN_2D input, if (x2 >= 0 && y2 >= 0 && x2 < GET_IMAGE_WIDTH(input) && y2 < GET_IMAGE_HEIGHT(input) ) { - pix = (float)(READ_IMAGE_2D(input, sampler, coord_norm).x); + pix = (float)(READ_input_IMAGE(input, sampler, POS_input_INSTANCE(x2, y2, 0, 0)).x); } int2 pos = (int2){i, j}; - WRITE_IMAGE_2D(output, pos, (DTYPE_OUT) CONVERT_DTYPE_OUT(pix)); + WRITE_output_IMAGE(output, POS_output_INSTANCE(i, j, 0, 0), CONVERT_output_PIXEL_TYPE(pix)); } \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/affineTransforms_interpolate.cl b/src/main/java/net/haesleinhuepf/clij/kernels/affine_transform_3d_interpolate_x.cl similarity index 91% rename from src/main/java/net/haesleinhuepf/clij/kernels/affineTransforms_interpolate.cl rename to src/main/java/net/haesleinhuepf/clij/kernels/affine_transform_3d_interpolate_x.cl index d9ecbc4..d44bf8b 100644 --- a/src/main/java/net/haesleinhuepf/clij/kernels/affineTransforms_interpolate.cl +++ b/src/main/java/net/haesleinhuepf/clij/kernels/affine_transform_3d_interpolate_x.cl @@ -38,9 +38,10 @@ #define SAMPLER_ADDRESS CLK_ADDRESS_CLAMP #endif -__kernel void affine_interpolate(DTYPE_IMAGE_IN_3D input, - DTYPE_IMAGE_OUT_3D output, - __constant float * mat) +__kernel void affine_transform_3d_interpolate( + IMAGE_input_TYPE input, + IMAGE_output_TYPE output, + IMAGE_mat_TYPE mat) { const sampler_t sampler = CLK_NORMALIZED_COORDS_TRUE| @@ -73,9 +74,9 @@ __kernel void affine_interpolate(DTYPE_IMAGE_IN_3D input, //float4 coord_norm = (float4)(x2 * GET_IMAGE_WIDTH(input) / GET_IMAGE_WIDTH(output) / Nx,y2 * GET_IMAGE_HEIGHT(input) / GET_IMAGE_HEIGHT(output) / Ny, z2 * GET_IMAGE_DEPTH(input) / GET_IMAGE_DEPTH(output) / Nz,0.f); float4 coord_norm = (float4)(x2/Nx,y2/Ny,z2/Nz,0.f); - float pix = (float)(READ_IMAGE_3D(input, sampler, coord_norm).x); + float pix = (float)(READ_input_IMAGE(input, sampler, coord_norm).x); int4 pos = (int4){i, j, k,0}; - WRITE_IMAGE_3D(output, pos, (DTYPE_OUT) CONVERT_DTYPE_OUT(pix)); + WRITE_output_IMAGE(output, pos, CONVERT_output_PIXEL_TYPE(pix)); } \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/affineTransforms.cl b/src/main/java/net/haesleinhuepf/clij/kernels/affine_transform_3d_x.cl similarity index 91% rename from src/main/java/net/haesleinhuepf/clij/kernels/affineTransforms.cl rename to src/main/java/net/haesleinhuepf/clij/kernels/affine_transform_3d_x.cl index 8b094df..6bebdee 100644 --- a/src/main/java/net/haesleinhuepf/clij/kernels/affineTransforms.cl +++ b/src/main/java/net/haesleinhuepf/clij/kernels/affine_transform_3d_x.cl @@ -38,9 +38,10 @@ #define SAMPLER_ADDRESS CLK_ADDRESS_CLAMP #endif -__kernel void affine(DTYPE_IMAGE_IN_3D input, - DTYPE_IMAGE_OUT_3D output, - __constant float * mat) +__kernel void affine_transform_3d( + IMAGE_input_TYPE input, + IMAGE_output_TYPE output, + IMAGE_mat_TYPE mat) { const sampler_t sampler = CLK_NORMALIZED_COORDS_TRUE| @@ -80,12 +81,12 @@ __kernel void affine(DTYPE_IMAGE_IN_3D input, if (x2 >= 0 && y2 >= 0 && z2 >= 0 && x2 < GET_IMAGE_WIDTH(input) && y2 < GET_IMAGE_HEIGHT(input) && z2 < GET_IMAGE_DEPTH(input) ) { - pix = (float)(READ_IMAGE_3D(input, sampler, coord_norm).x); + pix = (float)(READ_input_IMAGE(input, sampler, POS_input_INSTANCE(x2, y2, z2, 0)).x); } int4 pos = (int4){i, j, k,0}; - WRITE_IMAGE_3D(output, pos, (DTYPE_OUT) CONVERT_DTYPE_OUT(pix)); + WRITE_output_IMAGE(output, POS_output_INSTANCE(i, j, k, 0), CONVERT_output_PIXEL_TYPE(pix)); } diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/apply_threshold_2d.cl b/src/main/java/net/haesleinhuepf/clij/kernels/apply_threshold_2d.cl deleted file mode 100644 index 5dd47a8..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/apply_threshold_2d.cl +++ /dev/null @@ -1,20 +0,0 @@ -__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - -__kernel void apply_threshold_2d(DTYPE_IMAGE_IN_2D src, - const float threshold, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - DTYPE_IN inputValue = READ_IMAGE_2D(src, sampler, pos).x; - DTYPE_OUT value = 1.0; - if (inputValue < threshold) { - value = 0.0; - } - - WRITE_IMAGE_2D (dst, pos, value); -} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/apply_threshold_3d.cl b/src/main/java/net/haesleinhuepf/clij/kernels/apply_threshold_3d.cl deleted file mode 100644 index 90f746d..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/apply_threshold_3d.cl +++ /dev/null @@ -1,21 +0,0 @@ -__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - -__kernel void apply_threshold_3d(DTYPE_IMAGE_IN_3D src, - const float threshold, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - DTYPE_IN inputValue = READ_IMAGE_3D(src, sampler, pos).x; - DTYPE_OUT value = 1.0; - if (inputValue < threshold) { - value = 0.0; - } - - WRITE_IMAGE_3D (dst, pos, value); -} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/apply_vectorfield_2d_interpolate_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/apply_vectorfield_2d_interpolate_x.cl new file mode 100644 index 0000000..fad1f0b --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/apply_vectorfield_2d_interpolate_x.cl @@ -0,0 +1,49 @@ + +#ifndef SAMPLER_FILTER +#define SAMPLER_FILTER CLK_FILTER_LINEAR +#endif + +#ifndef SAMPLER_ADDRESS +#define SAMPLER_ADDRESS CLK_ADDRESS_CLAMP +#endif + +__kernel void apply_vectorfield_2d_interpolate( + IMAGE_src_TYPE src, + IMAGE_vectorX_TYPE vectorX, + IMAGE_vectorY_TYPE vectorY, + IMAGE_dst_TYPE dst +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_TRUE| + SAMPLER_ADDRESS | SAMPLER_FILTER; + + uint i = get_global_id(0); + uint j = get_global_id(1); + + uint Nx = GET_IMAGE_WIDTH(src); + uint Ny = GET_IMAGE_HEIGHT(src); + + float x = i+0.5f; + float y = j+0.5f; + + + const POS_vectorX_TYPE posX = POS_vectorX_INSTANCE(i, j, 0, 0); + const POS_vectorY_TYPE posY = POS_vectorY_INSTANCE(i, j, 0, 0); + + float x2 = x + (float)(READ_vectorX_IMAGE(vectorX, sampler, posX).x); + float y2 = y + (float)(READ_vectorY_IMAGE(vectorY, sampler, posY).x); + + + float2 coord_norm = (float2)(x2 / Nx, y2 / Ny); + + float pix = 0; + if (x2 >= 0 && y2 >= 0 && + x2 < GET_IMAGE_WIDTH(src) && y2 < GET_IMAGE_HEIGHT(src) + ) { + pix = (float)(READ_src_IMAGE(src, sampler, coord_norm).x); + } + + + const POS_dst_TYPE posD = POS_dst_INSTANCE(i, j, 0, 0); + WRITE_dst_IMAGE(dst, posD, CONVERT_dst_PIXEL_TYPE(pix)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/apply_vectorfield_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/apply_vectorfield_2d_x.cl new file mode 100644 index 0000000..5fbef5a --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/apply_vectorfield_2d_x.cl @@ -0,0 +1,49 @@ + +#ifndef SAMPLER_FILTER +#define SAMPLER_FILTER CLK_FILTER_LINEAR +#endif + +#ifndef SAMPLER_ADDRESS +#define SAMPLER_ADDRESS CLK_ADDRESS_CLAMP +#endif + + +__kernel void apply_vectorfield_2d( + IMAGE_src_TYPE src, + IMAGE_vectorX_TYPE vectorX, + IMAGE_vectorY_TYPE vectorY, + IMAGE_dst_TYPE dst +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE| + SAMPLER_ADDRESS | SAMPLER_FILTER; + + uint i = get_global_id(0); + uint j = get_global_id(1); + + uint Nx = get_global_size(0); + uint Ny = get_global_size(1); + + float x = i+0.5f; + float y = j+0.5f; + + const POS_vectorX_TYPE posX = POS_vectorX_INSTANCE(i, j, 0, 0); + const POS_vectorY_TYPE posY = POS_vectorY_INSTANCE(i, j, 0, 0); + + float x2 = x + (float)(READ_vectorX_IMAGE(vectorX, sampler, posX).x); + float y2 = y + (float)(READ_vectorY_IMAGE(vectorY, sampler, posY).x); + + + int2 coord_norm = (int2)(x2, y2); + + float pix = 0; + if (x2 >= 0 && y2 >= 0 && + x2 < GET_IMAGE_WIDTH(src) && y2 < GET_IMAGE_HEIGHT(src) + ) { + pix = (float)(READ_src_IMAGE(src, sampler, coord_norm).x); + } + + + const POS_dst_TYPE posD = POS_dst_INSTANCE(i, j, 0, 0); + WRITE_dst_IMAGE(dst, posD, CONVERT_dst_PIXEL_TYPE(pix)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/apply_vectorfield_3d_interpolate_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/apply_vectorfield_3d_interpolate_x.cl new file mode 100644 index 0000000..d0f5622 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/apply_vectorfield_3d_interpolate_x.cl @@ -0,0 +1,53 @@ + +#ifndef SAMPLER_FILTER +#define SAMPLER_FILTER CLK_FILTER_LINEAR +#endif + +#ifndef SAMPLER_ADDRESS +#define SAMPLER_ADDRESS CLK_ADDRESS_CLAMP +#endif + +__kernel void apply_vectorfield_3d_interpolate( + IMAGE_src_TYPE src, + IMAGE_vectorX_TYPE vectorX, + IMAGE_vectorY_TYPE vectorY, + IMAGE_vectorZ_TYPE vectorZ, + IMAGE_dst_TYPE dst +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_TRUE| + SAMPLER_ADDRESS | SAMPLER_FILTER; + + uint i = get_global_id(0); + uint j = get_global_id(1); + uint k = get_global_id(2); + + uint Nx = GET_IMAGE_WIDTH(src); + uint Ny = GET_IMAGE_HEIGHT(src); + uint Nz = GET_IMAGE_DEPTH(src); + + float x = i+0.5f; + float y = j+0.5f; + float z = k+0.5f; + + int4 pos = (int4){i, j, k,0}; + + float x2 = x + (float)(READ_vectorX_IMAGE(vectorX, sampler, pos).x); + float y2 = y + (float)(READ_vectorY_IMAGE(vectorY, sampler, pos).x); + float z2 = z + (float)(READ_vectorZ_IMAGE(vectorZ, sampler, pos).x); + + + //int4 coord_norm = (int4)(x2 * GET_IMAGE_WIDTH(input) / GET_IMAGE_WIDTH(output),y2 * GET_IMAGE_HEIGHT(input) / GET_IMAGE_HEIGHT(output), z2 * GET_IMAGE_DEPTH(input) / GET_IMAGE_DEPTH(output),0.f); + float4 coord_norm = (float4)(x2 / Nx, y2 / Ny, z2 / Nz,0.f); + + + + float pix = 0; + if (x2 >= 0 && y2 >= 0 && z2 >= 0 && + x2 < GET_IMAGE_WIDTH(src) && y2 < GET_IMAGE_HEIGHT(src) && z2 < GET_IMAGE_DEPTH(src) + ) { + pix = (float)(READ_src_IMAGE(src, sampler, coord_norm).x); + } + + WRITE_dst_IMAGE(dst, pos, CONVERT_dst_PIXEL_TYPE(pix)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/apply_vectorfield_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/apply_vectorfield_3d_x.cl new file mode 100644 index 0000000..e4dee67 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/apply_vectorfield_3d_x.cl @@ -0,0 +1,54 @@ + +#ifndef SAMPLER_FILTER +#define SAMPLER_FILTER CLK_FILTER_LINEAR +#endif + +#ifndef SAMPLER_ADDRESS +#define SAMPLER_ADDRESS CLK_ADDRESS_CLAMP +#endif + +__kernel void apply_vectorfield_3d( + IMAGE_src_TYPE src, + IMAGE_vectorX_TYPE vectorX, + IMAGE_vectorY_TYPE vectorY, + IMAGE_vectorZ_TYPE vectorZ, + IMAGE_dst_TYPE dst +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | + SAMPLER_ADDRESS | SAMPLER_FILTER; + + uint i = get_global_id(0); + uint j = get_global_id(1); + uint k = get_global_id(2); + + uint Nx = get_global_size(0); + uint Ny = get_global_size(1); + uint Nz = get_global_size(2); + + float x = i+0.5f; + float y = j+0.5f; + float z = k+0.5f; + + int4 pos = (int4){i, j, k,0}; + + float x2 = x + (float)(READ_vectorX_IMAGE(vectorX, sampler, pos).x); + float y2 = y + (float)(READ_vectorY_IMAGE(vectorY, sampler, pos).x); + float z2 = z + (float)(READ_vectorZ_IMAGE(vectorZ, sampler, pos).x); + + + //int4 coord_norm = (int4)(x2 * GET_IMAGE_WIDTH(input) / GET_IMAGE_WIDTH(output),y2 * GET_IMAGE_HEIGHT(input) / GET_IMAGE_HEIGHT(output), z2 * GET_IMAGE_DEPTH(input) / GET_IMAGE_DEPTH(output),0.f); + int4 coord_norm = (int4)(x2,y2, z2,0.f); + + + + float pix = 0; + if (x2 >= 0 && y2 >= 0 && z2 >= 0 && + x2 < GET_IMAGE_WIDTH(src) && y2 < GET_IMAGE_HEIGHT(src) && z2 < GET_IMAGE_DEPTH(src) + ) { + pix = (float)(READ_src_IMAGE(src, sampler, coord_norm).x); + } + + WRITE_dst_IMAGE(dst, pos, CONVERT_dst_PIXEL_TYPE(pix)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/arg_max_project_3d_2d.cl b/src/main/java/net/haesleinhuepf/clij/kernels/arg_max_project_3d_2d.cl deleted file mode 100644 index beb5a66..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/arg_max_project_3d_2d.cl +++ /dev/null @@ -1,23 +0,0 @@ - -__kernel void arg_max_project_3d_2d( - DTYPE_IMAGE_OUT_2D dst_max, - DTYPE_IMAGE_OUT_2D dst_arg, - DTYPE_IMAGE_IN_3D src -) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int x = get_global_id(0); - const int y = get_global_id(1); - DTYPE_IN max = 0; - int max_pos = 0; - for(int z = 0; z < GET_IMAGE_IN_DEPTH(src); z++) - { - DTYPE_IN value = READ_IMAGE_3D(src,sampler,(int4)(x,y,z,0)).x; - if (value > max || z == 0) { - max = value; - max_pos = z; - } - } - WRITE_IMAGE_2D(dst_max,(int2)(x,y), CONVERT_DTYPE_OUT(max)); - WRITE_IMAGE_2D(dst_arg,(int2)(x,y), CONVERT_DTYPE_OUT(max_pos)); -} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/arg_maximum_z_projection_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/arg_maximum_z_projection_x.cl new file mode 100644 index 0000000..45eb41b --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/arg_maximum_z_projection_x.cl @@ -0,0 +1,23 @@ + +__kernel void arg_maximum_z_projection ( + IMAGE_dst_max_TYPE dst_max, + IMAGE_dst_arg_TYPE dst_arg, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + float max = 0; + int max_pos = 0; + for(int z = 0; z < GET_IMAGE_DEPTH(src); z++) + { + float value = READ_src_IMAGE(src,sampler,POS_src_INSTANCE(x,y,z,0)).x; + if (value > max || z == 0) { + max = value; + max_pos = z; + } + } + WRITE_dst_max_IMAGE(dst_max,POS_dst_max_INSTANCE(x,y,0,0), CONVERT_dst_max_PIXEL_TYPE(max)); + WRITE_dst_arg_IMAGE(dst_arg,POS_dst_arg_INSTANCE(x,y,0,0), CONVERT_dst_arg_PIXEL_TYPE(max_pos)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/average_distance_of_n_far_off_distances_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/average_distance_of_n_far_off_distances_x.cl new file mode 100644 index 0000000..20c1599 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/average_distance_of_n_far_off_distances_x.cl @@ -0,0 +1,53 @@ +__kernel void average_distance_of_n_far_off_points( +IMAGE_src_distancematrix_TYPE src_distancematrix, +IMAGE_dst_indexlist_TYPE dst_indexlist, int nPoints) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int pointIndex = get_global_id(0); + + // so many point candidates are available: + const int height = GET_IMAGE_HEIGHT(src_distancematrix); + + float distances[1000]; + float indices[1000]; + + int initialized_values = 0; + + // start at 1 to exclude background + for (int y = 1; y < height; y++) { + if (pointIndex != y) { // exclude distance to self + float distance = READ_src_distancematrix_IMAGE(src_distancematrix, sampler, POS_src_distancematrix_INSTANCE(pointIndex, y, 0, 0)).x; + + if (initialized_values < nPoints) { + initialized_values++; + distances[initialized_values - 1] = distance; + indices[initialized_values - 1] = y; + } + // sort by insert + for (int i = initialized_values - 1; i >= 0; i--) { + if (distance < distances[i]) { + break; + } + if (distance > distances[i] && (i == 0 || distance <= distances[i - 1])) { + for (int j = initialized_values - 1; j > i; j--) { + indices[j] = indices[j - 1]; + distances[j] = distances[j - 1]; + } + distances[i] = distance; + indices[i] = y; + break; + } + } + } + } + + float sum = 0; + int count = 0; + for (int i = 0; i < initialized_values; i++) { + sum = sum + distances[i]; + count++; + } + + float res = sum / count; + WRITE_dst_indexlist_IMAGE(dst_indexlist, POS_dst_indexlist_INSTANCE(pointIndex, 0, 0, 0), CONVERT_dst_indexlist_PIXEL_TYPE(res)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/average_distance_of_n_shortest_distances_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/average_distance_of_n_shortest_distances_x.cl new file mode 100644 index 0000000..f998407 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/average_distance_of_n_shortest_distances_x.cl @@ -0,0 +1,53 @@ +__kernel void average_distance_of_n_closest_points( +IMAGE_src_distancematrix_TYPE src_distancematrix, +IMAGE_dst_indexlist_TYPE dst_indexlist, int nPoints) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int pointIndex = get_global_id(0); + + // so many point candidates are available: + const int height = GET_IMAGE_HEIGHT(src_distancematrix); + + float distances[1000]; + float indices[1000]; + + int initialized_values = 0; + + // start at 1 to exclude background + for (int y = 1; y < height; y++) { + if (pointIndex != y) { // exclude distance to self + float distance = READ_src_distancematrix_IMAGE(src_distancematrix, sampler, POS_src_distancematrix_INSTANCE(pointIndex, y, 0, 0)).x; + + if (initialized_values < nPoints) { + initialized_values++; + distances[initialized_values - 1] = distance; + indices[initialized_values - 1] = y; + } + // sort by insert + for (int i = initialized_values - 1; i >= 0; i--) { + if (distance > distances[i]) { + break; + } + if (distance < distances[i] && (i == 0 || distance >= distances[i - 1])) { + for (int j = initialized_values - 1; j > i; j--) { + indices[j] = indices[j - 1]; + distances[j] = distances[j - 1]; + } + distances[i] = distance; + indices[i] = y; + break; + } + } + } + } + + float sum = 0; + int count = 0; + for (int i = 0; i < initialized_values; i++) { + sum = sum + distances[i]; + count++; + } + + float res = sum / count; + WRITE_dst_indexlist_IMAGE(dst_indexlist, POS_dst_indexlist_INSTANCE(pointIndex, 0, 0, 0), CONVERT_dst_indexlist_PIXEL_TYPE(res)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/average_distance_of_touching_neighbors_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/average_distance_of_touching_neighbors_x.cl new file mode 100644 index 0000000..e602a43 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/average_distance_of_touching_neighbors_x.cl @@ -0,0 +1,38 @@ + +__kernel void average_distance_of_touching_neighbors ( + IMAGE_src_distance_matrix_TYPE src_distance_matrix, + IMAGE_src_touch_matrix_TYPE src_touch_matrix, + IMAGE_dst_average_distance_list_TYPE dst_average_distance_list +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int label_id = get_global_id(0); + const int label_count = get_global_size(0); + + int count = 0; + float sum = 0; + + int y = label_id; + int x = 0; + for (x = 0; x < label_id; x++) { + POS_src_touch_matrix_TYPE pos = POS_src_touch_matrix_INSTANCE(x, y, 0, 0); + float value = READ_src_touch_matrix_IMAGE(src_touch_matrix, sampler, pos).x; + if (value > 0) { + sum = sum + READ_src_distance_matrix_IMAGE(src_distance_matrix, sampler, pos).x; + count++; + } + } + x = label_id; + for (y = label_id + 1; y < label_count; y++) { + POS_src_touch_matrix_TYPE pos = POS_src_touch_matrix_INSTANCE(x, y, 0, 0); + float value = READ_src_touch_matrix_IMAGE(src_touch_matrix, sampler, pos).x; + if (value > 0) { + sum = sum + READ_src_distance_matrix_IMAGE(src_distance_matrix, sampler, pos).x; + count++; + } + } + + float average = sum / count; + WRITE_dst_average_distance_list_IMAGE(dst_average_distance_list, (POS_dst_average_distance_list_INSTANCE(label_id, 0, 0, 0)), CONVERT_dst_average_distance_list_PIXEL_TYPE(average)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/binaryCounting.cl b/src/main/java/net/haesleinhuepf/clij/kernels/binaryCounting.cl deleted file mode 100644 index 8241f40..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/binaryCounting.cl +++ /dev/null @@ -1,123 +0,0 @@ -__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - -__kernel void count_nonzero_slicewise_image3d -( - DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src, - const int Nx, const int Ny -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4){i,j,k,0}; - - const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, 0, 0 }; - - float aSquared = e.x * e.x; - float bSquared = e.y * e.y; - - DTYPE_OUT sum = 0; - int count = 0; - - for (int x = -e.x; x <= e.x; x++) { - float xSquared = x * x; - for (int y = -e.y; y <= e.y; y++) { - float ySquared = y * y; - if (xSquared / aSquared + ySquared / bSquared <= 1.0) { - DTYPE_OUT value = (DTYPE_OUT)READ_IMAGE_3D(src,sampler,coord+((int4){x,y,k,0})).x; - if (value != 0) { - count++; - } - } - } - } - - DTYPE_OUT res = CONVERT_DTYPE_OUT(count); - WRITE_IMAGE_3D(dst, coord, res); -} - - -__kernel void count_nonzero_image2d -( - DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src, - const int Nx, const int Ny -) -{ - const int i = get_global_id(0), j = get_global_id(1); - const int2 coord = (int2){i,j}; - - const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, 0, 0 }; - int count = 0; - float sum = 0; - - float aSquared = e.x * e.x; - float bSquared = e.y * e.y; - - for (int x = -e.x; x <= e.x; x++) { - float xSquared = x * x; - for (int y = -e.y; y <= e.y; y++) { - float ySquared = y * y; - if (xSquared / aSquared + ySquared / bSquared <= 1.0) { - DTYPE_OUT value = (DTYPE_OUT)READ_IMAGE_2D(src,sampler,coord+((int2){x,y})).x; - if (value != 0) { - count++; - } - } - } - } - - DTYPE_OUT res = CONVERT_DTYPE_OUT(count); - WRITE_IMAGE_2D(dst, coord, res); -} - -__kernel void count_nonzero_image3d -( - DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src, - const int Nx, const int Ny, const int Nz -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4){i,j,k,0}; - - const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, (Nz-1)/2, 0 }; - int count = 0; - float sum = 0; - - float aSquared = e.x * e.x; - float bSquared = e.y * e.y; - float cSquared = e.z * e.z; - - for (int x = -e.x; x <= e.x; x++) { - float xSquared = x * x; - for (int y = -e.y; y <= e.y; y++) { - float ySquared = y * y; - for (int z = -e.z; z <= e.z; z++) { - float zSquared = z * z; - if (xSquared / aSquared + ySquared / bSquared + zSquared / cSquared <= 1.0) { - - int x1 = coord.x + x; - int x2 = coord.y + y; - int x3 = coord.z + z; - const int4 pos = (int4){x1,x2,x3,0}; - float value_res = (float)READ_IMAGE_3D(src,sampler,pos).x; - if (value_res != 0) { - count++; - } - } - } - } - } - - - DTYPE_OUT res = CONVERT_DTYPE_OUT(count); - WRITE_IMAGE_3D(dst, coord, res); -} - - - - - - - - - - - diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/binaryIJ.cl b/src/main/java/net/haesleinhuepf/clij/kernels/binaryIJ.cl deleted file mode 100644 index 2cd2bd9..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/binaryIJ.cl +++ /dev/null @@ -1,40 +0,0 @@ -__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - -__kernel void convert_to_imagej_binary_2d(DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - float value = (float)(READ_IMAGE_2D(src, sampler, pos).x); - if ( value != 0 ) { - value = 255; - } else { - value = 0; - } - WRITE_IMAGE_2D (dst, pos, CONVERT_DTYPE_OUT(value)); -} - - -__kernel void convert_to_imagej_binary_3d(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - float value = (float)(READ_IMAGE_3D(src, sampler, pos).x); - if ( value != 0 ) { - value = 255; - } else { - value = 0; - } - WRITE_IMAGE_3D (dst, pos, CONVERT_DTYPE_OUT(value)); -} - diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/binaryProcessing2D.cl b/src/main/java/net/haesleinhuepf/clij/kernels/binaryProcessing2D.cl deleted file mode 100644 index dbee4bf..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/binaryProcessing2D.cl +++ /dev/null @@ -1,200 +0,0 @@ -__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - -__kernel void binary_or_2d(DTYPE_IMAGE_IN_2D src1, - DTYPE_IMAGE_IN_2D src2, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - DTYPE_OUT value1 = CONVERT_DTYPE_OUT(READ_IMAGE_2D(src1, sampler, pos).x); - DTYPE_OUT value2 = CONVERT_DTYPE_OUT(READ_IMAGE_2D(src2, sampler, pos).x); - if ( value1 > 0 || value2 > 0 ) { - value1 = 1; - } else { - value1 = 0; - } - WRITE_IMAGE_2D (dst, pos, value1); -} - -__kernel void binary_and_2d(DTYPE_IMAGE_IN_2D src1, - DTYPE_IMAGE_IN_2D src2, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - DTYPE_OUT value1 = CONVERT_DTYPE_OUT(READ_IMAGE_2D(src1, sampler, pos).x); - DTYPE_OUT value2 = CONVERT_DTYPE_OUT(READ_IMAGE_2D(src2, sampler, pos).x); - if ( value1 > 0 && value2 > 0 ) { - value1 = 1; - } else { - value1 = 0; - } - WRITE_IMAGE_2D (dst, pos, value1); -} - -__kernel void binary_xor_2d(DTYPE_IMAGE_IN_2D src1, - DTYPE_IMAGE_IN_2D src2, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - DTYPE_OUT value1 = CONVERT_DTYPE_OUT(READ_IMAGE_2D(src1, sampler, pos).x); - DTYPE_OUT value2 = CONVERT_DTYPE_OUT(READ_IMAGE_2D(src2, sampler, pos).x); - if ( (value1 > 0 && value2 == 0) || (value1 == 0 && value2 > 0)) { - value1 = 1; - } else { - value1 = 0; - } - WRITE_IMAGE_2D (dst, pos, value1); -} - -__kernel void binary_not_2d(DTYPE_IMAGE_IN_2D src1, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - DTYPE_OUT value1 = CONVERT_DTYPE_OUT(READ_IMAGE_2D(src1, sampler, pos).x); - if ( value1 > 0) { - value1 = 0; - } else { - value1 = 1; - } - WRITE_IMAGE_2D (dst, pos, value1); -} - - -__kernel void erode_box_neighborhood_2d(DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - float value = READ_IMAGE_2D(src, sampler, pos).x; - if (value != 0) { - for (int ax = -1; ax <= 1; ax++) { - for (int ay = -1; ay <= 1; ay++) { - value = READ_IMAGE_2D(src, sampler, (pos + (int2){ax, ay})).x; - if (value == 0) { - break; - } - } - if (value == 0) { - break; - } - } - } - if (value != 0) { - value = 1; - } - - WRITE_IMAGE_2D (dst, pos, CONVERT_DTYPE_OUT(value)); -} - - -__kernel void erode_diamond_neighborhood_2d(DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - float value = READ_IMAGE_2D(src, sampler, pos).x; - if (value != 0) { - value = READ_IMAGE_2D(src, sampler, (pos + (int2){1, 0})).x; - if (value != 0) { - value = READ_IMAGE_2D(src, sampler, (pos + (int2){-1, 0})).x; - if (value != 0) { - value = READ_IMAGE_2D(src, sampler, (pos + (int2){0, 1})).x; - if (value != 0) { - value = READ_IMAGE_2D(src, sampler, (pos + (int2){0, -1})).x; - } - } - } - } - if (value != 0) { - value = 1; - } - - WRITE_IMAGE_2D (dst, pos, CONVERT_DTYPE_OUT(value)); -} - - -__kernel void dilate_box_neighborhood_2d(DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - float value = READ_IMAGE_2D(src, sampler, pos).x; - if (value == 0) { - for (int ax = -1; ax <= 1; ax++) { - for (int ay = -1; ay <= 1; ay++) { - value = READ_IMAGE_2D(src, sampler, (pos + (int2){ax, ay})).x; - if (value != 0) { - break; - } - } - if (value != 0) { - break; - } - } - } - if (value != 0) { - value = 1; - } - - WRITE_IMAGE_2D (dst, pos, CONVERT_DTYPE_OUT(value)); -} - -__kernel void dilate_diamond_neighborhood_2d(DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - float value = READ_IMAGE_2D(src, sampler, pos).x; - if (value == 0) { - value = READ_IMAGE_2D(src, sampler, (pos + (int2){1, 0})).x; - if (value == 0) { - value = READ_IMAGE_2D(src, sampler, (pos + (int2){-1, 0})).x; - if (value == 0) { - value = READ_IMAGE_2D(src, sampler, (pos + (int2){0, 1})).x; - if (value == 0) { - value = READ_IMAGE_2D(src, sampler, (pos + (int2){0, -1})).x; - } - } - } - } - if (value != 0) { - value = 1; - } - - WRITE_IMAGE_2D (dst, pos, CONVERT_DTYPE_OUT(value)); -} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/binaryProcessing3D.cl b/src/main/java/net/haesleinhuepf/clij/kernels/binaryProcessing3D.cl deleted file mode 100644 index 1e6b6da..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/binaryProcessing3D.cl +++ /dev/null @@ -1,345 +0,0 @@ -__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - -__kernel void binary_or_3d(DTYPE_IMAGE_IN_3D src1, - DTYPE_IMAGE_IN_3D src2, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - DTYPE_OUT value1 = CONVERT_DTYPE_OUT(READ_IMAGE_3D(src1, sampler, pos).x); - DTYPE_OUT value2 = CONVERT_DTYPE_OUT(READ_IMAGE_3D(src2, sampler, pos).x); - if ( value1 > 0 || value2 > 0 ) { - value1 = 1; - } else { - value1 = 0; - } - WRITE_IMAGE_3D (dst, pos, value1); -} - -__kernel void binary_and_3d(DTYPE_IMAGE_IN_3D src1, - DTYPE_IMAGE_IN_3D src2, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - DTYPE_OUT value1 = CONVERT_DTYPE_OUT(READ_IMAGE_3D(src1, sampler, pos).x); - DTYPE_OUT value2 = CONVERT_DTYPE_OUT(READ_IMAGE_3D(src2, sampler, pos).x); - if ( value1 > 0 && value2 > 0 ) { - value1 = 1; - } else { - value1 = 0; - } - WRITE_IMAGE_3D (dst, pos, value1); -} - -__kernel void binary_xor_3d(DTYPE_IMAGE_IN_3D src1, - DTYPE_IMAGE_IN_3D src2, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - DTYPE_OUT value1 = CONVERT_DTYPE_OUT(READ_IMAGE_3D(src1, sampler, pos).x); - DTYPE_OUT value2 = CONVERT_DTYPE_OUT(READ_IMAGE_3D(src2, sampler, pos).x); - if ( (value1 > 0 && value2 == 0) || (value1 == 0 && value2 > 0)) { - value1 = 1; - } else { - value1 = 0; - } - WRITE_IMAGE_3D (dst, pos, value1); -} - -__kernel void binary_not_3d(DTYPE_IMAGE_IN_3D src1, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - DTYPE_OUT value1 = CONVERT_DTYPE_OUT(READ_IMAGE_3D(src1, sampler, pos).x); - if ( value1 > 0) { - value1 = 0; - } else { - value1 = 1; - } - WRITE_IMAGE_3D (dst, pos, value1); -} - -__kernel void erode_box_neighborhood_3d(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - float value = READ_IMAGE_3D(src, sampler, pos).x; - if (value != 0) { - for (int ax = -1; ax <= 1; ax++) { - for (int ay = -1; ay <= 1; ay++) { - for (int az = -1; az <= 1; az++) { - value = READ_IMAGE_3D(src, sampler, (pos + (int4){ax, ay, az, 0})).x; - if (value == 0) { - break; - } - } - if (value == 0) { - break; - } - } - if (value == 0) { - break; - } - } - } - if (value != 0) { - value = 1; - } - - WRITE_IMAGE_3D (dst, pos, CONVERT_DTYPE_OUT(value)); -} - -__kernel void erode_box_neighborhood_slice_by_slice(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - float value = READ_IMAGE_3D(src, sampler, pos).x; - if (value != 0) { - for (int ax = -1; ax <= 1; ax++) { - for (int ay = -1; ay <= 1; ay++) { - value = READ_IMAGE_3D(src, sampler, (pos + (int4){ax, ay, 0, 0})).x; - if (value == 0) { - break; - } - } - if (value == 0) { - break; - } - } - } - if (value != 0) { - value = 1; - } - - WRITE_IMAGE_3D (dst, pos, CONVERT_DTYPE_OUT(value)); -} - -__kernel void erode_diamond_neighborhood_3d(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - float value = READ_IMAGE_3D(src, sampler, pos).x; - if (value != 0) { - value = READ_IMAGE_3D(src, sampler, (pos + (int4){1, 0, 0, 0})).x; - if (value != 0) { - value = READ_IMAGE_3D(src, sampler, (pos + (int4){-1, 0, 0, 0})).x; - if (value != 0) { - value = READ_IMAGE_3D(src, sampler, (pos + (int4){0, 1, 0, 0})).x; - if (value != 0) { - value = READ_IMAGE_3D(src, sampler, (pos + (int4){0, -1, 0, 0})).x; - } - } - } - } - if (value != 0) { - value = 1; - } - - WRITE_IMAGE_3D (dst, pos, CONVERT_DTYPE_OUT(value)); -} - -__kernel void erode_diamond_neighborhood_slice_by_slice(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - float value = READ_IMAGE_3D(src, sampler, pos).x; - if (value != 0) { - value = READ_IMAGE_3D(src, sampler, (pos + (int4){1, 0, 0, 0})).x; - if (value != 0) { - value = READ_IMAGE_3D(src, sampler, (pos + (int4){-1, 0, 0, 0})).x; - if (value != 0) { - value = READ_IMAGE_3D(src, sampler, (pos + (int4){0, 1, 0, 0})).x; - if (value != 0) { - value = READ_IMAGE_3D(src, sampler, (pos + (int4){0, -1, 0, 0})).x; - } - } - } - } - if (value != 0) { - value = 1; - } - - WRITE_IMAGE_3D (dst, pos, CONVERT_DTYPE_OUT(value)); -} - -__kernel void dilate_box_neighborhood_3d(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - float value = READ_IMAGE_3D(src, sampler, pos).x; - if (value < 1) { - for (int ax = -1; ax <= 1; ax++) { - for (int ay = -1; ay <= 1; ay++) { - for (int az = -1; az <= 1; az++) { - value = READ_IMAGE_3D(src, sampler, (pos + (int4){ax, ay, az, 0})).x; - if (value != 0) { - break; - } - } - if (value != 0) { - break; - } - } - if (value != 0) { - break; - } - } - } - if (value != 0) { - value = 1; - } - - WRITE_IMAGE_3D (dst, pos, CONVERT_DTYPE_OUT(value)); -} - -__kernel void dilate_box_neighborhood_slice_by_slice(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - float value = READ_IMAGE_3D(src, sampler, pos).x; - if (value == 0) { - for (int ax = -1; ax <= 1; ax++) { - for (int ay = -1; ay <= 1; ay++) { - value = READ_IMAGE_3D(src, sampler, (pos + (int4){ax, ay, 0, 0})).x; - if (value != 0) { - break; - } - } - if (value != 0) { - break; - } - } - } - if (value != 0) { - value = 1; - } - - WRITE_IMAGE_3D (dst, pos, CONVERT_DTYPE_OUT(value)); -} - -__kernel void dilate_diamond_neighborhood_3d(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - float value = READ_IMAGE_3D(src, sampler, pos).x; - if (value == 0) { - - value = READ_IMAGE_3D(src, sampler, (pos + (int4){1, 0, 0, 0})).x; - if (value == 0) { - value = READ_IMAGE_3D(src, sampler, (pos + (int4){-1, 0, 0, 0})).x; - if (value == 0) { - value = READ_IMAGE_3D(src, sampler, (pos + (int4){0, 1, 0, 0})).x; - if (value == 0) { - value = READ_IMAGE_3D(src, sampler, (pos + (int4){0, -1, 0, 0})).x; - if (value == 0) { - value = READ_IMAGE_3D(src, sampler, (pos + (int4){0, 0, 1, 0})).x; - if (value == 0) { - value = READ_IMAGE_3D(src, sampler, (pos + (int4){0, 0, -1, 0})).x; - } - } - } - } - } - } - if (value != 0) { - value = 1; - } - - WRITE_IMAGE_3D (dst, pos, CONVERT_DTYPE_OUT(value)); -} - -__kernel void dilate_diamond_neighborhood_slice_by_slice(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - float value = READ_IMAGE_3D(src, sampler, pos).x; - if (value == 0) { - - value = READ_IMAGE_3D(src, sampler, (pos + (int4){1, 0, 0, 0})).x; - if (value == 0) { - value = READ_IMAGE_3D(src, sampler, (pos + (int4){-1, 0, 0, 0})).x; - if (value == 0) { - value = READ_IMAGE_3D(src, sampler, (pos + (int4){0, 1, 0, 0})).x; - if (value == 0) { - value = READ_IMAGE_3D(src, sampler, (pos + (int4){0, -1, 0, 0})).x; - } - } - } - } - if (value != 0) { - value = 1; - } - - WRITE_IMAGE_3D (dst, pos, CONVERT_DTYPE_OUT(value)); -} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/binary_and_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/binary_and_2d_x.cl new file mode 100644 index 0000000..4ab372e --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/binary_and_2d_x.cl @@ -0,0 +1,22 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void binary_and_2d( + IMAGE_src1_TYPE src1, + IMAGE_src2_TYPE src2, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + IMAGE_dst_PIXEL_TYPE value1 = CONVERT_dst_PIXEL_TYPE(READ_src1_IMAGE(src1, sampler, pos).x); + IMAGE_dst_PIXEL_TYPE value2 = CONVERT_dst_PIXEL_TYPE(READ_src2_IMAGE(src2, sampler, pos).x); + if ( value1 != 0 && value2 != 0 ) { + value1 = 1; + } else { + value1 = 0; + } + WRITE_dst_IMAGE (dst, pos, value1); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/binary_and_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/binary_and_3d_x.cl new file mode 100644 index 0000000..5f87c61 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/binary_and_3d_x.cl @@ -0,0 +1,23 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void binary_and_3d( + IMAGE_src1_TYPE src1, + IMAGE_src2_TYPE src2, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + IMAGE_dst_PIXEL_TYPE value1 = CONVERT_dst_PIXEL_TYPE(READ_src1_IMAGE(src1, sampler, pos).x); + IMAGE_dst_PIXEL_TYPE value2 = CONVERT_dst_PIXEL_TYPE(READ_src2_IMAGE(src2, sampler, pos).x); + if ( value1 != 0 && value2 != 0 ) { + value1 = 1; + } else { + value1 = 0; + } + WRITE_dst_IMAGE (dst, pos, value1); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/binary_edge_detection_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/binary_edge_detection_2d_x.cl new file mode 100644 index 0000000..978fe87 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/binary_edge_detection_2d_x.cl @@ -0,0 +1,39 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void binary_edge_detection_2d +( + IMAGE_dst_TYPE dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float valueToWrite = READ_src_IMAGE(src, sampler, pos).x; + if (valueToWrite != 0) { + valueToWrite = 0; + float value = READ_src_IMAGE(src, sampler, (pos + (int2){1, 0})).x; + if ( value == 0) { + valueToWrite = 1; + } else { + value = READ_src_IMAGE(src, sampler, (pos + (int2){-1, 0})).x; + if ( value == 0) { + valueToWrite = 1; + } else { + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, 1})).x; + if ( value == 0) { + valueToWrite = 1; + } else { + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, -1})).x; + if ( value == 0) { + valueToWrite = 1; + } + } + } + } + } + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(valueToWrite)); + +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/binary_edge_detection_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/binary_edge_detection_3d_x.cl new file mode 100644 index 0000000..b47f7e9 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/binary_edge_detection_3d_x.cl @@ -0,0 +1,49 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void binary_edge_detection_3d +( + IMAGE_dst_TYPE dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float valueToWrite = READ_src_IMAGE(src, sampler, pos).x; + if (valueToWrite != 0) { + valueToWrite = 0; + float value = READ_src_IMAGE(src, sampler, (pos + (int4){1, 0, 0, 0})).x; + if ( value == 0) { + valueToWrite = 1; + } else { + value = READ_src_IMAGE(src, sampler, (pos + (int4){-1, 0, 0, 0})).x; + if ( value == 0) { + valueToWrite = 1; + } else { + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 1, 0, 0})).x; + if ( value == 0) { + valueToWrite = 1; + } else { + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, -1, 0, 0})).x; + if ( value == 0) { + valueToWrite = 1; + } else { + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 0, 1, 0})).x; + if ( value == 0) { + valueToWrite = 1; + } else { + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 0, -1, 0})).x; + if ( value == 0) { + valueToWrite = 1; + } + } + } + } + } + } + } + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(valueToWrite)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/binary_not_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/binary_not_2d_x.cl new file mode 100644 index 0000000..e3f33a5 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/binary_not_2d_x.cl @@ -0,0 +1,21 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void binary_not_2d( + IMAGE_src1_TYPE src1, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + IMAGE_dst_PIXEL_TYPE value1 = CONVERT_dst_PIXEL_TYPE(READ_src1_IMAGE(src1, sampler, pos).x); + if ( value1 != 0) { + value1 = 0; + } else { + value1 = 1; + } + WRITE_dst_IMAGE (dst, pos, value1); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/binary_not_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/binary_not_3d_x.cl new file mode 100644 index 0000000..2400b16 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/binary_not_3d_x.cl @@ -0,0 +1,22 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void binary_not_3d( + IMAGE_src1_TYPE src1, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + IMAGE_dst_PIXEL_TYPE value1 = CONVERT_dst_PIXEL_TYPE(READ_src1_IMAGE(src1, sampler, pos).x); + if ( value1 != 0) { + value1 = 0; + } else { + value1 = 1; + } + WRITE_dst_IMAGE (dst, pos, value1); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/binary_or_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/binary_or_2d_x.cl new file mode 100644 index 0000000..6f05e27 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/binary_or_2d_x.cl @@ -0,0 +1,23 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void binary_or_2d( + IMAGE_src1_TYPE src1, + IMAGE_src2_TYPE src2, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + IMAGE_dst_PIXEL_TYPE value1 = CONVERT_dst_PIXEL_TYPE(READ_src1_IMAGE(src1, sampler, pos).x); + IMAGE_dst_PIXEL_TYPE value2 = CONVERT_dst_PIXEL_TYPE(READ_src2_IMAGE(src2, sampler, pos).x); + if ( value1 != 0 || value2 != 0 ) { + value1 = 1; + } else { + value1 = 0; + } + WRITE_dst_IMAGE (dst, pos, value1); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/binary_or_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/binary_or_3d_x.cl new file mode 100644 index 0000000..1adc2ac --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/binary_or_3d_x.cl @@ -0,0 +1,24 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void binary_or_3d( + IMAGE_src1_TYPE src1, + IMAGE_src2_TYPE src2, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + IMAGE_dst_PIXEL_TYPE value1 = CONVERT_dst_PIXEL_TYPE(READ_src1_IMAGE(src1, sampler, pos).x); + IMAGE_dst_PIXEL_TYPE value2 = CONVERT_dst_PIXEL_TYPE(READ_src2_IMAGE(src2, sampler, pos).x); + if ( value1 != 0 || value2 != 0 ) { + value1 = 1; + } else { + value1 = 0; + } + WRITE_dst_IMAGE (dst, pos, value1); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/binary_subtract_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/binary_subtract_2d_x.cl new file mode 100644 index 0000000..95e8c1c --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/binary_subtract_2d_x.cl @@ -0,0 +1,22 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void binary_subtract_2d +( + IMAGE_dst_TYPE dst, IMAGE_src1_TYPE src1, IMAGE_src2_TYPE src2 +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float value1 = READ_src1_IMAGE(src1, sampler, pos).x; + if (value1 != 0) { + float value2 = READ_src2_IMAGE(src2, sampler, pos).x; + if (value2 != 0) { + value1 = 0; + } + } + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value1)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/binary_subtract_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/binary_subtract_3d_x.cl new file mode 100644 index 0000000..93bf97c --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/binary_subtract_3d_x.cl @@ -0,0 +1,23 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void binary_subtract_3d +( + IMAGE_dst_TYPE dst, IMAGE_src1_TYPE src1, IMAGE_src2_TYPE src2 +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float value1 = READ_src1_IMAGE(src1, sampler, pos).x; + if (value1 != 0) { + float value2 = READ_src2_IMAGE(src2, sampler, pos).x; + if (value2 != 0) { + value1 = 0; + } + } + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value1)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/binary_xor_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/binary_xor_2d_x.cl new file mode 100644 index 0000000..c77aed4 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/binary_xor_2d_x.cl @@ -0,0 +1,23 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void binary_xor_2d( + IMAGE_src1_TYPE src1, + IMAGE_src2_TYPE src2, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + IMAGE_dst_PIXEL_TYPE value1 = CONVERT_dst_PIXEL_TYPE(READ_src1_IMAGE(src1, sampler, pos).x); + IMAGE_dst_PIXEL_TYPE value2 = CONVERT_dst_PIXEL_TYPE(READ_src2_IMAGE(src2, sampler, pos).x); + if ( (value1 != 0 && value2 == 0) || (value1 == 0 && value2 != 0)) { + value1 = 1; + } else { + value1 = 0; + } + WRITE_dst_IMAGE (dst, pos, value1); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/binary_xor_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/binary_xor_3d_x.cl new file mode 100644 index 0000000..217633a --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/binary_xor_3d_x.cl @@ -0,0 +1,23 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void binary_xor_3d( + IMAGE_src1_TYPE src1, + IMAGE_src2_TYPE src2, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + IMAGE_dst_PIXEL_TYPE value1 = CONVERT_dst_PIXEL_TYPE(READ_src1_IMAGE(src1, sampler, pos).x); + IMAGE_dst_PIXEL_TYPE value2 = CONVERT_dst_PIXEL_TYPE(READ_src2_IMAGE(src2, sampler, pos).x); + if ( (value1 != 0 && value2 == 0) || (value1 == 0 && value2 != 0)) { + value1 = 1; + } else { + value1 = 0; + } + WRITE_dst_IMAGE (dst, pos, value1); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/blur.cl b/src/main/java/net/haesleinhuepf/clij/kernels/blur.cl deleted file mode 100644 index d72f2b1..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/blur.cl +++ /dev/null @@ -1,186 +0,0 @@ -// Adapted from Uwe Schmidt, https://github.com/ClearControl/FastFuse/blob/master/src/fastfuse/tasks/kernels/blur.cl -// - -__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - -__kernel void gaussian_blur_image3d -( - DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src, - const int Nx, const int Ny, const int Nz, - const float sx, const float sy, const float sz -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4)(i,j,k,0); - - // centers - const int4 c = (int4) ( (Nx-1)/2, (Ny-1)/2, (Nz-1)/2, 0 ); - // normalizations - const float4 n = (float4)( -2*sx*sx, -2*sy*sy, -2*sz*sz, 0 ); - - float res = 0, hsum = 0; - - for (int x = -c.x; x <= c.x; x++) { - const float wx = (x*x) / n.x; - for (int y = -c.y; y <= c.y; y++) { - const float wy = (y*y) / n.y; - for (int z = -c.z; z <= c.z; z++) { - const float wz = (z*z) / n.z; - const float h = exp(wx + wy + wz); - res += h * (float)READ_IMAGE_3D(src,sampler,coord+(int4)(x,y,z,0)).x; - hsum += h; - } - } - } - - res /= hsum; - WRITE_IMAGE_3D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - - -__kernel void gaussian_blur_slicewise_image3d -( - DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src, - const int Nx, const int Ny, - const float sx, const float sy -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4)(i,j,k,0); - - // centers - const int4 c = (int4) ( (Nx-1)/2, (Ny-1)/2, 0, 0 ); - // normalizations - const float4 n = (float4)( -2*sx*sx, -2*sy*sy, 0, 0 ); - - float res = 0, hsum = 0; - - for (int x = -c.x; x <= c.x; x++) { - const float wx = (x*x) / n.x; - for (int y = -c.y; y <= c.y; y++) { - const float wy = (y*y) / n.y; - const float h = exp(wx + wy); - res += h * (float)READ_IMAGE_3D(src,sampler,coord+(int4)(x,y,0,0)).x; - hsum += h; - } - } - - res /= hsum; - WRITE_IMAGE_3D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - -__kernel void gaussian_blur_image2d -( - DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src, - const int Nx, const int Ny, - const float sx, const float sy -) -{ - const int i = get_global_id(0), j = get_global_id(1); - const int2 coord = (int2)(i,j); - - // centers - const int2 c = (int2) ( (Nx-1)/2, (Ny-1)/2 ); - // normalizations - const float2 n = (float2)( -2*sx*sx, -2*sy*sy); - - float res = 0, hsum = 0; - - for (int x = -c.x; x <= c.x; x++) { - const float wx = (x*x) / n.x; - for (int y = -c.y; y <= c.y; y++) { - const float wy = (y*y) / n.y; - const float h = exp(wx + wy); - res += h * (float)READ_IMAGE_2D(src,sampler,coord+(int2)(x,y)).x; - hsum += h; - } - } - - res /= hsum; - WRITE_IMAGE_2D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - -__kernel void gaussian_blur_image2d_ij -( - DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src, - const int Nx, const int Ny, - const float sx, const float sy -) -{ - const int i = get_global_id(0), j = get_global_id(1); - const int2 coord = (int2)(i,j); - - // centers - const int2 c = (int2) ( (Nx-1)/2, (Ny-1)/2 ); - // normalizations - const float2 n = (float2)( -2*sx*sx, -2*sy*sy); - - float res = 0, hsum = 0; - - for (int x = -c.x; x <= c.x; x++) { - const float wx = (x*x) / n.x; - for (int y = -c.y; y <= c.y; y++) { - const float wy = (y*y) / n.y; - const float h = exp(wx + wy); - res += h * (float)READ_IMAGE_2D(src,sampler,coord+(int2)(x,y)).x; - hsum += h; - } - } - - res /= hsum; - WRITE_IMAGE_2D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - -__kernel void gaussian_blur_sep_image3d -( - DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src, - const int dim, const int N, const float s -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4)(i,j,k,0); - const int4 dir = (int4)(dim==0,dim==1,dim==2,0); - - // center - const int c = (N-1)/2; - // normalization - const float n = -2*s*s; - - float res = 0, hsum = 0; - for (int v = -c; v <= c; v++) { - const float h = exp((v*v)/n); - res += h * (float)READ_IMAGE_3D(src,sampler,coord+v*dir).x; - hsum += h; - } - res /= hsum; - WRITE_IMAGE_3D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - - -__kernel void gaussian_blur_sep_image2d -( - DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src, - const int dim, const int N, const float s -) -{ - const int i = get_global_id(0), j = get_global_id(1); - const int2 coord = (int2)(i,j); - const int2 dir = (int2)(dim==0,dim==1); - - // center - const int c = (N-1)/2; - // normalization - const float n = -2*s*s; - - float res = 0, hsum = 0; - for (int v = -c; v <= c; v++) { - const float h = exp((v*v)/n); - res += h * (float)READ_IMAGE_2D(src,sampler,coord+v*dir).x; - hsum += h; - } - res /= hsum; - WRITE_IMAGE_2D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - - diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/convolve_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/convolve_2d_x.cl new file mode 100644 index 0000000..c95dee0 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/convolve_2d_x.cl @@ -0,0 +1,31 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + +__kernel void convolve_2d( + IMAGE_src_TYPE src, + IMAGE_kernelImage_TYPE kernelImage, + IMAGE_dst_TYPE dst +) { + const int i = get_global_id(0); + const int j = get_global_id(1); + + int2 coord = (int2){i, j}; + + const int kernelWidth = GET_IMAGE_WIDTH(kernelImage); + const int kernelHeight = GET_IMAGE_HEIGHT(kernelImage); + + int2 c = (int2){kernelWidth / 2, kernelHeight / 2}; + + float sum = 0; + for (int x = -c.x; x <= c.x; x++) { + for (int y = -c.y; y <= c.y; y++) { + int2 kernelCoord = c + (int2)(x,y); + int2 imageCoord = coord+(int2)(x,y); + sum = sum + ((float)READ_IMAGE(kernelImage,sampler,kernelCoord).x + * (float)READ_IMAGE(src,sampler,imageCoord).x); + } + } + WRITE_IMAGE(dst,coord,CONVERT_dst_PIXEL_TYPE(sum)); +} + + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/convolve_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/convolve_3d_x.cl new file mode 100644 index 0000000..7bf61c1 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/convolve_3d_x.cl @@ -0,0 +1,34 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + +__kernel void convolve_3d( + IMAGE_src_TYPE src, + IMAGE_kernelImage_TYPE kernelImage, + IMAGE_dst_TYPE dst +) { + const int i = get_global_id(0); + const int j = get_global_id(1); + const int k = get_global_id(2); + + int4 coord = (int4){i, j, k, 0}; + + const int kernelWidth = GET_IMAGE_WIDTH(kernelImage); + const int kernelHeight = GET_IMAGE_HEIGHT(kernelImage); + const int kernelDepth = GET_IMAGE_DEPTH(kernelImage); + + int4 c = (int4){kernelWidth / 2, kernelHeight / 2, kernelDepth / 2, 0}; + + float sum = 0; + for (int x = -c.x; x <= c.x; x++) { + for (int y = -c.y; y <= c.y; y++) { + for (int z = -c.z; z <= c.z; z++) { + int4 kernelCoord = c + (int4)(x,y,z,0); + int4 imageCoord = coord+(int4)(x,y,z,0); + sum = sum + (float)READ_IMAGE(kernelImage,sampler,kernelCoord).x + * (float)READ_IMAGE(src,sampler,imageCoord).x; + } + } + } + + WRITE_IMAGE(dst,coord, CONVERT_dst_PIXEL_TYPE(sum)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/copy_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/copy_2d_x.cl new file mode 100644 index 0000000..a6168e3 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/copy_2d_x.cl @@ -0,0 +1,15 @@ +__kernel void copy_2d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int dx = get_global_id(0); + const int dy = get_global_id(1); + + + const int2 pos = (int2){dx,dy}; + + const float out = READ_src_IMAGE(src,sampler,pos).x; + WRITE_dst_IMAGE(dst,pos, CONVERT_dst_PIXEL_TYPE(out)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/copy_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/copy_3d_x.cl new file mode 100644 index 0000000..0165713 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/copy_3d_x.cl @@ -0,0 +1,15 @@ +__kernel void copy_3d ( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int dx = get_global_id(0); + const int dy = get_global_id(1); + const int dz = get_global_id(2); + + const int4 pos = (int4){dx,dy,dz,0}; + + const float out = READ_src_IMAGE(src,sampler,pos).x; + WRITE_dst_IMAGE(dst, pos, CONVERT_dst_PIXEL_TYPE(out)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/copy_slice_from_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/copy_slice_from_3d_x.cl new file mode 100644 index 0000000..c577cef --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/copy_slice_from_3d_x.cl @@ -0,0 +1,17 @@ + +__kernel void copy_slice_from_3d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + int slice +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int dx = get_global_id(0); + const int dy = get_global_id(1); + + const int4 pos4 = (int4){dx,dy,slice,0}; + const int2 pos2 = (int2){dx,dy}; + + const float out = READ_src_IMAGE(src,sampler,pos4).x; + WRITE_dst_IMAGE(dst,pos2, CONVERT_dst_PIXEL_TYPE(out)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/copy_slice_to_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/copy_slice_to_3d_x.cl new file mode 100644 index 0000000..5129c88 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/copy_slice_to_3d_x.cl @@ -0,0 +1,17 @@ + +__kernel void copy_slice_to_3d ( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + int slice +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int dx = get_global_id(0); + const int dy = get_global_id(1); + + const int2 pos2 = (int2){dx,dy}; + const int4 pos4 = (int4){dx,dy,slice,0}; + + const float out = READ_src_IMAGE(src,sampler,pos2).x; + WRITE_dst_IMAGE(dst,pos4, CONVERT_dst_PIXEL_TYPE(out)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/count_non_zero_projection_3d_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/count_non_zero_projection_3d_2d_x.cl new file mode 100644 index 0000000..6414df1 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/count_non_zero_projection_3d_2d_x.cl @@ -0,0 +1,21 @@ +__kernel void count_non_zero_projection_3d_2d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + float tolerance +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + float count = 0; + for(int z = 0; z < GET_IMAGE_DEPTH(src); z++) + { + POS_src_TYPE pos = POS_src_INSTANCE(x,y,z,0); + float value = READ_src_IMAGE(src,sampler,pos).x; + if (value > tolerance || value < -tolerance) { + count = count + 1; + } + } + POS_dst_TYPE pos2 = POS_dst_INSTANCE(x,y,0,0); + WRITE_dst_IMAGE(dst, pos2, CONVERT_dst_PIXEL_TYPE(count)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/count_nonzero_pixels_slice_by_slice_sphere_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/count_nonzero_pixels_slice_by_slice_sphere_3d_x.cl new file mode 100644 index 0000000..52e9bfa --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/count_nonzero_pixels_slice_by_slice_sphere_3d_x.cl @@ -0,0 +1,44 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void count_nonzero_pixels_slice_by_slice_sphere_3d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int Nx, + const int Ny +) +{ + const int i = get_global_id(0); + const int j = get_global_id(1); + const int k = get_global_id(2); + + const POS_src_TYPE coord = POS_dst_INSTANCE(i,j,k,0); + const POS_dst_TYPE dcoord = POS_dst_INSTANCE(i,j,k,0); + + const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, 0, 0 }; + + float aSquared = e.x * e.x; + float bSquared = e.y * e.y; + if (aSquared == 0) { + aSquared = FLT_MIN; + } + if (bSquared == 0) { + bSquared = FLT_MIN; + } + int count = 0; + + for (int x = -e.x; x <= e.x; x++) { + float xSquared = x * x; + for (int y = -e.y; y <= e.y; y++) { + float ySquared = y * y; + if (xSquared / aSquared + ySquared / bSquared <= 1.0) { + float value = (float)READ_src_IMAGE(src,sampler,coord+(POS_src_INSTANCE(x,y,k,0))).x; + if (value != 0) { + count++; + } + } + } + } + + WRITE_dst_IMAGE(dst, coord, CONVERT_dst_PIXEL_TYPE(count)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/count_nonzero_pixels_sphere_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/count_nonzero_pixels_sphere_2d_x.cl new file mode 100644 index 0000000..60a31e3 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/count_nonzero_pixels_sphere_2d_x.cl @@ -0,0 +1,43 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void count_nonzero_pixels_sphere_2d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int Nx, + const int Ny +) +{ + const int i = get_global_id(0); + const int j = get_global_id(1); + const POS_src_TYPE coord = POS_src_INSTANCE(i,j,0,0); + const POS_dst_TYPE dcoord = POS_dst_INSTANCE(i,j,0,0); + + const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, 0, 0 }; + int count = 0; + + float aSquared = e.x * e.x; + float bSquared = e.y * e.y; + if (aSquared == 0) { + aSquared = FLT_MIN; + } + if (bSquared == 0) { + bSquared = FLT_MIN; + } + + for (int x = -e.x; x <= e.x; x++) { + float xSquared = x * x; + for (int y = -e.y; y <= e.y; y++) { + float ySquared = y * y; + if (xSquared / aSquared + ySquared / bSquared <= 1.0) { + float value = (float)READ_IMAGE(src,sampler,coord+(POS_src_INSTANCE(x, y, 0, 0))).x; + if (value != 0) { + count++; + } + } + } + } + + + WRITE_IMAGE(dst, dcoord, CONVERT_dst_PIXEL_TYPE(count)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/count_nonzero_voxels_sphere_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/count_nonzero_voxels_sphere_3d_x.cl new file mode 100644 index 0000000..d114fcb --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/count_nonzero_voxels_sphere_3d_x.cl @@ -0,0 +1,68 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void count_nonzero_voxels_sphere_3d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int Nx, + const int Ny, + const int Nz +) +{ + const int i = get_global_id(0); + const int j = get_global_id(1); + const int k = get_global_id(2); + + const POS_dst_TYPE coord = POS_dst_INSTANCE(i,j,k,0); + + const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, (Nz-1)/2, 0 }; + int count = 0; + + float aSquared = e.x * e.x; + float bSquared = e.y * e.y; + float cSquared = e.z * e.z; + if (aSquared == 0) { + aSquared = FLT_MIN; + } + if (bSquared == 0) { + bSquared = FLT_MIN; + } + if (cSquared == 0) { + cSquared = FLT_MIN; + } + + for (int x = -e.x; x <= e.x; x++) { + float xSquared = x * x; + for (int y = -e.y; y <= e.y; y++) { + float ySquared = y * y; + for (int z = -e.z; z <= e.z; z++) { + float zSquared = z * z; + if (xSquared / aSquared + ySquared / bSquared + zSquared / cSquared <= 1.0) { + + int x1 = coord.x + x; + int x2 = coord.y + y; + int x3 = coord.z + z; + const POS_src_TYPE pos = POS_src_INSTANCE(x1,x2,x3,0); + float value_res = (float)READ_src_IMAGE(src,sampler,pos).x; + if (value_res != 0) { + count++; + } + } + } + } + } + + + WRITE_dst_IMAGE(dst, coord, CONVERT_dst_PIXEL_TYPE(count)); +} + + + + + + + + + + + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/count_touching_neighbors_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/count_touching_neighbors_x.cl new file mode 100644 index 0000000..0bb1e72 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/count_touching_neighbors_x.cl @@ -0,0 +1,31 @@ + +__kernel void count_touching_neighbors ( +IMAGE_src_touch_matrix_TYPE src_touch_matrix, +IMAGE_dst_count_list_TYPE dst_count_list +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int label_id = get_global_id(0); + const int label_count = get_global_size(0); + + int count = 0; + + int y = label_id; + int x = 0; + for (x = 0; x < label_id; x++) { + float value = READ_src_touch_matrix_IMAGE(src_touch_matrix, sampler, POS_src_touch_matrix_INSTANCE(x, y, 0, 0)).x; + if (value > 0) { + count++; + } + } + x = label_id; + for (y = label_id + 1; y < label_count; y++) { + float value = READ_src_touch_matrix_IMAGE(src_touch_matrix, sampler, POS_src_touch_matrix_INSTANCE(x, y, 0, 0)).x; + if (value > 0) { + count++; + } + } + + WRITE_dst_count_list_IMAGE(dst_count_list, (POS_dst_count_list_INSTANCE(label_id, 0, 0, 0)), CONVERT_dst_count_list_PIXEL_TYPE(count)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/crop_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/crop_2d_x.cl new file mode 100644 index 0000000..a27c6f9 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/crop_2d_x.cl @@ -0,0 +1,22 @@ +__kernel void crop_2d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + int start_x, + int start_y +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int dx = get_global_id(0); + const int dy = get_global_id(1); + + const int sx = start_x + dx; + const int sy = start_y + dy; + + + const POS_dst_TYPE dpos = POS_dst_INSTANCE(dx, dy, 0, 0); + const POS_src_TYPE spos = POS_src_INSTANCE(sx, sy, 0, 0); + + const float out = READ_src_IMAGE(src,sampler,spos).x; + WRITE_dst_IMAGE(dst,dpos, CONVERT_dst_PIXEL_TYPE(out)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/crop_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/crop_3d_x.cl new file mode 100644 index 0000000..35f3fe2 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/crop_3d_x.cl @@ -0,0 +1,25 @@ + +__kernel void crop_3d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + int start_x, + int start_y, + int start_z +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int dx = get_global_id(0); + const int dy = get_global_id(1); + const int dz = get_global_id(2); + + + const int sx = start_x + dx; + const int sy = start_y + dy; + const int sz = start_z + dz; + + const POS_dst_TYPE dpos = POS_dst_INSTANCE(dx, dy, dz, 0); + const POS_src_TYPE spos = POS_src_INSTANCE(sx, sy, sz, 0); + + const float out = READ_src_IMAGE(src,sampler,spos).x; + WRITE_dst_IMAGE(dst,dpos, CONVERT_dst_PIXEL_TYPE(out)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/deform.cl b/src/main/java/net/haesleinhuepf/clij/kernels/deform.cl deleted file mode 100644 index 9ef5300..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/deform.cl +++ /dev/null @@ -1,89 +0,0 @@ - -#ifndef SAMPLER_FILTER -#define SAMPLER_FILTER CLK_FILTER_LINEAR -#endif - -#ifndef SAMPLER_ADDRESS -#define SAMPLER_ADDRESS CLK_ADDRESS_CLAMP -#endif - -__kernel void deform_3d(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_IN_3D vectorX, - DTYPE_IMAGE_IN_3D vectorY, - DTYPE_IMAGE_IN_3D vectorZ, - DTYPE_IMAGE_OUT_3D dst) -{ - const sampler_t sampler = CLK_NORMALIZED_COORDS_TRUE| - SAMPLER_ADDRESS | SAMPLER_FILTER; - - uint i = get_global_id(0); - uint j = get_global_id(1); - uint k = get_global_id(2); - - uint Nx = get_global_size(0); - uint Ny = get_global_size(1); - uint Nz = get_global_size(2); - - float x = i+0.5f; - float y = j+0.5f; - float z = k+0.5f; - - int4 pos = (int4){i, j, k,0}; - - float x2 = x + (float)(READ_IMAGE_3D(vectorX, sampler, pos).x); - float y2 = y + (float)(READ_IMAGE_3D(vectorY, sampler, pos).x); - float z2 = z + (float)(READ_IMAGE_3D(vectorZ, sampler, pos).x); - - - //int4 coord_norm = (int4)(x2 * GET_IMAGE_WIDTH(input) / GET_IMAGE_WIDTH(output),y2 * GET_IMAGE_HEIGHT(input) / GET_IMAGE_HEIGHT(output), z2 * GET_IMAGE_DEPTH(input) / GET_IMAGE_DEPTH(output),0.f); - int4 coord_norm = (int4)(x2,y2, z2,0.f); - - - - float pix = 0; - if (x2 >= 0 && y2 >= 0 && z2 >= 0 && - x2 < GET_IMAGE_WIDTH(src) && y2 < GET_IMAGE_HEIGHT(src) && z2 < GET_IMAGE_DEPTH(src) - ) { - pix = (float)(READ_IMAGE_3D(src, sampler, coord_norm).x); - } - - WRITE_IMAGE_3D(dst, pos, CONVERT_DTYPE_OUT(pix)); -} - - -__kernel void deform_2d(DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_IN_2D vectorX, - DTYPE_IMAGE_IN_2D vectorY, - DTYPE_IMAGE_OUT_2D dst) -{ - const sampler_t sampler = CLK_NORMALIZED_COORDS_TRUE| - SAMPLER_ADDRESS | SAMPLER_FILTER; - - uint i = get_global_id(0); - uint j = get_global_id(1); - - uint Nx = get_global_size(0); - uint Ny = get_global_size(1); - - float x = i+0.5f; - float y = j+0.5f; - - - int2 pos = (int2){i, j}; - - float x2 = x + (float)(READ_IMAGE_2D(vectorX, sampler, pos).x); - float y2 = y + (float)(READ_IMAGE_2D(vectorY, sampler, pos).x); - - - int2 coord_norm = (int2)(x2, y2); - - float pix = 0; - if (x2 >= 0 && y2 >= 0 && - x2 < GET_IMAGE_WIDTH(src) && y2 < GET_IMAGE_HEIGHT(src) - ) { - pix = (float)(READ_IMAGE_2D(src, sampler, coord_norm).x); - } - - - WRITE_IMAGE_2D(dst, pos, CONVERT_DTYPE_OUT(pix)); -} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/deform_interpolate.cl b/src/main/java/net/haesleinhuepf/clij/kernels/deform_interpolate.cl deleted file mode 100644 index 9b02bb4..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/deform_interpolate.cl +++ /dev/null @@ -1,89 +0,0 @@ - -#ifndef SAMPLER_FILTER -#define SAMPLER_FILTER CLK_FILTER_LINEAR -#endif - -#ifndef SAMPLER_ADDRESS -#define SAMPLER_ADDRESS CLK_ADDRESS_CLAMP -#endif - -__kernel void deform_3d_interpolate(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_IN_3D vectorX, - DTYPE_IMAGE_IN_3D vectorY, - DTYPE_IMAGE_IN_3D vectorZ, - DTYPE_IMAGE_OUT_3D dst) -{ - const sampler_t sampler = CLK_NORMALIZED_COORDS_TRUE| - SAMPLER_ADDRESS | SAMPLER_FILTER; - - uint i = get_global_id(0); - uint j = get_global_id(1); - uint k = get_global_id(2); - - uint Nx = GET_IMAGE_WIDTH(src); - uint Ny = GET_IMAGE_HEIGHT(src); - uint Nz = GET_IMAGE_DEPTH(src); - - float x = i+0.5f; - float y = j+0.5f; - float z = k+0.5f; - - int4 pos = (int4){i, j, k,0}; - - float x2 = x + (float)(READ_IMAGE_3D(vectorX, sampler, pos).x); - float y2 = y + (float)(READ_IMAGE_3D(vectorY, sampler, pos).x); - float z2 = z + (float)(READ_IMAGE_3D(vectorZ, sampler, pos).x); - - - //int4 coord_norm = (int4)(x2 * GET_IMAGE_WIDTH(input) / GET_IMAGE_WIDTH(output),y2 * GET_IMAGE_HEIGHT(input) / GET_IMAGE_HEIGHT(output), z2 * GET_IMAGE_DEPTH(input) / GET_IMAGE_DEPTH(output),0.f); - float4 coord_norm = (float4)(x2 / Nx, y2 / Ny, z2 / Nz,0.f); - - - - float pix = 0; - if (x2 >= 0 && y2 >= 0 && z2 >= 0 && - x2 < GET_IMAGE_WIDTH(src) && y2 < GET_IMAGE_HEIGHT(src) && z2 < GET_IMAGE_DEPTH(src) - ) { - pix = (float)(READ_IMAGE_3D(src, sampler, coord_norm).x); - } - - WRITE_IMAGE_3D(dst, pos, CONVERT_DTYPE_OUT(pix)); -} - - -__kernel void deform_2d_interpolate(DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_IN_2D vectorX, - DTYPE_IMAGE_IN_2D vectorY, - DTYPE_IMAGE_OUT_2D dst) -{ - const sampler_t sampler = CLK_NORMALIZED_COORDS_TRUE| - SAMPLER_ADDRESS | SAMPLER_FILTER; - - uint i = get_global_id(0); - uint j = get_global_id(1); - - uint Nx = GET_IMAGE_WIDTH(src); - uint Ny = GET_IMAGE_HEIGHT(src); - - float x = i+0.5f; - float y = j+0.5f; - - - int2 pos = (int2){i, j}; - - float x2 = x + (float)(READ_IMAGE_2D(vectorX, sampler, pos).x); - float y2 = y + (float)(READ_IMAGE_2D(vectorY, sampler, pos).x); - - - float2 coord_norm = (float2)(x2 / Nx, y2 / Ny); - - float pix = 0; - if (x2 >= 0 && y2 >= 0 && - x2 < GET_IMAGE_WIDTH(src) && y2 < GET_IMAGE_HEIGHT(src) - ) { - pix = (float)(READ_IMAGE_2D(src, sampler, coord_norm).x); - } - - - WRITE_IMAGE_2D(dst, pos, CONVERT_DTYPE_OUT(pix)); -} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/depth_projection_interpolation_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/depth_projection_interpolation_x.cl new file mode 100644 index 0000000..e6e7cdb --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/depth_projection_interpolation_x.cl @@ -0,0 +1,56 @@ + +__kernel void depth_projection( + IMAGE_dst_depth_TYPE dst_depth, + IMAGE_src_TYPE src, + IMAGE_lut_TYPE lut, + float min_display_intensity, + float max_display_intensity +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_LINEAR; + //CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + float max = 0; + float max_z = 0; + + for(float z = 0; z < GET_IMAGE_DEPTH(src); z += GET_IMAGE_DEPTH(src) / 255.0 ) + { + float value = READ_IMAGE(src,sampler,(float4)(x, y,z,0)).x; + if (value > max || z == 0) { + max = value; + max_z = z; + } + } + + float intensity = (max - min_display_intensity) / (max_display_intensity - min_display_intensity); + float relative_z = max_z / (GET_IMAGE_DEPTH(src)-1); + + if (intensity < 0) { + intensity = 0; + } + if (intensity > 1) { + intensity = 1; + } + if (relative_z < 0) { + relative_z = 0; + } + if (relative_z > 1) { + relative_z = 1; + } + + int lookup_index = 255.0 * relative_z; + //if (x == 255 && y == 255) { + // printf("gello %f \n", intensity ); + // printf("gello %f \n", relative_z ); + // printf("gello %d \n", lookup_index ); + //} + + float r = READ_IMAGE(lut, sampler, (int4)(lookup_index, 0, 0, 0)).x * intensity; + float g = READ_IMAGE(lut, sampler, (int4)(lookup_index, 0, 1, 0)).x * intensity; + float b = READ_IMAGE(lut, sampler, (int4)(lookup_index, 0, 2, 0)).x * intensity; + + WRITE_IMAGE(dst_depth,POS_dst_depth_INSTANCE(x, y, 0, 0), CONVERT_dst_depth_PIXEL_TYPE(r)); + WRITE_IMAGE(dst_depth,POS_dst_depth_INSTANCE(x, y, 1, 0), CONVERT_dst_depth_PIXEL_TYPE(g)); + WRITE_IMAGE(dst_depth,POS_dst_depth_INSTANCE(x, y, 2, 0), CONVERT_dst_depth_PIXEL_TYPE(b)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/depth_projection_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/depth_projection_x.cl new file mode 100644 index 0000000..79e34d9 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/depth_projection_x.cl @@ -0,0 +1,55 @@ + +__kernel void depth_projection( + IMAGE_dst_depth_TYPE dst_depth, + IMAGE_src_TYPE src, + IMAGE_lut_TYPE lut, + float min_display_intensity, + float max_display_intensity +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + float max = 0; + float max_z = 0; + + for(float z = 0; z < GET_IMAGE_DEPTH(src); z += GET_IMAGE_DEPTH(src) / 255.0 ) + { + float value = READ_IMAGE(src,sampler,(int4)(x,y,z,0)).x; + if (value > max || z == 0) { + max = value; + max_z = z; + } + } + + float intensity = (max - min_display_intensity) / (max_display_intensity - min_display_intensity); + float relative_z = max_z / (GET_IMAGE_DEPTH(src)-1); + + if (intensity < 0) { + intensity = 0; + } + if (intensity > 1) { + intensity = 1; + } + if (relative_z < 0) { + relative_z = 0; + } + if (relative_z > 1) { + relative_z = 1; + } + + int lookup_index = 255.0 * relative_z; + //if (x == 255 && y == 255) { + // printf("gello %f \n", intensity ); + // printf("gello %f \n", relative_z ); + // printf("gello %d \n", lookup_index ); + //} + + float r = READ_IMAGE(lut, sampler, (int4)(lookup_index, 0, 0, 0)).x * intensity; + float g = READ_IMAGE(lut, sampler, (int4)(lookup_index, 0, 1, 0)).x * intensity; + float b = READ_IMAGE(lut, sampler, (int4)(lookup_index, 0, 2, 0)).x * intensity; + + WRITE_IMAGE(dst_depth,POS_dst_depth_INSTANCE(x, y, 0, 0), CONVERT_dst_depth_PIXEL_TYPE(r)); + WRITE_IMAGE(dst_depth,POS_dst_depth_INSTANCE(x, y, 1, 0), CONVERT_dst_depth_PIXEL_TYPE(g)); + WRITE_IMAGE(dst_depth,POS_dst_depth_INSTANCE(x, y, 2, 0), CONVERT_dst_depth_PIXEL_TYPE(b)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/detect_label_edges_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/detect_label_edges_2d_x.cl new file mode 100644 index 0000000..91d5a24 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/detect_label_edges_2d_x.cl @@ -0,0 +1,37 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void detect_label_edges_diamond_2d +( + IMAGE_src_label_map_TYPE src_label_map, IMAGE_dst_edge_image_TYPE dst_edge_image +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float center = READ_src_label_map_IMAGE(src_label_map, sampler, pos).x; + float valueToWrite = 0; + float value = READ_src_label_map_IMAGE(src_label_map, sampler, (pos + (int2){-1, 0})).x; + if ( value != center) { + valueToWrite = 1; + } else { + value = READ_src_label_map_IMAGE(src_label_map, sampler, (pos + (int2){0, -1})).x; + if ( value != center ) { + valueToWrite = 1; + } else { + value = READ_src_label_map_IMAGE(src_label_map, sampler, (pos + (int2){1, 0})).x; + if ( value != center ) { + valueToWrite = 1; + } else { + value = READ_src_label_map_IMAGE(src_label_map, sampler, (pos + (int2){0, 1})).x; + if ( value != center ) { + valueToWrite = 1; + } + } + } + } + + WRITE_dst_edge_image_IMAGE (dst_edge_image, pos, CONVERT_dst_edge_image_PIXEL_TYPE(valueToWrite)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/detect_label_edges_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/detect_label_edges_3d_x.cl new file mode 100644 index 0000000..93328e1 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/detect_label_edges_3d_x.cl @@ -0,0 +1,48 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void detect_label_edges_diamond_3d +( + IMAGE_src_label_map_TYPE src_label_map, IMAGE_dst_edge_image_TYPE dst_edge_image +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float center = READ_src_label_map_IMAGE(src_label_map, sampler, pos).x; + float valueToWrite = 0; + + float value = READ_src_label_map_IMAGE(src_label_map, sampler, (pos + (int4){-1, 0, 0, 0})).x; + if ( value != center) { + valueToWrite = 1; + } else { + value = READ_src_label_map_IMAGE(src_label_map, sampler, (pos + (int4){0, -1, 0, 0})).x; + if ( value != center ) { + valueToWrite = 1; + } else { + value = READ_src_label_map_IMAGE(src_label_map, sampler, (pos + (int4){0, 0, -1, 0})).x; + if ( value != center ) { + valueToWrite = 1; + } else { + value = READ_src_label_map_IMAGE(src_label_map, sampler, (pos + (int4){1, 0, 0, 0})).x; + if ( value != center ) { + valueToWrite = 1; + } else { + value = READ_src_label_map_IMAGE(src_label_map, sampler, (pos + (int4){0, 1, 0, 0})).x; + if ( value != center ) { + valueToWrite = 1; + } else { + value = READ_src_label_map_IMAGE(src_label_map, sampler, (pos + (int4){0, 0, 1, 0})).x; + if ( value != center ) { + valueToWrite = 1; + } + } + } + } + } + } + WRITE_dst_edge_image_IMAGE (dst_edge_image, pos, CONVERT_dst_edge_image_PIXEL_TYPE(valueToWrite)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/detect_maxima_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/detect_maxima_2d_x.cl new file mode 100644 index 0000000..ba29309 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/detect_maxima_2d_x.cl @@ -0,0 +1,35 @@ + +__kernel void detect_maxima_2d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + int radius = 1; + + int2 pos = {get_global_id(0), get_global_id(1)}; + float localMax = READ_src_IMAGE(src, sampler, pos).x - 1; + int2 localMaxPos = pos; + + for(int x = -radius; x < radius + 1; x++) + { + for(int y = -radius; y < radius + 1; y++) + { + const int2 localPos = pos + (int2){ x, y}; + + float value = READ_src_IMAGE(src, sampler, localPos).x; + if (value > localMax) { + localMax = value; + localMaxPos = localPos; + } + + } + } + + if (pos.x == localMaxPos.x && pos.y == localMaxPos.y) { + WRITE_dst_IMAGE(dst, pos, 1); + } else { + WRITE_dst_IMAGE(dst, pos, 0); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/detect_maxima_3d_slice_by_slice_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/detect_maxima_3d_slice_by_slice_x.cl new file mode 100644 index 0000000..2146a46 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/detect_maxima_3d_slice_by_slice_x.cl @@ -0,0 +1,36 @@ + +__kernel void detect_maxima_3d_slice_by_slice( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + int radius = 1; + + int4 pos = {get_global_id(0), get_global_id(1), get_global_id(2), 0}; + float localMax = READ_src_IMAGE(src, sampler, pos).x - 1; + int4 localMaxPos = pos; + + for(int x = -radius; x < radius + 1; x++) + { + for(int y = -radius; y < radius + 1; y++) + { + int z = 0; + const int4 localPos = pos + (int4){ x, y, z, 0}; + + float value = READ_src_IMAGE(src, sampler, localPos).x; + + if (value > localMax) { + localMax = value; + localMaxPos = localPos; + } + } + } + + if (pos.x == localMaxPos.x && pos.y == localMaxPos.y) { + WRITE_dst_IMAGE(dst, pos, 1); + } else { + WRITE_dst_IMAGE(dst, pos, 0); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/detect_maxima_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/detect_maxima_3d_x.cl new file mode 100644 index 0000000..5f3dde7 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/detect_maxima_3d_x.cl @@ -0,0 +1,49 @@ + +__kernel void detect_maxima_3d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + int radius = 1; + + int i = get_global_id(0); + int j = get_global_id(1); + int k = get_global_id(2); + + if (i == 0 && j == 0 && k == 0) { + printf("size: %d\n", get_global_size(2)); + } + + POS_src_TYPE pos = POS_src_INSTANCE(i, j, k, 0); + float localMax = READ_src_IMAGE(src, sampler, pos).x - 1; + int4 localMaxPos = pos; + + for(int x = -radius; x < radius + 1; x++) + { + for(int y = -radius; y < radius + 1; y++) + { + for(int z = -radius; z < radius + 1; z++) + { + const POS_src_TYPE localPos = POS_src_INSTANCE( i + x, j + y, k + z, 0); + + float value = READ_src_IMAGE(src, sampler, localPos).x; + + + if (value > localMax) { + localMax = value; + localMaxPos = localPos; + } + } + } + } + + + POS_dst_TYPE dpos = POS_dst_INSTANCE(get_global_id(0), get_global_id(1), get_global_id(2), 0); + if (pos.x == localMaxPos.x && pos.y == localMaxPos.y && pos.z == localMaxPos.z) { + WRITE_dst_IMAGE(dst, dpos, 1); + } else { + WRITE_dst_IMAGE(dst, dpos, 0); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/detect_minima_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/detect_minima_2d_x.cl new file mode 100644 index 0000000..07a4104 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/detect_minima_2d_x.cl @@ -0,0 +1,35 @@ + +__kernel void detect_minima_2d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + int radius = 1; + + int2 pos = {get_global_id(0), get_global_id(1)}; + float localMin = READ_src_IMAGE(src, sampler, pos).x + 1; + int2 localMinPos = pos; + + for(int x = -radius; x < radius + 1; x++) + { + for(int y = -radius; y < radius + 1; y++) + { + const int2 localPos = pos + (int2){ x, y}; + + float value = READ_src_IMAGE(src, sampler, localPos).x; + + if (value < localMin) { + localMin = value; + localMinPos = localPos; + } + } + } + + if (pos.x == localMinPos.x && pos.y == localMinPos.y) { + WRITE_dst_IMAGE(dst, pos, 1); + } else { + WRITE_dst_IMAGE(dst, pos, 0); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/detect_minima_3d_slice_by_slice_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/detect_minima_3d_slice_by_slice_x.cl new file mode 100644 index 0000000..611da73 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/detect_minima_3d_slice_by_slice_x.cl @@ -0,0 +1,37 @@ + +__kernel void detect_minima_3d_slice_by_slice( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + int radius = 1; + + int4 pos = {get_global_id(0), get_global_id(1), get_global_id(2), 0}; + float localMin = READ_src_IMAGE(src, sampler, pos).x + 1; + int4 localMinPos = pos; + + for(int x = -radius; x < radius + 1; x++) + { + for(int y = -radius; y < radius + 1; y++) + { + int z = 0; + const int4 localPos = pos + (int4){ x, y, z, 0}; + + float value = READ_src_IMAGE(src, sampler, localPos).x; + + if (value < localMin) { + localMin = value; + localMinPos = localPos; + } + } + } + + if (pos.x == localMinPos.x && pos.y == localMinPos.y) { + WRITE_dst_IMAGE(dst, pos, 1); + } else { + WRITE_dst_IMAGE(dst, pos, 0); + } +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/detect_minima_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/detect_minima_3d_x.cl new file mode 100644 index 0000000..637bebd --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/detect_minima_3d_x.cl @@ -0,0 +1,39 @@ + +__kernel void detect_minima_3d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + int radius = 1; + + int4 pos = {get_global_id(0), get_global_id(1), get_global_id(2), 0}; + float localMin = READ_src_IMAGE(src, sampler, pos).x + 1; + int4 localMinPos = pos; + + for(int x = -radius; x < radius + 1; x++) + { + for(int y = -radius; y < radius + 1; y++) + { + for(int z = -radius; z < radius + 1; z++) + { + const int4 localPos = pos + (int4){ x, y, z, 0}; + + float value = READ_src_IMAGE(src, sampler, localPos).x; + + if (value < localMin) { + localMin = value; + localMinPos = localPos; + } + } + } + } + + if (pos.x == localMinPos.x && pos.y == localMinPos.y && pos.z == localMinPos.z) { + WRITE_dst_IMAGE(dst, pos, 1); + } else { + WRITE_dst_IMAGE(dst, pos, 0); + } +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/detection.cl b/src/main/java/net/haesleinhuepf/clij/kernels/detection.cl deleted file mode 100644 index 3376906..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/detection.cl +++ /dev/null @@ -1,132 +0,0 @@ - -__kernel void detect_local_optima_3d( - DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst, - __private int radius, - __private int detect_maxima -) -{ - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - int4 pos = {get_global_id(0), get_global_id(1), get_global_id(2), 0}; - float localMin = READ_IMAGE_3D(src, sampler, pos).x + 1; - float localMax = localMin - 2; - int4 localMinPos = pos; - int4 localMaxPos = pos; - - for(int x = -radius; x < radius + 1; x++) - { - for(int y = -radius; y < radius + 1; y++) - { - for(int z = -radius; z < radius + 1; z++) - { - const int4 localPos = pos + (int4){ x, y, z, 0}; - - float value = READ_IMAGE_3D(src, sampler, localPos).x; - - if (value < localMin) { - localMin = value; - localMinPos = localPos; - } - if (value > localMax) { - localMax = value; - localMaxPos = localPos; - } - } - } - } - - if ((detect_maxima == 1 && pos.x == localMaxPos.x && pos.y == localMaxPos.y && pos.z == localMaxPos.z) || - (pos.x == localMinPos.x && pos.y == localMinPos.y && pos.z == localMinPos.z)) { - WRITE_IMAGE_3D(dst, pos, ((DTYPE_OUT){1, 0, 0, 0})); - } else { - WRITE_IMAGE_3D(dst, pos, ((DTYPE_OUT){0, 0, 0, 0})); - } -} - - -__kernel void detect_local_optima_3d_slice_by_slice( - DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst, - __private int radius, - __private int detect_maxima -) -{ - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - int4 pos = {get_global_id(0), get_global_id(1), get_global_id(2), 0}; - float localMin = READ_IMAGE_3D(src, sampler, pos).x + 1; - float localMax = localMin - 2; - int4 localMinPos = pos; - int4 localMaxPos = pos; - - for(int x = -radius; x < radius + 1; x++) - { - for(int y = -radius; y < radius + 1; y++) - { - int z = 0; - const int4 localPos = pos + (int4){ x, y, z, 0}; - - float value = READ_IMAGE_3D(src, sampler, localPos).x; - - if (value < localMin) { - localMin = value; - localMinPos = localPos; - } - if (value > localMax) { - localMax = value; - localMaxPos = localPos; - } - } - } - - if ((detect_maxima == 1 && pos.x == localMaxPos.x && pos.y == localMaxPos.y) || - (pos.x == localMinPos.x && pos.y == localMinPos.y)) { - WRITE_IMAGE_3D(dst, pos, ((DTYPE_OUT){1, 0, 0, 0})); - } else { - WRITE_IMAGE_3D(dst, pos, ((DTYPE_OUT){0, 0, 0, 0})); - } -} - -__kernel void detect_local_optima_2d( - DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_OUT_2D dst, - __private int radius, - __private int detect_maxima -) -{ - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - int2 pos = {get_global_id(0), get_global_id(1)}; - float localMin = READ_IMAGE_2D(src, sampler, pos).x + 1; - float localMax = localMin - 2; - int2 localMinPos = pos; - int2 localMaxPos = pos; - - for(int x = -radius; x < radius + 1; x++) - { - for(int y = -radius; y < radius + 1; y++) - { - const int2 localPos = pos + (int2){ x, y}; - - float value = READ_IMAGE_2D(src, sampler, localPos).x; - - if (value < localMin) { - localMin = value; - localMinPos = localPos; - } - if (value > localMax) { - localMax = value; - localMaxPos = localPos; - } - - } - } - - if ((detect_maxima == 1 && pos.x == localMaxPos.x && pos.y == localMaxPos.y) || - (pos.x == localMinPos.x && pos.y == localMinPos.y)) { - WRITE_IMAGE_2D(dst, pos, ((DTYPE_OUT)1)); - } else { - WRITE_IMAGE_2D(dst, pos, ((DTYPE_OUT)0)); - } -} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/differenceOfGaussian.cl b/src/main/java/net/haesleinhuepf/clij/kernels/differenceOfGaussian.cl deleted file mode 100644 index 3f76c6b..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/differenceOfGaussian.cl +++ /dev/null @@ -1,146 +0,0 @@ - -__kernel void subtract_convolved_images_3d_fast( - DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst, - __private int radius, - __private float sigma_minuend, - __private float sigma_subtrahend -) -{ - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - int4 pos = {get_global_id(0), get_global_id(1), get_global_id(2), 0}; - - float sum_minuend = 0.0f; - float sum_subtrahend = 0.0f; - float weighted_sum_minuend = 0.0f; - float weighted_sum_subtrahend = 0.0f; - - for(int x = -radius; x < radius + 1; x++) - { - for(int y = -radius; y < radius + 1; y++) - { - for(int z = -radius; z < radius + 1; z++) - { - const int4 kernelPos = {x+radius, y+radius, z+radius, 0}; - const int4 imagePos = pos + (int4){ x, y, z, 0}; - - float image_pixel_value = READ_IMAGE_3D(src, sampler, imagePos).x; - - float weight_minuend = exp(-((float) (x * x + y * y + z * z) / (3.0f - * sigma_minuend - * sigma_minuend - * sigma_minuend))); - float weight_subtrahend = exp(-((float) (x * x + y * y + z * z) / (3.0f - * sigma_subtrahend - * sigma_subtrahend - * sigma_subtrahend))); - - weighted_sum_minuend += weight_minuend * image_pixel_value; - weighted_sum_subtrahend += weight_subtrahend * image_pixel_value; - - sum_minuend += weight_minuend; - sum_subtrahend += weight_subtrahend; - } - } - } - - float pix = weighted_sum_minuend / sum_minuend - weighted_sum_subtrahend / sum_subtrahend; //,0,0,0}; - WRITE_IMAGE_3D(dst, pos, CONVERT_DTYPE_OUT(pix)); -} - - -__kernel void subtract_convolved_images_3d_slice_by_slice( - DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst, - __private int radius, - __private float sigma_minuend, - __private float sigma_subtrahend -) -{ - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - int4 pos = {get_global_id(0), get_global_id(1), get_global_id(2), 0}; - - float sum_minuend = 0.0f; - float sum_subtrahend = 0.0f; - float weighted_sum_minuend = 0.0f; - float weighted_sum_subtrahend = 0.0f; - - for(int x = -radius; x < radius + 1; x++) - { - for(int y = -radius; y < radius + 1; y++) - { - int z = 0; - const int4 kernelPos = {x+radius, y+radius, z+radius, 0}; - const int4 imagePos = pos + (int4){ x, y, z, 0}; - - float image_pixel_value = READ_IMAGE_3D(src, sampler, imagePos).x; - - float weight_minuend = exp(-((float) (x * x + y * y + z * z) / (3.0f - * sigma_minuend - * sigma_minuend - * sigma_minuend))); - float weight_subtrahend = exp(-((float) (x * x + y * y + z * z) / (3.0f - * sigma_subtrahend - * sigma_subtrahend - * sigma_subtrahend))); - - weighted_sum_minuend += weight_minuend * image_pixel_value; - weighted_sum_subtrahend += weight_subtrahend * image_pixel_value; - - sum_minuend += weight_minuend; - sum_subtrahend += weight_subtrahend; - } - } - - float pix = weighted_sum_minuend / sum_minuend - weighted_sum_subtrahend / sum_subtrahend; - WRITE_IMAGE_3D(dst, pos, CONVERT_DTYPE_OUT(pix)); -} - -__kernel void subtract_convolved_images_2d_fast( - DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_OUT_2D dst, - __private int radius, - __private float sigma_minuend, - __private float sigma_subtrahend -) -{ - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - int2 pos = {get_global_id(0), get_global_id(1)}; - - float sum_minuend = 0.0f; - float sum_subtrahend = 0.0f; - float weighted_sum_minuend = 0.0f; - float weighted_sum_subtrahend = 0.0f; - - for(int x = -radius; x < radius + 1; x++) - { - for(int y = -radius; y < radius + 1; y++) - { - const int2 kernelPos = {x+radius, y+radius}; - const int2 imagePos = pos + (int2){ x, y}; - - float image_pixel_value = READ_IMAGE_2D(src, sampler, imagePos).x; - - float weight_minuend = exp(-((float) (x * x + y * y) / (2.0f - * sigma_minuend - * sigma_minuend))); - float weight_subtrahend = exp(-((float) (x * x + y * y) / (2.0f - * sigma_subtrahend - * sigma_subtrahend))); - - weighted_sum_minuend += weight_minuend * image_pixel_value; - weighted_sum_subtrahend += weight_subtrahend * image_pixel_value; - - sum_minuend += weight_minuend; - sum_subtrahend += weight_subtrahend; - - } - } - - float pix = weighted_sum_minuend / sum_minuend - weighted_sum_subtrahend / sum_subtrahend; //,0,0,0}; - WRITE_IMAGE_2D(dst, pos, CONVERT_DTYPE_OUT(pix)); -} - diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/dilate_box_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/dilate_box_2d_x.cl new file mode 100644 index 0000000..5c95060 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/dilate_box_2d_x.cl @@ -0,0 +1,32 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void dilate_box_2d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float value = READ_src_IMAGE(src, sampler, pos).x; + if (value == 0) { + for (int ax = -1; ax <= 1; ax++) { + for (int ay = -1; ay <= 1; ay++) { + value = READ_src_IMAGE(src, sampler, (pos + (int2){ax, ay})).x; + if (value != 0) { + break; + } + } + if (value != 0) { + break; + } + } + } + if (value != 0) { + value = 1; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/dilate_box_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/dilate_box_3d_x.cl new file mode 100644 index 0000000..8f48c10 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/dilate_box_3d_x.cl @@ -0,0 +1,38 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void dilate_box_3d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float value = READ_src_IMAGE(src, sampler, pos).x; + if (value < 1) { + for (int ax = -1; ax <= 1; ax++) { + for (int ay = -1; ay <= 1; ay++) { + for (int az = -1; az <= 1; az++) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){ax, ay, az, 0})).x; + if (value != 0) { + break; + } + } + if (value != 0) { + break; + } + } + if (value != 0) { + break; + } + } + } + if (value != 0) { + value = 1; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/dilate_box_slice_by_slice_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/dilate_box_slice_by_slice_3d_x.cl new file mode 100644 index 0000000..04356b1 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/dilate_box_slice_by_slice_3d_x.cl @@ -0,0 +1,33 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void dilate_box_slice_by_slice_3d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float value = READ_src_IMAGE(src, sampler, pos).x; + if (value == 0) { + for (int ax = -1; ax <= 1; ax++) { + for (int ay = -1; ay <= 1; ay++) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){ax, ay, 0, 0})).x; + if (value != 0) { + break; + } + } + if (value != 0) { + break; + } + } + } + if (value != 0) { + value = 1; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/dilate_sphere_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/dilate_sphere_2d_x.cl new file mode 100644 index 0000000..414ef23 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/dilate_sphere_2d_x.cl @@ -0,0 +1,31 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void dilate_sphere_2d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float value = READ_src_IMAGE(src, sampler, pos).x; + if (value == 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int2){1, 0})).x; + if (value == 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int2){-1, 0})).x; + if (value == 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, 1})).x; + if (value == 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, -1})).x; + } + } + } + } + if (value != 0) { + value = 1; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/dilate_sphere_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/dilate_sphere_3d_x.cl new file mode 100644 index 0000000..65c44a0 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/dilate_sphere_3d_x.cl @@ -0,0 +1,39 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void dilate_sphere_3d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float value = READ_src_IMAGE(src, sampler, pos).x; + if (value == 0) { + + value = READ_src_IMAGE(src, sampler, (pos + (int4){1, 0, 0, 0})).x; + if (value == 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){-1, 0, 0, 0})).x; + if (value == 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 1, 0, 0})).x; + if (value == 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, -1, 0, 0})).x; + if (value == 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 0, 1, 0})).x; + if (value == 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 0, -1, 0})).x; + } + } + } + } + } + } + if (value != 0) { + value = 1; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/dilate_sphere_slice_by_slice_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/dilate_sphere_slice_by_slice_3d_x.cl new file mode 100644 index 0000000..eb2ccb7 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/dilate_sphere_slice_by_slice_3d_x.cl @@ -0,0 +1,33 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void dilate_sphere_slice_by_slice_3d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float value = READ_src_IMAGE(src, sampler, pos).x; + if (value == 0) { + + value = READ_src_IMAGE(src, sampler, (pos + (int4){1, 0, 0, 0})).x; + if (value == 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){-1, 0, 0, 0})).x; + if (value == 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 1, 0, 0})).x; + if (value == 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, -1, 0, 0})).x; + } + } + } + } + if (value != 0) { + value = 1; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/distance_matrix_to_mesh_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/distance_matrix_to_mesh_x.cl new file mode 100644 index 0000000..7b4bea2 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/distance_matrix_to_mesh_x.cl @@ -0,0 +1,51 @@ +__kernel void distance_matrix_to_mesh( +IMAGE_src_pointlist_TYPE src_pointlist, +IMAGE_src_distance_matrix_TYPE src_distance_matrix, +IMAGE_dst_mesh_TYPE dst_mesh, +float distance_threshold) { + + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int pointIndex = get_global_id(0); + + POS_src_pointlist_TYPE pos = POS_src_pointlist_INSTANCE(pointIndex, 0, 0, 0); + const float pointAx = READ_src_pointlist_IMAGE(src_pointlist, sampler, pos).x; + pos = (int2){pointIndex, 1}; + const float pointAy = READ_src_pointlist_IMAGE(src_pointlist, sampler, pos).x; + pos = (int2){pointIndex, 2}; + const float pointAz = READ_src_pointlist_IMAGE(src_pointlist, sampler, pos).x; + + int4 pointA = (int4){pointAx, pointAy, pointAz, 0}; + + // so many point candidates are available: + const int num_pointBs = GET_IMAGE_HEIGHT(src_distance_matrix); + for (int pointBIndex = pointIndex; pointBIndex < num_pointBs; pointBIndex++) { + + if (pointIndex != pointBIndex) { + POS_src_distance_matrix_TYPE mPos = POS_src_distance_matrix_INSTANCE(pointIndex+1, pointBIndex+1, 0, 0); + const float distance = READ_src_distance_matrix_IMAGE(src_distance_matrix, sampler, mPos).x; + if (distance < distance_threshold) { + pos = (int2){pointBIndex, 0}; + const float pointBx = READ_src_pointlist_IMAGE(src_pointlist, sampler, pos).x; + pos = (int2){pointBIndex, 1}; + const float pointBy = READ_src_pointlist_IMAGE(src_pointlist, sampler, pos).x; + pos = (int2){pointBIndex, 2}; + const float pointBz = READ_src_pointlist_IMAGE(src_pointlist, sampler, pos).x; + + // draw line from A to B + float distanceX = pow(pointAx - pointBx, (float)2.0); + float distanceY = pow(pointAy - pointBy, (float)2.0); + float distanceZ = pow(pointAz - pointBz, (float)2.0); + + float distance = sqrt(distanceX + distanceY + distanceZ); + for (float d = 0; d < distance; d = d + 0.5) { + POS_dst_mesh_TYPE tPos = POS_dst_mesh_INSTANCE(pointAx + (pointBx - pointAx) * d / distance, + pointAy + (pointBy - pointAy) * d / distance, + pointAz + (pointBz - pointAz) * d / distance, + 0); + WRITE_dst_mesh_IMAGE(dst_mesh, tPos, 1); + } + } + } + } +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/distancemap_localPositiveMinimum_box_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/distancemap_localPositiveMinimum_box_2d_x.cl new file mode 100644 index 0000000..662393a --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/distancemap_localPositiveMinimum_box_2d_x.cl @@ -0,0 +1,31 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void distancemap_local_positive_minimum_box_2d +( + IMAGE_dst_TYPE dst, IMAGE_flag_dst_TYPE flag_dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float foundMinimum = READ_src_IMAGE(src, sampler, pos).x; + if (foundMinimum > 0) { + + for (int ax = -1; ax <= 1; ax++) { + for (int ay = -1; ay <= 1; ay++) { + float value = READ_src_IMAGE(src, sampler, (pos + (int2){ax, ay})).x; + if ( value < foundMinimum && value >= 0) { + foundMinimum = value; + } + } + } + + if (foundMinimum > 0) { + WRITE_flag_dst_IMAGE(flag_dst,(int4)(0,0,0,0),1); + } + } + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(foundMinimum)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/distancemap_localPositiveMinimum_box_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/distancemap_localPositiveMinimum_box_3d_x.cl new file mode 100644 index 0000000..58da9f1 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/distancemap_localPositiveMinimum_box_3d_x.cl @@ -0,0 +1,33 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void distancemap_local_positive_minimum_box_3d +( + IMAGE_dst_TYPE dst, IMAGE_flag_dst_TYPE flag_dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float foundMinimum = READ_src_IMAGE(src, sampler, pos).x; + if (foundMinimum > 0) { + for (int ax = -1; ax <= 1; ax++) { + for (int ay = -1; ay <= 1; ay++) { + for (int az = -1; az <= 1; az++) { + float value = READ_src_IMAGE(src, sampler, (pos + (int4){ax, ay, az, 0})).x; + if ( value < foundMinimum && value >= 0) { + foundMinimum = value; + } + } + } + } + + if (foundMinimum > 0) { + WRITE_flag_dst_IMAGE(flag_dst,(int4)(0,0,0,0),1); + } + } + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(foundMinimum)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/distancemap_localPositiveMinimum_diamond_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/distancemap_localPositiveMinimum_diamond_2d_x.cl new file mode 100644 index 0000000..8fcf3ca --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/distancemap_localPositiveMinimum_diamond_2d_x.cl @@ -0,0 +1,35 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void distancemap_local_positive_minimum_diamond_2d +( + IMAGE_dst_TYPE dst, IMAGE_flag_dst_TYPE flag_dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float foundMinimum = READ_src_IMAGE(src, sampler, pos).x; + if (foundMinimum > 0) { + + for (int ay = -1; ay <= 1; ay++) { + float value = READ_src_IMAGE(src, sampler, (pos + (int2){0, ay})).x; + if ( value < foundMinimum && value >= 0) { + foundMinimum = value; + } + } + for (int ax = -1; ax <= 1; ax++) { + float value = READ_src_IMAGE(src, sampler, (pos + (int2){ax, 0})).x; + if ( value < foundMinimum && value >= 0) { + foundMinimum = value; + } + } + + if (foundMinimum > 0) { + WRITE_flag_dst_IMAGE(flag_dst,(int4)(0,0,0,0),1); + } + } + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(foundMinimum)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/distancemap_localPositiveMinimum_diamond_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/distancemap_localPositiveMinimum_diamond_3d_x.cl new file mode 100644 index 0000000..d0f3935 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/distancemap_localPositiveMinimum_diamond_3d_x.cl @@ -0,0 +1,43 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void distancemap_local_positive_minimum_diamond_3d +( + IMAGE_dst_TYPE dst, IMAGE_flag_dst_TYPE flag_dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float foundMinimum = READ_src_IMAGE(src, sampler, pos).x; + if (foundMinimum > 0) { + for (int ax = -1; ax <= 1; ax++) { + float value = READ_src_IMAGE(src, sampler, (pos + (int4){ax, 0, 0, 0})).x; + if ( value < foundMinimum && value >= 0) { + foundMinimum = value; + } + } + + for (int ay = -1; ay <= 1; ay++) { + float value = READ_src_IMAGE(src, sampler, (pos + (int4){0, ay, 0, 0})).x; + if ( value < foundMinimum && value >= 0) { + foundMinimum = value; + } + } + + for (int az = -1; az <= 1; az++) { + float value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 0, az, 0})).x; + if ( value < foundMinimum && value >= 0) { + foundMinimum = value; + } + } + + if (foundMinimum > 0) { + WRITE_flag_dst_IMAGE(flag_dst,(int4)(0,0,0,0),1); + } + } + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(foundMinimum)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/divide_images_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/divide_images_2d_x.cl new file mode 100644 index 0000000..a32c2e8 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/divide_images_2d_x.cl @@ -0,0 +1,17 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void divide_images_2d( + IMAGE_src_TYPE src, + IMAGE_src1_TYPE src1, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const float value = (float)READ_src_IMAGE(src, sampler, pos).x / READ_src1_IMAGE(src1, sampler, pos).x; + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/divide_images_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/divide_images_3d_x.cl new file mode 100644 index 0000000..8b84d49 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/divide_images_3d_x.cl @@ -0,0 +1,19 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + +__kernel void divide_images_3d( + IMAGE_src_TYPE src, + IMAGE_src1_TYPE src1, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const float value = (float)READ_src_IMAGE(src, sampler, pos).x / READ_src1_IMAGE(src1, sampler, pos).x; + + WRITE_dst_IMAGE(dst, pos, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/downsample_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/downsample_2d_x.cl new file mode 100644 index 0000000..45a60f1 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/downsample_2d_x.cl @@ -0,0 +1,17 @@ + +__kernel void downsample_2d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + float factor_x, + float factor_y +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int dx = get_global_id(0); + const int dy = get_global_id(1); + + const int sx = factor_x * dx; + const int sy = factor_y * dy; + const float out = READ_src_IMAGE(src,sampler,((int2){sx,sy})).x; + WRITE_dst_IMAGE(dst,((int2){dx,dy}), CONVERT_dst_PIXEL_TYPE(out)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/downsample_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/downsample_3d_x.cl new file mode 100644 index 0000000..8d1af50 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/downsample_3d_x.cl @@ -0,0 +1,19 @@ +__kernel void downsample_3d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + float factor_x, + float factor_y, + float factor_z +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int dx = get_global_id(0); + const int dy = get_global_id(1); + const int dz = get_global_id(2); + + const int sx = factor_x * dx; + const int sy = factor_y * dy; + const int sz = factor_z * dz; + const float out = READ_src_IMAGE(src,sampler,((int4){sx,sy,sz,0})).x; + WRITE_dst_IMAGE(dst,((int4){dx,dy,dz,0}), CONVERT_dst_PIXEL_TYPE(out)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/downsample_xy_by_half_median_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/downsample_xy_by_half_median_3d_x.cl new file mode 100644 index 0000000..1545f7d --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/downsample_xy_by_half_median_3d_x.cl @@ -0,0 +1,79 @@ +// the following two methods originate from +// https://github.com/ClearControl/fastfuse/blob/master/src/main/java/fastfuse/tasks/kernels/downsampling.cl + +#define min_nobranch(x,y) x < y ? x : y; +#define max_nobranch(x,y) x > y ? x : y; + +inline void swap(IMAGE_dst_PIXEL_TYPE *a, int i, int j) { + IMAGE_dst_PIXEL_TYPE t; + t = min_nobranch(a[i],a[j]); + a[j] = max_nobranch(a[i],a[j]); + a[i] = t; +} + + +__kernel void downsample_xy_by_half_median_3d ( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); + const int4 coord_out = (int4){i,j,k,0}; + const int x = 2*i, y = 2*j, z = k; + + IMAGE_src_PIXEL_TYPE pixel[4]; + pixel[0] = READ_src_IMAGE(src,sampler,((int4){x+0,y+0,z,0})).x; + pixel[1] = READ_src_IMAGE(src,sampler,((int4){x+0,y+1,z,0})).x; + pixel[2] = READ_src_IMAGE(src,sampler,((int4){x+1,y+0,z,0})).x; + pixel[3] = READ_src_IMAGE(src,sampler,((int4){x+1,y+1,z,0})).x; + + // // sort pixel array + // swap(pixel,0,1); + // swap(pixel,2,3); + // swap(pixel,0,2); + // swap(pixel,1,3); + // swap(pixel,1,2); + + // if ((pixel[0] > pixel[1]) || + // (pixel[1] > pixel[2]) || + // (pixel[2] > pixel[3])) + // printf("array not sorted for i=%d, j=%d, k=%d\n", i,j,k); + + // swap array elements such that pixel[0] = "min(pixel)" and pixel[3] = "max(pixel)" + // this tiny performance improvement is only there to make Martin happy + swap(pixel,0,1); + swap(pixel,2,3); + swap(pixel,0,2); + swap(pixel,1,3); + + // if ( (pixel[0] > pixel[1]) || (pixel[0] > pixel[2]) || (pixel[0] > pixel[3]) || + // (pixel[3] < pixel[2]) || (pixel[3] < pixel[1]) || (pixel[3] < pixel[0]) ) + // printf("array not sorted for i=%d, j=%d, k=%d\n", i,j,k); + + // output is mean of medians + const float out = (pixel[1] + pixel[2]) / 2.0f; + + WRITE_dst_IMAGE(dst,coord_out, CONVERT_dst_PIXEL_TYPE(out)); +} + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/downsampling.cl b/src/main/java/net/haesleinhuepf/clij/kernels/downsampling.cl deleted file mode 100644 index f30ac46..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/downsampling.cl +++ /dev/null @@ -1,147 +0,0 @@ -__kernel void downsample_3d_nearest(DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src, float factor_x, float factor_y, float factor_z) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int dx = get_global_id(0); - const int dy = get_global_id(1); - const int dz = get_global_id(2); - - const int sx = factor_x * dx; - const int sy = factor_y * dy; - const int sz = factor_z * dz; - const DTYPE_IN out = READ_IMAGE_3D(src,sampler,((int4){sx,sy,sz,0})).x; - WRITE_IMAGE_3D(dst,((int4){dx,dy,dz,0}), CONVERT_DTYPE_OUT(out)); -} - -__kernel void downsample_2d_nearest(DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src, float factor_x, float factor_y) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int dx = get_global_id(0); - const int dy = get_global_id(1); - - const int sx = factor_x * dx; - const int sy = factor_y * dy; - const DTYPE_IN out = READ_IMAGE_2D(src,sampler,((int2){sx,sy})).x; - WRITE_IMAGE_2D(dst,((int2){dx,dy}), CONVERT_DTYPE_OUT(out)); -} - -#define SIZEX 4 -#define SIZEY 4 -#define SIZETotal SIZEX * SIZEY - -__kernel void DownSample ( DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_OUT_2D des, - __constant int * dim // "constant" memory (64K) pre-cached so it can be read fast - ) -{ - // tell the sampler how to read the image - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_FILTER_NEAREST; - - int i = get_global_id (0); - int j = get_global_id (1); - - // jump to the starting indexes - int is = i * SIZEX; - int js = j * SIZEY; - - if ( is >= dim[0] - SIZEX && js >= dim[1] - SIZEY ) - return; - - float total = 0; - - // we can unroll the loop to reduce overhead (e.g., condition check) - // if you know the size (e.g., 4 * 4 ), then you can write 16 separate - // "read_imageui" instead of using the loop - // There is a way for CPU to generate the unrolled code to be - // placed in the kernel. - for ( int z = 0; z < SIZEX; z++ ) { - for ( int x = 0; x < SIZEX; x++ ) { - for ( int y = 0; y < SIZEY; y++ ) { - if ( is < dim[0] - x && js < dim[1] - y ) { - total += (READ_IMAGE_2D ( src, sampler, ((int2) { is + x, js + y }) )).x; - } - } - } - } - - total = ( total / SIZETotal ); - WRITE_IMAGE_2D ( des, ((int2) { i, j }), CONVERT_DTYPE_OUT(total) ); -} - - -// the following two methods originate from -// https://github.com/ClearControl/fastfuse/blob/master/src/main/java/fastfuse/tasks/kernels/downsampling.cl - -#define min_nobranch(x,y) x < y ? x : y; -#define max_nobranch(x,y) x > y ? x : y; - -inline void swap(DTYPE_IN *a, int i, int j) { - DTYPE_IN t; - t = min_nobranch(a[i],a[j]); - a[j] = max_nobranch(a[i],a[j]); - a[i] = t; -} - - -__kernel void downsample_xy_by_half_median(DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src) { - - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord_out = (int4){i,j,k,0}; - const int x = 2*i, y = 2*j, z = k; - - DTYPE_IN pixel[4]; - pixel[0] = READ_IMAGE_3D(src,sampler,((int4){x+0,y+0,z,0})).x; - pixel[1] = READ_IMAGE_3D(src,sampler,((int4){x+0,y+1,z,0})).x; - pixel[2] = READ_IMAGE_3D(src,sampler,((int4){x+1,y+0,z,0})).x; - pixel[3] = READ_IMAGE_3D(src,sampler,((int4){x+1,y+1,z,0})).x; - - // // sort pixel array - // swap(pixel,0,1); - // swap(pixel,2,3); - // swap(pixel,0,2); - // swap(pixel,1,3); - // swap(pixel,1,2); - - // if ((pixel[0] > pixel[1]) || - // (pixel[1] > pixel[2]) || - // (pixel[2] > pixel[3])) - // printf("array not sorted for i=%d, j=%d, k=%d\n", i,j,k); - - // swap array elements such that pixel[0] = "min(pixel)" and pixel[3] = "max(pixel)" - // this tiny performance improvement is only there to make Martin happy - swap(pixel,0,1); - swap(pixel,2,3); - swap(pixel,0,2); - swap(pixel,1,3); - - // if ( (pixel[0] > pixel[1]) || (pixel[0] > pixel[2]) || (pixel[0] > pixel[3]) || - // (pixel[3] < pixel[2]) || (pixel[3] < pixel[1]) || (pixel[3] < pixel[0]) ) - // printf("array not sorted for i=%d, j=%d, k=%d\n", i,j,k); - - // output is mean of medians - const float out = (pixel[1] + pixel[2]) / 2.0f; - - WRITE_IMAGE_3D(dst,coord_out, CONVERT_DTYPE_OUT(out)); -} - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/draw_box_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/draw_box_2d_x.cl new file mode 100644 index 0000000..1322687 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/draw_box_2d_x.cl @@ -0,0 +1,23 @@ + +__kernel void draw_box_2d ( + IMAGE_dst_TYPE dst, + float x1, + float y1, + float x2, + float y2, + float value +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + if (!((x >= x1 && x <= x2) || (x >= x2 && x <= x1))) { + return; + } + if (!((y >= y1 && y <= y2) || (y >= y2 && y <= y1))) { + return; + } + + int2 ipos = (int2){x,y}; + WRITE_dst_IMAGE (dst, ipos, CONVERT_dst_PIXEL_TYPE(value)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/draw_box_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/draw_box_3d_x.cl new file mode 100644 index 0000000..e3c2fb1 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/draw_box_3d_x.cl @@ -0,0 +1,28 @@ +__kernel void draw_box_3d ( + IMAGE_dst_TYPE dst, + float x1, + float y1, + float z1, + float x2, + float y2, + float z2, + float value +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + if (!((x >= x1 && x <= x2) || (x >= x2 && x <= x1))) { + return; + } + if (!((y >= y1 && y <= y2) || (y >= y2 && y <= y1))) { + return; + } + if (!((z >= z1 && z <= z2) || (z >= z2 && z <= z1))) { + return; + } + + int4 ipos = (int4){x,y,z,0}; + WRITE_dst_IMAGE (dst, ipos, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/draw_sphere_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/draw_sphere_2d_x.cl new file mode 100644 index 0000000..1ac32f7 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/draw_sphere_2d_x.cl @@ -0,0 +1,30 @@ + +__kernel void draw_sphere_2d( + IMAGE_dst_TYPE dst, + float cx, + float cy, + float rx, + float ry, + float rxsq, + float rysq, + float value +) +{ + const float x = get_global_id(0); + const float y = get_global_id(1); +/* + if ((x < cx - rx) || (x > cx + rx)) { + return; + } + if ((y < cy - ry) || (y > cy + ry)) { + return; + }*/ + + float xSquared = pow(x - cx, 2); + float ySquared = pow(y - cy, 2); + + if ((xSquared / rxsq + ySquared / rysq) <= 1.0) { + int2 ipos = (int2){x,y}; + WRITE_dst_IMAGE(dst, ipos, CONVERT_dst_PIXEL_TYPE(value)); + } +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/draw_sphere_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/draw_sphere_3d_x.cl new file mode 100644 index 0000000..42058c0 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/draw_sphere_3d_x.cl @@ -0,0 +1,37 @@ +__kernel void draw_sphere_3d ( + IMAGE_dst_TYPE dst, + float cx, + float cy, + float cz, + float rx, + float ry, + float rz, + float rxsq, + float rysq, + float rzsq, + float value +) +{ + const float x = get_global_id(0); + const float y = get_global_id(1); + const float z = get_global_id(2); + + if ((x < cx - rx) || (x > cx + rx)) { + return; + } + if ((y < cy - ry) || (y > cy + ry)) { + return; + } + if ((z < cz - rz) || (z > cz + rz)) { + return; + } + + float xSquared = pow(x - cx, 2); + float ySquared = pow(y - cy, 2); + float zSquared = pow(z - cz, 2); + + if ((xSquared / rxsq + ySquared / rysq + zSquared / rzsq) <= 1.0) { + int4 ipos = (int4){x,y,z,0}; + WRITE_dst_IMAGE (dst, ipos, CONVERT_dst_PIXEL_TYPE(value)); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/drawline_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/drawline_2d_x.cl new file mode 100644 index 0000000..48cb625 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/drawline_2d_x.cl @@ -0,0 +1,30 @@ +__kernel void draw_line_2D (IMAGE_dst_TYPE dst, + float x1, + float y1, + float x2, + float y2, + float radius, + float value + ) +{ + const float x = min(x1, x2) - radius + get_global_id(0); + const float y = min(y1, y2) - radius + get_global_id(1); + + if (!((x >= x1 - radius && x <= x2 + radius) || (x >= x2 - radius && x <= x1 + radius))) { + return; + } + if (!((y >= y1 - radius && y <= y2 + radius) || (y >= y2 - radius && y <= y1 + radius))) { + return; + } + + + float4 r = (float4){x-x2, y-y2, 0, 0}; + float4 r1 = (float4){x1-x2, y1-y2, 0, 0}; + float4 v = cross(r1, r); + float distance = length(v) / length(r1); + + if (distance < radius) { + int2 ipos = (int2){x,y}; + WRITE_dst_IMAGE (dst, ipos, CONVERT_dst_PIXEL_TYPE(value)); + } +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/drawline_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/drawline_3d_x.cl new file mode 100644 index 0000000..40d184e --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/drawline_3d_x.cl @@ -0,0 +1,36 @@ +__kernel void draw_line_3D (IMAGE_dst_TYPE dst, + float x1, + float y1, + float z1, + float x2, + float y2, + float z2, + float radius, + float value + ) +{ + const float x = min(x1, x2) - radius + get_global_id(0); + const float y = min(y1, y2) - radius + get_global_id(1); + const float z = min(z1, z2) - radius + get_global_id(2); + + if (!((x >= x1 - radius && x <= x2 + radius) || (x >= x2 - radius && x <= x1 + radius))) { + return; + } + if (!((y >= y1 - radius && y <= y2 + radius) || (y >= y2 - radius && y <= y1 + radius))) { + return; + } + if (!((z >= z1 - radius && z <= z2 + radius) || (z >= z2 - radius && z <= z1 + radius))) { + return; + } + + + float4 r = (float4){x-x2, y-y2, z-z2, 0}; + float4 r1 = (float4){x1-x2, y1-y2, z1-z2, 0}; + float4 v = cross(r1, r); + float distance = length(v) / length(r1); + + if (distance < radius) { + int4 ipos = (int4){x,y,z,0}; + WRITE_dst_IMAGE (dst, ipos, CONVERT_dst_PIXEL_TYPE(value)); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/duplication.cl b/src/main/java/net/haesleinhuepf/clij/kernels/duplication.cl deleted file mode 100644 index 8a8f5b8..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/duplication.cl +++ /dev/null @@ -1,89 +0,0 @@ -__kernel void copy_3d (DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int dx = get_global_id(0); - const int dy = get_global_id(1); - const int dz = get_global_id(2); - - const int4 pos = (int4){dx,dy,dz,0}; - - const DTYPE_IN out = READ_IMAGE_3D(src,sampler,pos).x; - WRITE_IMAGE_3D(dst, pos, CONVERT_DTYPE_OUT(out)); -} - -__kernel void copy_2d(DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int dx = get_global_id(0); - const int dy = get_global_id(1); - - - const int2 pos = (int2){dx,dy}; - - const DTYPE_IN out = READ_IMAGE_2D(src,sampler,pos).x; - WRITE_IMAGE_2D(dst,pos, CONVERT_DTYPE_OUT(out)); -} - -__kernel void copySlice(DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_3D src, int slice) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int dx = get_global_id(0); - const int dy = get_global_id(1); - - const int4 pos4 = (int4){dx,dy,slice,0}; - const int2 pos2 = (int2){dx,dy}; - - const DTYPE_IN out = READ_IMAGE_3D(src,sampler,pos4).x; - WRITE_IMAGE_2D(dst,pos2, CONVERT_DTYPE_OUT(out)); -} - -__kernel void putSliceInStack(DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_2D src, int slice) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int dx = get_global_id(0); - const int dy = get_global_id(1); - - const int2 pos2 = (int2){dx,dy}; - const int4 pos4 = (int4){dx,dy,slice,0}; - - const DTYPE_IN out = READ_IMAGE_2D(src,sampler,pos2).x; - WRITE_IMAGE_3D(dst,pos4, CONVERT_DTYPE_OUT(out)); -} - - -__kernel void crop_3d(DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src, int start_x, int start_y, int start_z) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int dx = get_global_id(0); - const int dy = get_global_id(1); - const int dz = get_global_id(2); - - - const int sx = start_x + dx; - const int sy = start_y + dy; - const int sz = start_z + dz; - - const int4 dpos = (int4){dx,dy,dz,0}; - const int4 spos = (int4){sx,sy,sz,0}; - - const DTYPE_IN out = READ_IMAGE_3D(src,sampler,spos).x; - WRITE_IMAGE_3D(dst,dpos, CONVERT_DTYPE_OUT(out)); -} - - -__kernel void crop_2d(DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src, int start_x, int start_y) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int dx = get_global_id(0); - const int dy = get_global_id(1); - - const int sx = start_x + dx; - const int sy = start_y + dy; - - const int2 dpos = (int2){dx,dy}; - const int2 spos = (int2){sx,sy}; - - const DTYPE_IN out = READ_IMAGE_2D(src,sampler,spos).x; - WRITE_IMAGE_2D(dst,dpos, CONVERT_DTYPE_OUT(out)); -} - diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/entropy_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/entropy_2d_x.cl new file mode 100644 index 0000000..b53ad02 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/entropy_2d_x.cl @@ -0,0 +1,50 @@ +__kernel void entropy_2d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst, + int radiusX, + int radiusY, + float minIntensity, + float maxIntensity +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + POS_src_TYPE pos = POS_src_INSTANCE(get_global_id(0), get_global_id(1), 0, 0); + float centerValue = READ_IMAGE(src, sampler, pos).x; + float result = 0; + + int numBins = 256; + float hist[256]; + for (int i = 0; i < numBins; i++) { + hist[i] = 0; + } + + float size_bin = (maxIntensity - minIntensity) / numBins; + + /* create histogram over all pixels in radius */ + for (int x = -radiusX; x <= radiusX; x++) + { + for (int y = -radiusY; y <= radiusY; y++) + { + const POS_src_TYPE localPos = pos + POS_src_INSTANCE(x, y, 0, 0); + float value = READ_IMAGE(src, sampler, localPos).x; + int bin = (int) (value / size_bin); + hist[bin] = hist[bin] + 1; + } + } + + float total = (radiusX * 2 + 1) * (radiusY * 2 + 1); + + // compute entropy + float entropy = 0; + for (int k = 0; k < numBins; k++) + { + if (hist[k] > 0) + { + float p = hist[k] / total; + entropy = entropy + (-p * log2(p)); + } + } + + WRITE_IMAGE(dst, pos, CONVERT_dst_PIXEL_TYPE(entropy)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/entropy_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/entropy_3d_x.cl new file mode 100644 index 0000000..1f88383 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/entropy_3d_x.cl @@ -0,0 +1,55 @@ +__kernel void entropy_3d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst, + int radiusX, + int radiusY, + int radiusZ, + float minIntensity, + float maxIntensity +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + POS_src_TYPE pos = POS_src_INSTANCE(get_global_id(0), get_global_id(1), get_global_id(2), 0); + float centerValue = READ_IMAGE(src, sampler, pos).x; + float result = 0; + + int numBins = 256; + float hist[256]; + for (int i = 0; i < numBins; i++) { + hist[i] = 0; + } + + float size_bin = (maxIntensity - minIntensity) / numBins; + + // create histogram over all pixels in radius + for (int x = -radiusX; x <= radiusX; x++) + { + for (int y = -radiusY; y <= radiusY; y++) + { + for (int z = -radiusZ; z <= radiusZ; z++) + { + const POS_src_TYPE localPos = pos + POS_src_INSTANCE(x, y, z, 0); + float value = READ_IMAGE(src, sampler, localPos).x; + int bin = (int) (value / size_bin); + hist[bin] = hist[bin] + 1; + } + } + } + + + float total = (radiusX * 2 + 1) * (radiusY * 2 + 1) * (radiusZ * 2 + 1); + + // compute entropy + float entropy = 0; + for (int k = 0; k < numBins; k++) + { + if (hist[k] > 0) + { + float p = hist[k] / total; + entropy = entropy + (-p * log2(p)); + } + } + + WRITE_IMAGE(dst, pos, CONVERT_dst_PIXEL_TYPE(entropy)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/equal_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/equal_2d_x.cl new file mode 100644 index 0000000..177b34d --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/equal_2d_x.cl @@ -0,0 +1,22 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void equal_2d( + IMAGE_src1_TYPE src1, + IMAGE_src2_TYPE src2, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + const float input2 = (float)READ_src2_IMAGE(src2, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 == input2) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/equal_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/equal_3d_x.cl new file mode 100644 index 0000000..54035f3 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/equal_3d_x.cl @@ -0,0 +1,23 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void equal_3d( + IMAGE_src1_TYPE src1, + IMAGE_src2_TYPE src2, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + const float input2 = (float)READ_sec2_IMAGE(src2, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 == input2) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/equal_constant_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/equal_constant_2d_x.cl new file mode 100644 index 0000000..e030996 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/equal_constant_2d_x.cl @@ -0,0 +1,21 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void equal_constant_2d( + IMAGE_src1_TYPE src1, + float scalar, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 == scalar) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/equal_constant_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/equal_constant_3d_x.cl new file mode 100644 index 0000000..6a153e9 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/equal_constant_3d_x.cl @@ -0,0 +1,22 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void equal_constant_3d( + IMAGE_src1_TYPE src1, + float scalar, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 == scalar) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/erode_box_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/erode_box_2d_x.cl new file mode 100644 index 0000000..2fc3905 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/erode_box_2d_x.cl @@ -0,0 +1,33 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void erode_box_2d ( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float value = READ_src_IMAGE(src, sampler, pos).x; + if (value != 0) { + for (int ax = -1; ax <= 1; ax++) { + for (int ay = -1; ay <= 1; ay++) { + value = READ_src_IMAGE(src, sampler, (pos + (int2){ax, ay})).x; + if (value == 0) { + break; + } + } + if (value == 0) { + break; + } + } + } + if (value != 0) { + value = 1; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/erode_box_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/erode_box_3d_x.cl new file mode 100644 index 0000000..0ac5644 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/erode_box_3d_x.cl @@ -0,0 +1,38 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void erode_box_3d ( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float value = READ_src_IMAGE(src, sampler, pos).x; + if (value != 0) { + for (int ax = -1; ax <= 1; ax++) { + for (int ay = -1; ay <= 1; ay++) { + for (int az = -1; az <= 1; az++) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){ax, ay, az, 0})).x; + if (value == 0) { + break; + } + } + if (value == 0) { + break; + } + } + if (value == 0) { + break; + } + } + } + if (value != 0) { + value = 1; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/erode_box_slice_by_slice_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/erode_box_slice_by_slice_3d_x.cl new file mode 100644 index 0000000..ace79d2 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/erode_box_slice_by_slice_3d_x.cl @@ -0,0 +1,33 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void erode_box_slice_by_slice_3d ( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float value = READ_src_IMAGE(src, sampler, pos).x; + if (value != 0) { + for (int ax = -1; ax <= 1; ax++) { + for (int ay = -1; ay <= 1; ay++) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){ax, ay, 0, 0})).x; + if (value == 0) { + break; + } + } + if (value == 0) { + break; + } + } + } + if (value != 0) { + value = 1; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/erode_sphere_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/erode_sphere_2d_x.cl new file mode 100644 index 0000000..699c1ed --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/erode_sphere_2d_x.cl @@ -0,0 +1,31 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void erode_sphere_2d ( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float value = READ_src_IMAGE(src, sampler, pos).x; + if (value != 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int2){1, 0})).x; + if (value != 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int2){-1, 0})).x; + if (value != 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, 1})).x; + if (value != 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, -1})).x; + } + } + } + } + if (value != 0) { + value = 1; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/erode_sphere_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/erode_sphere_3d_x.cl new file mode 100644 index 0000000..dd85ce2 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/erode_sphere_3d_x.cl @@ -0,0 +1,38 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void erode_sphere_3d ( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float value = READ_src_IMAGE(src, sampler, pos).x; + if (value != 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){1, 0, 0, 0})).x; + if (value != 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){-1, 0, 0, 0})).x; + if (value != 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 1, 0, 0})).x; + if (value != 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, -1, 0, 0})).x; + if (value != 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 0, 1, 0})).x; + if (value != 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 0, -1, 0})).x; + } + } + } + } + } + } + if (value != 0) { + value = 1; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/erode_sphere_slice_by_slice_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/erode_sphere_slice_by_slice_3d_x.cl new file mode 100644 index 0000000..a78f5d5 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/erode_sphere_slice_by_slice_3d_x.cl @@ -0,0 +1,32 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void erode_sphere_slice_by_slice_3d ( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float value = READ_src_IMAGE(src, sampler, pos).x; + if (value != 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){1, 0, 0, 0})).x; + if (value != 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){-1, 0, 0, 0})).x; + if (value != 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 1, 0, 0})).x; + if (value != 0) { + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, -1, 0, 0})).x; + } + } + } + } + if (value != 0) { + value = 1; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/excludeLabelsOnEdges_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/excludeLabelsOnEdges_3d_x.cl new file mode 100644 index 0000000..572ef89 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/excludeLabelsOnEdges_3d_x.cl @@ -0,0 +1,85 @@ +__kernel void exclude_on_edges_x_3d ( + IMAGE_src_TYPE src, + IMAGE_label_index_dst_TYPE label_index_dst +) +{ + const sampler_t intsampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST; + + int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int width = GET_IMAGE_WIDTH(src); + + x = 0; + POS_src_TYPE pos = POS_src_INSTANCE(x, y, z,0); + int index = READ_src_IMAGE(src, intsampler, pos).x; + if (index > 0) { + WRITE_label_index_dst_IMAGE (label_index_dst, POS_label_index_dst_INSTANCE(index,0,0,0), 0); + } + + x = width - 1; + pos = POS_src_INSTANCE(x, y, z,0); + index = READ_src_IMAGE(src, intsampler, pos).x; + if (index > 0) { + WRITE_label_index_dst_IMAGE (label_index_dst, POS_label_index_dst_INSTANCE(index,0,0,0), 0); + } +} + +__kernel void exclude_on_edges_y_3d ( + IMAGE_src_TYPE src, + IMAGE_label_index_dst_TYPE label_index_dst +) +{ + const sampler_t intsampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + int y = get_global_id(1); + const int z = get_global_id(2); + + const int height = GET_IMAGE_HEIGHT(src); + + y = 0; + POS_src_TYPE pos = POS_src_INSTANCE(x, y, z,0); + int index = READ_src_IMAGE(src, intsampler, pos).x; + if (index > 0) { + WRITE_label_index_dst_IMAGE (label_index_dst, POS_label_index_dst_INSTANCE(index,0,0,0), 0); + } + + y = height - 1; + pos = POS_src_INSTANCE(x, y, z,0); + index = READ_src_IMAGE(src, intsampler, pos).x; + if (index > 0) { + WRITE_label_index_dst_IMAGE (label_index_dst, POS_label_index_dst_INSTANCE(index,0,0,0), 0); + } +} + + +__kernel void exclude_on_edges_z_3d ( + IMAGE_src_TYPE src, + IMAGE_label_index_dst_TYPE label_index_dst +) +{ + const sampler_t intsampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + int z = get_global_id(2); + + const int depth = GET_IMAGE_DEPTH(src); + + z = 0; + POS_src_TYPE pos = POS_src_INSTANCE(x, y, z,0); + int index = READ_src_IMAGE(src, intsampler, pos).x; + if (index > 0) { + WRITE_label_index_dst_IMAGE (label_index_dst, POS_label_index_dst_INSTANCE(index,0,0,0), 0); + } + + z = depth - 1; + pos = POS_src_INSTANCE(x, y, z,0); + index = READ_src_IMAGE(src, intsampler, pos).x; + if (index > 0) { + WRITE_label_index_dst_IMAGE (label_index_dst, POS_label_index_dst_INSTANCE(index,0,0,0), 0); + } +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/exclude_labels_on_surface_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/exclude_labels_on_surface_2d_x.cl new file mode 100644 index 0000000..2286691 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/exclude_labels_on_surface_2d_x.cl @@ -0,0 +1,68 @@ +__kernel void exclude_labels_on_surface_2d ( + IMAGE_src_pointlist_TYPE src_pointlist, + IMAGE_src_label_map_TYPE src_label_map, + IMAGE_label_index_dst_TYPE label_index_dst, + float centerX, + float centerY +) +{ + const sampler_t intsampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST; + + const int label_id = get_global_id(0); + + const float x = READ_src_pointlist_IMAGE(src_pointlist, intsampler, POS_src_pointlist_INSTANCE(label_id - 1, 0, 0, 0)).x; + const float y = READ_src_pointlist_IMAGE(src_pointlist, intsampler, POS_src_pointlist_INSTANCE(label_id - 1, 1, 0, 0)).x; + + float2 directionVector = (float2){x - centerX, y - centerY}; + //if (direction != 0) { + // directionVector.x = -directionVector.x; + // directionVector.y = -directionVector.y; + //} + float len = length(directionVector); + directionVector.x = directionVector.x / len; + directionVector.y = directionVector.y / len; + + //if (label_id == 33) { + // printf("DIR %f / %f \n", directionVector.x, directionVector.y); + //} + + int width = GET_IMAGE_WIDTH(src_label_map); + int height = GET_IMAGE_HEIGHT(src_label_map); + + float2 position = (float2){x, y}; + + bool foundMyself = false; + bool foundAnother = false; + while (true) { + int2 pos = (int2){(int)position.x, (int)position.y}; + //if (label_id == 33) { + // printf("\n%d / %d", pos.x, pos.y); + //} + int label = READ_src_label_map_IMAGE(src_label_map, intsampler, pos).x; + if (label_id == label) { + foundMyself = true; + //if (label_id == 33) { + // printf(" found myself"); + //} + } else if (foundMyself && label_id != label && label > 0) { // I found another label sitting between myself and the image border + foundAnother = true; + //if (label_id == 33) { + // printf(" found another"); + //} + break; + } + + position = position + directionVector; + if (position.x < 0 || position.y < 0 || position.x >= width || position.y >= height) { + break; + } + } + + if (!foundAnother) { + //printf("%d eliminate\n", label_id); + WRITE_label_index_dst_IMAGE (label_index_dst, POS_label_index_dst_INSTANCE(label_id,0,0,0), 0); + } else { + //printf("%d keep old value\n", label_id); + WRITE_label_index_dst_IMAGE (label_index_dst, POS_label_index_dst_INSTANCE(label_id,0,0,0), CONVERT_label_index_dst_PIXEL_TYPE(label_id)); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/exclude_labels_on_surface_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/exclude_labels_on_surface_3d_x.cl new file mode 100644 index 0000000..655bb8c --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/exclude_labels_on_surface_3d_x.cl @@ -0,0 +1,58 @@ +__kernel void exclude_labels_on_surface_3d ( + IMAGE_src_pointlist_TYPE src_pointlist, + IMAGE_src_label_map_TYPE src_label_map, + IMAGE_label_index_dst_TYPE label_index_dst, + float centerX, + float centerY, + float centerZ +) +{ + const sampler_t intsampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST; + + const int label_id = get_global_id(0); + + const float x = READ_src_pointlist_IMAGE(src_pointlist, intsampler, POS_src_pointlist_INSTANCE(label_id - 1, 0, 0, 0)).x; + const float y = READ_src_pointlist_IMAGE(src_pointlist, intsampler, POS_src_pointlist_INSTANCE(label_id - 1, 1, 0, 0)).x; + const float z = READ_src_pointlist_IMAGE(src_pointlist, intsampler, POS_src_pointlist_INSTANCE(label_id - 1, 2, 0, 0)).x; + + float4 directionVector = (float4){x - centerX, y - centerY, z - centerZ, 0}; + float len = length(directionVector); + directionVector.x = directionVector.x / len; + directionVector.y = directionVector.y / len; + directionVector.z = directionVector.z / len; + + //if (label_id == 33) { + // printf("DIR %f / %f \n", directionVector.x, directionVector.y); + //} + + int width = GET_IMAGE_WIDTH(src_label_map); + int height = GET_IMAGE_HEIGHT(src_label_map); + int depth = GET_IMAGE_DEPTH(src_label_map); + + float4 position = (float4){x, y, z, 0}; + + bool foundMyself = false; + bool foundAnother = false; + while (true) { + int4 pos = (int4){(int)position.x, (int)position.y, (int)position.z, 0}; + + int label = READ_src_label_map_IMAGE(src_label_map, intsampler, pos).x; + if (label_id == label) { + foundMyself = true; + } else if (foundMyself && label_id != label && label > 0) { // I found another label sitting between myself and the image border + foundAnother = true; + break; + } + + position = position + directionVector; + if (position.x < 0 || position.y < 0 || position.z < 0 || position.x >= width || position.y >= height || position.z >= depth) { + break; + } + } + + if (!foundAnother) { + WRITE_label_index_dst_IMAGE (label_index_dst, POS_label_index_dst_INSTANCE(label_id,0,0,0), 0); + } else { + WRITE_label_index_dst_IMAGE (label_index_dst, POS_label_index_dst_INSTANCE(label_id,0,0,0), CONVERT_label_index_dst_PIXEL_TYPE(label_id)); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/exclude_labels_sub_surface_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/exclude_labels_sub_surface_2d_x.cl new file mode 100644 index 0000000..c6cf852 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/exclude_labels_sub_surface_2d_x.cl @@ -0,0 +1,68 @@ +__kernel void exclude_labels_sub_surface_2d ( + IMAGE_src_pointlist_TYPE src_pointlist, + IMAGE_src_label_map_TYPE src_label_map, + IMAGE_label_index_dst_TYPE label_index_dst, + float centerX, + float centerY +) +{ + const sampler_t intsampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST; + + const int label_id = get_global_id(0); + + const float x = READ_src_pointlist_IMAGE(src_pointlist, intsampler, POS_src_pointlist_INSTANCE(label_id - 1, 0, 0, 0)).x; + const float y = READ_src_pointlist_IMAGE(src_pointlist, intsampler, POS_src_pointlist_INSTANCE(label_id - 1, 1, 0, 0)).x; + + float2 directionVector = (float2){x - centerX, y - centerY}; + //if (direction != 0) { + // directionVector.x = -directionVector.x; + // directionVector.y = -directionVector.y; + //} + float len = length(directionVector); + directionVector.x = directionVector.x / len; + directionVector.y = directionVector.y / len; + + //if (label_id == 33) { + // printf("DIR %f / %f \n", directionVector.x, directionVector.y); + //} + + int width = GET_IMAGE_WIDTH(src_label_map); + int height = GET_IMAGE_HEIGHT(src_label_map); + + float2 position = (float2){x, y}; + + bool foundMyself = false; + bool foundAnother = false; + while (true) { + int2 pos = (int2){(int)position.x, (int)position.y}; + //if (label_id == 33) { + // printf("\n%d / %d", pos.x, pos.y); + //} + int label = READ_src_label_map_IMAGE(src_label_map, intsampler, pos).x; + if (label_id == label) { + foundMyself = true; + //if (label_id == 33) { + // printf(" found myself"); + //} + } else if (foundMyself && label_id != label && label > 0) { // I found another label sitting between myself and the image border + foundAnother = true; + //if (label_id == 33) { + // printf(" found another"); + //} + break; + } + + position = position + directionVector; + if (position.x < 0 || position.y < 0 || position.x >= width || position.y >= height) { + break; + } + } + + if (foundAnother) { + //printf("%d eliminate\n", label_id); + WRITE_label_index_dst_IMAGE (label_index_dst, POS_label_index_dst_INSTANCE(label_id,0,0,0), 0); + } else { + //printf("%d keep old value\n", label_id); + WRITE_label_index_dst_IMAGE (label_index_dst, POS_label_index_dst_INSTANCE(label_id,0,0,0), CONVERT_label_index_dst_PIXEL_TYPE(label_id)); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/exclude_labels_sub_surface_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/exclude_labels_sub_surface_3d_x.cl new file mode 100644 index 0000000..06fe28b --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/exclude_labels_sub_surface_3d_x.cl @@ -0,0 +1,58 @@ +__kernel void exclude_labels_sub_surface_3d ( + IMAGE_src_pointlist_TYPE src_pointlist, + IMAGE_src_label_map_TYPE src_label_map, + IMAGE_label_index_dst_TYPE label_index_dst, + float centerX, + float centerY, + float centerZ +) +{ + const sampler_t intsampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST; + + const int label_id = get_global_id(0); + + const float x = READ_src_pointlist_IMAGE(src_pointlist, intsampler, POS_src_pointlist_INSTANCE(label_id - 1, 0, 0, 0)).x; + const float y = READ_src_pointlist_IMAGE(src_pointlist, intsampler, POS_src_pointlist_INSTANCE(label_id - 1, 1, 0, 0)).x; + const float z = READ_src_pointlist_IMAGE(src_pointlist, intsampler, POS_src_pointlist_INSTANCE(label_id - 1, 2, 0, 0)).x; + + float4 directionVector = (float4){x - centerX, y - centerY, z - centerZ, 0}; + float len = length(directionVector); + directionVector.x = directionVector.x / len; + directionVector.y = directionVector.y / len; + directionVector.z = directionVector.z / len; + + //if (label_id == 33) { + // printf("DIR %f / %f \n", directionVector.x, directionVector.y); + //} + + int width = GET_IMAGE_WIDTH(src_label_map); + int height = GET_IMAGE_HEIGHT(src_label_map); + int depth = GET_IMAGE_DEPTH(src_label_map); + + float4 position = (float4){x, y, z, 0}; + + bool foundMyself = false; + bool foundAnother = false; + while (true) { + int4 pos = (int4){(int)position.x, (int)position.y, (int)position.z, 0}; + + int label = READ_src_label_map_IMAGE(src_label_map, intsampler, pos).x; + if (label_id == label) { + foundMyself = true; + } else if (foundMyself && label_id != label && label > 0) { // I found another label sitting between myself and the image border + foundAnother = true; + break; + } + + position = position + directionVector; + if (position.x < 0 || position.y < 0 || position.z < 0 || position.x >= width || position.y >= height || position.z >= depth) { + break; + } + } + + if (foundAnother) { + WRITE_label_index_dst_IMAGE (label_index_dst, POS_label_index_dst_INSTANCE(label_id,0,0,0), 0); + } else { + WRITE_label_index_dst_IMAGE (label_index_dst, POS_label_index_dst_INSTANCE(label_id,0,0,0), CONVERT_label_index_dst_PIXEL_TYPE(label_id)); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/exponential_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/exponential_2d_x.cl new file mode 100644 index 0000000..623b5a8 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/exponential_2d_x.cl @@ -0,0 +1,18 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void exponential_2d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const float input = (float)READ_src_IMAGE(src, sampler, pos).x; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(exp( input )); + + WRITE_dst_IMAGE (dst, pos, value); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/exponential_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/exponential_3d_x.cl new file mode 100644 index 0000000..e6bfb96 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/exponential_3d_x.cl @@ -0,0 +1,19 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void exponential_3d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const float input = (float)READ_src_IMAGE(src, sampler, pos).x; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(exp( input )); + + WRITE_dst_IMAGE (dst, pos, value); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/filtering.cl b/src/main/java/net/haesleinhuepf/clij/kernels/filtering.cl deleted file mode 100644 index 828104e..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/filtering.cl +++ /dev/null @@ -1,844 +0,0 @@ -__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - -inline int copyNeighborhoodToArray(DTYPE_IMAGE_IN_2D src, DTYPE_OUT array[], - const int2 coord, - const int Nx, const int Ny ) { - // centers - const int4 e = (int4) { (Nx-1)/2, (Ny-1)/2, 0, 0 }; - - float aSquared = e.x * e.x; - float bSquared = e.y * e.y; - - int count = 0; - - for (int x = -e.x; x <= e.x; x++) { - float xSquared = x * x; - for (int y = -e.y; y <= e.y; y++) { - float ySquared = y * y; - if (xSquared / aSquared + ySquared / bSquared <= 1.0) { - array[count] = (DTYPE_OUT)READ_IMAGE_2D(src,sampler,coord+((int2){x,y})).x; - count++; - } - } - } - return count; -} - -inline int copyBoxNeighborhoodToArray(DTYPE_IMAGE_IN_2D src, DTYPE_OUT array[], - const int2 coord, - const int Nx, const int Ny ) { - // centers - const int4 e = (int4) { (Nx-1)/2, (Ny-1)/2, 0, 0 }; - - float aSquared = e.x * e.x; - float bSquared = e.y * e.y; - - int count = 0; - - for (int x = -e.x; x <= e.x; x++) { - for (int y = -e.y; y <= e.y; y++) { - array[count] = (DTYPE_OUT)READ_IMAGE_2D(src,sampler,coord+((int2){x,y})).x; - count++; - } - } - return count; -} - -inline int copySliceNeighborhoodToArray(DTYPE_IMAGE_IN_3D src, DTYPE_OUT array[], - const int4 coord, - const int Nx, const int Ny ) { - // centers - const int4 e = (int4) { (Nx-1)/2, (Ny-1)/2, 0, 0 }; - - float aSquared = e.x * e.x; - float bSquared = e.y * e.y; - - int count = 0; - - for (int x = -e.x; x <= e.x; x++) { - float xSquared = x * x; - for (int y = -e.y; y <= e.y; y++) { - float ySquared = y * y; - if (xSquared / aSquared + ySquared / bSquared <= 1.0) { - array[count] = (DTYPE_OUT)READ_IMAGE_3D(src,sampler,coord+((int4){x,y,0,0})).x; - count++; - } - } - } - return count; -} - -inline int copyBoxSliceNeighborhoodToArray(DTYPE_IMAGE_IN_3D src, DTYPE_OUT array[], - const int4 coord, - const int Nx, const int Ny ) { - // centers - const int4 e = (int4) { (Nx-1)/2, (Ny-1)/2, 0, 0 }; - - float aSquared = e.x * e.x; - float bSquared = e.y * e.y; - - int count = 0; - - for (int x = -e.x; x <= e.x; x++) { - float xSquared = x * x; - for (int y = -e.y; y <= e.y; y++) { - array[count] = (DTYPE_OUT)READ_IMAGE_3D(src,sampler,coord+((int4){x,y,0,0})).x; - count++; - } - } - return count; -} - - -inline int copyVolumeNeighborhoodToArray(DTYPE_IMAGE_IN_3D src, DTYPE_OUT array[], - const int4 coord, - const int Nx, const int Ny, const int Nz ) { - // centers - const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, (Nz-1)/2, 0 }; - - int count = 0; - - float aSquared = e.x * e.x; - float bSquared = e.y * e.y; - float cSquared = e.z * e.z; - - for (int x = -e.x; x <= e.x; x++) { - float xSquared = x * x; - for (int y = -e.y; y <= e.y; y++) { - float ySquared = y * y; - for (int z = -e.z; z <= e.z; z++) { - float zSquared = z * z; - if (xSquared / aSquared + ySquared / bSquared + zSquared / cSquared <= 1.0) { - - int x1 = coord.x + x; - int x2 = coord.y + y; - int x3 = coord.z + z; - const int4 pos = (int4){x1,x2,x3,0}; - float value_res = (float)READ_IMAGE_3D(src,sampler,pos).x; - array[count] = value_res; - count++; - } - } - } - } - return count; -} - -inline int copyBoxVolumeNeighborhoodToArray(DTYPE_IMAGE_IN_3D src, DTYPE_OUT array[], - const int4 coord, - const int Nx, const int Ny, const int Nz ) { - // centers - const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, (Nz-1)/2, 0 }; - - int count = 0; - - float aSquared = e.x * e.x; - float bSquared = e.y * e.y; - float cSquared = e.z * e.z; - - for (int x = -e.x; x <= e.x; x++) { - for (int y = -e.y; y <= e.y; y++) { - for (int z = -e.z; z <= e.z; z++) { - int x1 = coord.x + x; - int x2 = coord.y + y; - int x3 = coord.z + z; - const int4 pos = (int4){x1,x2,x3,0}; - float value_res = (float)READ_IMAGE_3D(src,sampler,pos).x; - array[count] = value_res; - count++; - - } - } - } - return count; -} - - -inline void sort(DTYPE_OUT array[], int array_size) -{ - DTYPE_OUT temp; - for(int i = 0; i < array_size; i++) { - int j; - temp = array[i]; - for(j = i - 1; j >= 0 && temp < array[j]; j--) { - array[j+1] = array[j]; - } - array[j+1] = temp; - } -} - -inline DTYPE_OUT average(DTYPE_OUT array[], int array_size) -{ - DTYPE_OUT sum = 0; - for(int i = 0; i < array_size; i++) { - sum += array[i]; - } - return sum / array_size; -} - -inline DTYPE_OUT median(DTYPE_OUT array[], int array_size) -{ - sort(array, array_size); - return array[array_size / 2]; -} - -__kernel void mean_slicewise_image3d -( - DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src, - const int Nx, const int Ny -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4){i,j,k,0}; - - const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, 0, 0 }; - - float aSquared = e.x * e.x; - float bSquared = e.y * e.y; - - DTYPE_OUT sum = 0; - int count = 0; - - for (int x = -e.x; x <= e.x; x++) { - float xSquared = x * x; - for (int y = -e.y; y <= e.y; y++) { - float ySquared = y * y; - if (xSquared / aSquared + ySquared / bSquared <= 1.0) { - sum += (DTYPE_OUT)READ_IMAGE_3D(src,sampler,coord+((int4){x,y,0,0})).x; - count++; - } - } - } - - DTYPE_OUT res = CONVERT_DTYPE_OUT(sum / count); - WRITE_IMAGE_3D(dst, coord, res); -} - -__kernel void mean_image2d_ij -( - DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src, - const int radius -) -{ - const int i = get_global_id(0), j = get_global_id(1); - const int2 coord = (int2){i,j}; - - // centers - const int4 e = (int4) { radius, radius, 0, 0 }; - - float rSquared = pow((float)radius, 2) + 1; - - int count = 0; - - float sum = 0; - for (int x = -e.x; x <= e.x; x++) { - float xSquared = x * x; - for (int y = -e.y; y <= e.y; y++) { - float ySquared = y * y; - if (xSquared + ySquared <= rSquared) { - sum += (float)(READ_IMAGE_2D(src,sampler,coord+((int2){x,y})).x); - count++; - } - } - } - - - DTYPE_OUT res = CONVERT_DTYPE_OUT(sum / count + 0.5); - WRITE_IMAGE_2D(dst, coord, res); -} - - -__kernel void mean_image2d -( - DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src, - const int Nx, const int Ny -) -{ - const int i = get_global_id(0), j = get_global_id(1); - const int2 coord = (int2){i,j}; - - const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, 0, 0 }; - int count = 0; - float sum = 0; - - float aSquared = e.x * e.x; - float bSquared = e.y * e.y; - - for (int x = -e.x; x <= e.x; x++) { - float xSquared = x * x; - for (int y = -e.y; y <= e.y; y++) { - float ySquared = y * y; - if (xSquared / aSquared + ySquared / bSquared <= 1.0) { - sum += (DTYPE_OUT)READ_IMAGE_2D(src,sampler,coord+((int2){x,y})).x; - count++; - } - } - } - - DTYPE_OUT res = CONVERT_DTYPE_OUT(sum / count); - WRITE_IMAGE_2D(dst, coord, res); -} - -__kernel void mean_image3d -( - DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src, - const int Nx, const int Ny, const int Nz -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4){i,j,k,0}; - - const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, (Nz-1)/2, 0 }; - int count = 0; - float sum = 0; - - float aSquared = e.x * e.x; - float bSquared = e.y * e.y; - float cSquared = e.z * e.z; - - for (int x = -e.x; x <= e.x; x++) { - float xSquared = x * x; - for (int y = -e.y; y <= e.y; y++) { - float ySquared = y * y; - for (int z = -e.z; z <= e.z; z++) { - float zSquared = z * z; - if (xSquared / aSquared + ySquared / bSquared + zSquared / cSquared <= 1.0) { - - int x1 = coord.x + x; - int x2 = coord.y + y; - int x3 = coord.z + z; - const int4 pos = (int4){x1,x2,x3,0}; - float value_res = (float)READ_IMAGE_3D(src,sampler,pos).x; - sum += value_res; - count++; - } - } - } - } - - - DTYPE_OUT res = CONVERT_DTYPE_OUT(sum / count); - WRITE_IMAGE_3D(dst, coord, res); -} - -__kernel void median_image2d -( - DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src, - const int Nx, const int Ny -) -{ - const int i = get_global_id(0), j = get_global_id(1); - const int2 coord = (int2){i,j}; - - int array_size = Nx * Ny; - DTYPE_OUT array[MAX_ARRAY_SIZE]; - - array_size = copyNeighborhoodToArray(src, array, coord, Nx, Ny); - - DTYPE_OUT res = median(array, array_size); - WRITE_IMAGE_2D(dst, coord, res); -} - -__kernel void median_box_image2d -( - DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src, - const int Nx, const int Ny -) -{ - const int i = get_global_id(0), j = get_global_id(1); - const int2 coord = (int2){i,j}; - - int array_size = Nx * Ny; - DTYPE_OUT array[MAX_ARRAY_SIZE]; - - array_size = copyBoxNeighborhoodToArray(src, array, coord, Nx, Ny); - - DTYPE_OUT res = median(array, array_size); - WRITE_IMAGE_2D(dst, coord, res); -} - -__kernel void median_image3d -( - DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src, - const int Nx, const int Ny, const int Nz -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4){i,j,k,0}; - - int array_size = Nx * Ny * Nz; - DTYPE_OUT array[MAX_ARRAY_SIZE]; - - array_size = copyVolumeNeighborhoodToArray(src, array, coord, Nx, Ny, Nz); - - DTYPE_OUT res = median(array, array_size); - WRITE_IMAGE_3D(dst, coord, res); -} - -__kernel void median_box_image3d -( - DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src, - const int Nx, const int Ny, const int Nz -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4){i,j,k,0}; - - int array_size = Nx * Ny * Nz; - DTYPE_OUT array[MAX_ARRAY_SIZE]; - - array_size = copyBoxVolumeNeighborhoodToArray(src, array, coord, Nx, Ny, Nz); - - DTYPE_OUT res = median(array, array_size); - WRITE_IMAGE_3D(dst, coord, res); -} - -__kernel void median_slicewise_image3d -( - DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src, - const int Nx, const int Ny -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4){i,j,k,0}; - - int array_size = Nx * Ny; - DTYPE_OUT array[MAX_ARRAY_SIZE]; - - array_size = copySliceNeighborhoodToArray(src, array, coord, Nx, Ny); - - DTYPE_OUT res = median(array, array_size); - WRITE_IMAGE_3D(dst, coord, res); -} - -__kernel void median_box_slicewise_image3d -( - DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src, - const int Nx, const int Ny -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4){i,j,k,0}; - - int array_size = Nx * Ny; - DTYPE_OUT array[MAX_ARRAY_SIZE]; - - array_size = copyBoxSliceNeighborhoodToArray(src, array, coord, Nx, Ny); - - DTYPE_OUT res = median(array, array_size); - WRITE_IMAGE_3D(dst, coord, res); -} - -__kernel void minimum_slicewise_image3d -( - DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src, - const int Nx, const int Ny -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4){i,j,k,0}; - - const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, 0, 0 }; - - DTYPE_OUT minimumValue = CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,coord).x); - float aSquared = e.x * e.x; - float bSquared = e.y * e.y; - - for (int x = -e.x; x <= e.x; x++) { - float xSquared = x * x; - for (int y = -e.y; y <= e.y; y++) { - float ySquared = y * y; - if (xSquared / aSquared + ySquared / bSquared <= 1.0) { - DTYPE_OUT value = CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,coord+((int4){x,y,0,0})).x); - if (value < minimumValue) { - minimumValue = value; - } - } - } - } - - DTYPE_OUT res = minimumValue; - WRITE_IMAGE_3D(dst, coord, res); -} - - -__kernel void minimum_image2d -( - DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src, - const int Nx, const int Ny -) -{ - const int i = get_global_id(0), j = get_global_id(1); - const int2 coord = (int2){i,j}; - - const int4 e = (int4) { (Nx-1)/2, (Ny-1)/2, 0, 0 }; - - DTYPE_OUT minimumValue = CONVERT_DTYPE_OUT(READ_IMAGE_2D(src,sampler,coord).x); - float aSquared = e.x * e.x; - float bSquared = e.y * e.y; - - int count = 0; - - for (int x = -e.x; x <= e.x; x++) { - float xSquared = x * x; - for (int y = -e.y; y <= e.y; y++) { - float ySquared = y * y; - if (xSquared / aSquared + ySquared / bSquared <= 1.0) { - DTYPE_OUT value = (DTYPE_OUT)READ_IMAGE_2D(src,sampler,coord+((int2){x,y})).x; - if (value < minimumValue) { - minimumValue = value; - } - } - } - } - - DTYPE_OUT res = minimumValue; - WRITE_IMAGE_2D(dst, coord, res); -} - -__kernel void minimum_image2d_ij -( - DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src, - const int radius -) -{ - const int i = get_global_id(0), j = get_global_id(1); - const int2 coord = (int2){i,j}; - - // centers - const int4 e = (int4) { radius, radius, 0, 0 }; - - float rSquared = pow((float)radius, 2) + 1; - - float minimumValue = (float)(READ_IMAGE_2D(src,sampler,coord).x); - for (int x = -e.x; x <= e.x; x++) { - float xSquared = x * x; - for (int y = -e.y; y <= e.y; y++) { - float ySquared = y * y; - if (xSquared + ySquared <= rSquared) { - float value = (float)(READ_IMAGE_2D(src,sampler,coord+((int2){x,y})).x); - if (value < minimumValue) { - minimumValue = value; - } - } - } - } - - DTYPE_OUT res = CONVERT_DTYPE_OUT(minimumValue); - WRITE_IMAGE_2D(dst, coord, res); -} - - -__kernel void minimum_image3d -( - DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src, - const int Nx, const int Ny, const int Nz -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4){i,j,k,0}; - - const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, (Nz-1)/2, 0 }; - float minimumValue = (float)READ_IMAGE_3D(src,sampler,coord).x; - float aSquared = e.x * e.x; - float bSquared = e.y * e.y; - float cSquared = e.z * e.z; - - for (int x = -e.x; x <= e.x; x++) { - float xSquared = x * x; - for (int y = -e.y; y <= e.y; y++) { - float ySquared = y * y; - for (int z = -e.z; z <= e.z; z++) { - float zSquared = z * z; - if (xSquared / aSquared + ySquared / bSquared + zSquared / cSquared <= 1.0) { - - int x1 = coord.x + x; - int x2 = coord.y + y; - int x3 = coord.z + z; - const int4 pos = (int4){x1,x2,x3,0}; - float value_res = (float)READ_IMAGE_3D(src,sampler,pos).x; - if (value_res < minimumValue) { - minimumValue = value_res; - } - } - } - } - } - - - DTYPE_OUT res = CONVERT_DTYPE_OUT(minimumValue); - WRITE_IMAGE_3D(dst, coord, res); -} - -__kernel void maximum_slicewise_image3d -( - DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src, - const int Nx, const int Ny -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4){i,j,k,0}; - - const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, 0, 0 }; - DTYPE_OUT maximumValue = CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,coord).x); - float aSquared = e.x * e.x; - float bSquared = e.y * e.y; - - for (int x = -e.x; x <= e.x; x++) { - float xSquared = x * x; - for (int y = -e.y; y <= e.y; y++) { - float ySquared = y * y; - if (xSquared / aSquared + ySquared / bSquared <= 1.0) { - DTYPE_OUT value = CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,coord+((int4){x,y,0,0})).x); - if (value > maximumValue) { - maximumValue = value; - } - } - } - } - - DTYPE_OUT res = maximumValue; - WRITE_IMAGE_3D(dst, coord, res); -} - - -__kernel void maximum_image2d -( - DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src, - const int Nx, const int Ny -) -{ - const int i = get_global_id(0), j = get_global_id(1); - const int2 coord = (int2){i,j}; - const int4 e = (int4) { (Nx-1)/2, (Ny-1)/2, 0, 0 }; - - DTYPE_OUT maximumValue = CONVERT_DTYPE_OUT(READ_IMAGE_2D(src,sampler,coord).x); - float aSquared = e.x * e.x; - float bSquared = e.y * e.y; - - int count = 0; - - for (int x = -e.x; x <= e.x; x++) { - float xSquared = x * x; - for (int y = -e.y; y <= e.y; y++) { - float ySquared = y * y; - if (xSquared / aSquared + ySquared / bSquared <= 1.0) { - DTYPE_OUT value = CONVERT_DTYPE_OUT(READ_IMAGE_2D(src,sampler,coord+((int2){x,y})).x); - if (value > maximumValue) { - maximumValue = value; - } - } - } - } - - DTYPE_OUT res = maximumValue; - - WRITE_IMAGE_2D(dst, coord, res); -} - -__kernel void maximum_image2d_ij -( - DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src, - const int radius -) -{ - const int i = get_global_id(0), j = get_global_id(1); - const int2 coord = (int2){i,j}; - - // centers - const int4 e = (int4) { radius, radius, 0, 0 }; - - float rSquared = pow((float)radius, 2) + 1; - - float maximumValue = (float)(READ_IMAGE_2D(src,sampler,coord).x); - for (int x = -e.x; x <= e.x; x++) { - float xSquared = x * x; - for (int y = -e.y; y <= e.y; y++) { - float ySquared = y * y; - if (xSquared + ySquared <= rSquared) { - float value = (float)(READ_IMAGE_2D(src,sampler,coord+((int2){x,y})).x); - if (value > maximumValue) { - maximumValue = value; - } - } - } - } - - DTYPE_OUT res = CONVERT_DTYPE_OUT(maximumValue); - WRITE_IMAGE_2D(dst, coord, res); -} - - -__kernel void maximum_image3d -( - DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src, - const int Nx, const int Ny, const int Nz -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4){i,j,k,0}; - - - const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, (Nz-1)/2, 0 }; - float maximumValue = (float)READ_IMAGE_3D(src,sampler,coord).x; - float aSquared = e.x * e.x; - float bSquared = e.y * e.y; - float cSquared = e.z * e.z; - - for (int x = -e.x; x <= e.x; x++) { - float xSquared = x * x; - for (int y = -e.y; y <= e.y; y++) { - float ySquared = y * y; - for (int z = -e.z; z <= e.z; z++) { - float zSquared = z * z; - if (xSquared / aSquared + ySquared / bSquared + zSquared / cSquared <= 1.0) { - - int x1 = coord.x + x; - int x2 = coord.y + y; - int x3 = coord.z + z; - const int4 pos = (int4){x1,x2,x3,0}; - float value_res = (float)READ_IMAGE_3D(src,sampler,pos).x; - if (value_res > maximumValue) { - maximumValue = value_res; - } - } - } - } - } - - DTYPE_OUT res = CONVERT_DTYPE_OUT(maximumValue); - WRITE_IMAGE_3D(dst, coord, res); -} - -__kernel void mean_sep_image3d -( - DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src, - const int dim, const int N, const float s -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4)(i,j,k,0); - const int4 dir = (int4)(dim==0,dim==1,dim==2,0); - - // center - const int c = (N-1)/2; - - float res = 0, count = 0; - for (int v = -c; v <= c; v++) { - res += (float)READ_IMAGE_3D(src,sampler,coord+v*dir).x; - count += 1; - } - res /= count; - WRITE_IMAGE_3D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - - -__kernel void min_sep_image3d -( - DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src, - const int dim, const int N, const float s -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4)(i,j,k,0); - const int4 dir = (int4)(dim==0,dim==1,dim==2,0); - - // center - const int c = (N-1)/2; - - float res = READ_IMAGE_3D(src,sampler,coord).x; - for (int v = -c; v <= c; v++) { - res = min(res, (float)READ_IMAGE_3D(src,sampler,coord+v*dir).x); - } - WRITE_IMAGE_3D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - -__kernel void max_sep_image3d -( - DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src, - const int dim, const int N, const float s -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4)(i,j,k,0); - const int4 dir = (int4)(dim==0,dim==1,dim==2,0); - - // center - const int c = (N-1)/2; - - float res = READ_IMAGE_3D(src,sampler,coord).x; - for (int v = -c; v <= c; v++) { - res = max(res, (float)READ_IMAGE_3D(src,sampler,coord+v*dir).x); - } - WRITE_IMAGE_3D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - - -__kernel void mean_sep_image2d -( - DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src, - const int dim, const int N, const float s -) -{ - const int i = get_global_id(0), j = get_global_id(1); - const int2 coord = (int2)(i,j); - const int2 dir = (int2)(dim==0,dim==1); - - // center - const int c = (N-1)/2; - - float res = 0, count = 0; - for (int v = -c; v <= c; v++) { - res += (float)READ_IMAGE_2D(src,sampler,coord+v*dir).x; - count += 1; - } - res /= count; - WRITE_IMAGE_2D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - -__kernel void min_sep_image2d -( - DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src, - const int dim, const int N, const float s -) -{ - const int i = get_global_id(0), j = get_global_id(1); - const int2 coord = (int2)(i,j); - const int2 dir = (int2)(dim==0,dim==1); - - // center - const int c = (N-1)/2; - - float res = (float)(READ_IMAGE_2D(src,sampler,coord).x); - for (int v = -c; v <= c; v++) { - if (v != 0) { - res = min(res, (float)(READ_IMAGE_2D(src,sampler,coord+v*dir).x)); - } - } - WRITE_IMAGE_2D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - - -__kernel void max_sep_image2d -( - DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src, - const int dim, const int N, const float s -) -{ - const int i = get_global_id(0), j = get_global_id(1); - const int2 coord = (int2)(i,j); - const int2 dir = (int2)(dim==0,dim==1); - - // center - const int c = (N-1)/2; - - float res = (float)READ_IMAGE_2D(src,sampler,coord).x; - for (int v = -c; v <= c; v++) { - if (v != 0) { - res = max(res, (float)(READ_IMAGE_2D(src,sampler,coord+v*dir).x)); - } - } - WRITE_IMAGE_2D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/flip.cl b/src/main/java/net/haesleinhuepf/clij/kernels/flip.cl deleted file mode 100644 index 0c53bd5..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/flip.cl +++ /dev/null @@ -1,49 +0,0 @@ - -__kernel void flip_3d ( DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst, - const int flipx, - const int flipy, - const int flipz - ) -{ - const sampler_t intsampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST; - - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int width = get_global_size(0); - const int height = get_global_size(1); - const int depth = get_global_size(2); - - const int4 pos = (int4)(flipx?(width-1-x):x, - flipy?(height-1-y):y, - flipz?(depth-1-z):z,0); - - const DTYPE_IN value = READ_IMAGE_3D(src, intsampler, pos).x; - - WRITE_IMAGE_3D (dst, (int4)(x,y,z,0), CONVERT_DTYPE_OUT(value)); -} - - -__kernel void flip_2d ( DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_OUT_2D dst, - const int flipx, - const int flipy - ) -{ - const sampler_t intsampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST; - - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int width = get_global_size(0); - const int height = get_global_size(1); - - const int2 pos = (int2)(flipx?(width-1-x):x, - flipy?(height-1-y):y); - - const DTYPE_IN value = READ_IMAGE_2D(src, intsampler, pos).x; - - WRITE_IMAGE_2D (dst, (int2)(x,y), CONVERT_DTYPE_OUT(value)); -} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/flip_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/flip_2d_x.cl new file mode 100644 index 0000000..dedf084 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/flip_2d_x.cl @@ -0,0 +1,22 @@ + +__kernel void flip_2d ( IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst, + const int flipx, + const int flipy + ) +{ + const sampler_t intsampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int width = get_global_size(0); + const int height = get_global_size(1); + + const int2 pos = (int2)(flipx?(width-1-x):x, + flipy?(height-1-y):y); + + const float value = READ_src_IMAGE(src, intsampler, pos).x; + + WRITE_dst_IMAGE (dst, (int2)(x,y), CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/flip_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/flip_3d_x.cl new file mode 100644 index 0000000..e533339 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/flip_3d_x.cl @@ -0,0 +1,26 @@ + +__kernel void flip_3d ( IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst, + const int flipx, + const int flipy, + const int flipz + ) +{ + const sampler_t intsampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int width = get_global_size(0); + const int height = get_global_size(1); + const int depth = get_global_size(2); + + const int4 pos = (int4)(flipx?(width-1-x):x, + flipy?(height-1-y):y, + flipz?(depth-1-z):z,0); + + const float value = READ_src_IMAGE(src, intsampler, pos).x; + + WRITE_dst_IMAGE(dst, (int4)(x,y,z,0), CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/flood_fill_diamond_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/flood_fill_diamond_x.cl new file mode 100644 index 0000000..15181e0 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/flood_fill_diamond_x.cl @@ -0,0 +1,60 @@ +// Author: Robert Haase +// March 2020 +// + +__kernel void flood_fill_diamond( + IMAGE_src_TYPE src, + IMAGE_flag_dst_TYPE flag_dst, + IMAGE_dst_TYPE dst, + const float value_to_replace, + const float value_replacement, + int dimension +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = (dimension == 3)?get_global_id(2):0; + + const POS_src_TYPE pos = POS_src_INSTANCE(x, y, z, 0); + + float pixel = READ_IMAGE(src, sampler, pos).x; + if (pixel != value_to_replace) { + WRITE_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(pixel)); + return; // pixel is not changed. + } + + bool doReplace = false; + + if(READ_IMAGE(src, sampler, pos + POS_src_INSTANCE(-1, 0, 0, 0)).x == value_replacement ) { + doReplace = true; + } + if (!doReplace && READ_IMAGE(src, sampler, pos + POS_src_INSTANCE(1, 0, 0, 0)).x == value_replacement ) { + doReplace = true; + } + if (!doReplace && READ_IMAGE(src, sampler, pos + POS_src_INSTANCE(0, -1, 0, 0)).x == value_replacement ) { + doReplace = true; + } + if (!doReplace && READ_IMAGE(src, sampler, pos + POS_src_INSTANCE(0, 1, 0, 0)).x == value_replacement ) { + doReplace = true; + } + + if (dimension == 3) { + if (!doReplace && READ_IMAGE(src, sampler, pos + POS_src_INSTANCE(0, 0, -1, 0)).x == value_replacement ) { + doReplace = true; + } + if (!doReplace && READ_IMAGE(src, sampler, pos + POS_src_INSTANCE(0, 0, 1, 0)).x == value_replacement ) { + doReplace = true; + } + } + + if(doReplace) { + WRITE_IMAGE (flag_dst, POS_flag_dst_INSTANCE(0, 0, 0, 0), 1); + WRITE_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value_replacement)); + } else { + WRITE_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(pixel)); + } + + +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/gaussian_blur_separable_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/gaussian_blur_separable_2d_x.cl new file mode 100644 index 0000000..120710a --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/gaussian_blur_separable_2d_x.cl @@ -0,0 +1,37 @@ +// Adapted from Uwe Schmidt, https://github.com/ClearControl/FastFuse/blob/master/src/fastfuse/tasks/kernels/blur.cl +// + +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void gaussian_blur_separable_2d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int dim, + const int N, + const float s +) +{ + const int i = get_global_id(0); + const int j = get_global_id(1); + + const int2 coord = (int2)(i,j); + const int2 dir = (int2)(dim==0,dim==1); + + // center + const int c = (N-1)/2; + // normalization + const float n = -2*s*s; + + float res = 0; + float hsum = 0; + for (int v = -c; v <= c; v++) { + const float h = exp((v*v)/n); + res += h * (float)READ_src_IMAGE(src,sampler,coord+v*dir).x; + hsum += h; + } + res /= hsum; + WRITE_dst_IMAGE(dst, coord, CONVERT_dst_PIXEL_TYPE(res)); +} + + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/gaussian_blur_separable_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/gaussian_blur_separable_3d_x.cl new file mode 100644 index 0000000..7499e6b --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/gaussian_blur_separable_3d_x.cl @@ -0,0 +1,36 @@ +// Adapted from Uwe Schmidt, https://github.com/ClearControl/FastFuse/blob/master/src/fastfuse/tasks/kernels/blur.cl +// + +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void gaussian_blur_separable_3d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int dim, const int N, + const float s +) +{ + const int i = get_global_id(0); + const int j = get_global_id(1); + const int k = get_global_id(2); + + const int4 coord = (int4)(i,j,k,0); + const int4 dir = (int4)(dim==0,dim==1,dim==2,0); + + // center + const int c = (N-1)/2; + // normalization + const float n = -2*s*s; + + float res = 0; + float hsum = 0; + for (int v = -c; v <= c; v++) { + const float h = exp((v*v)/n); + res += h * (float)READ_src_IMAGE(src,sampler,coord+v*dir).x; + hsum += h; + } + res /= hsum; + WRITE_dst_IMAGE(dst,coord, CONVERT_dst_PIXEL_TYPE(res)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/generate_binary_overlap_matrix_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/generate_binary_overlap_matrix_2d_x.cl new file mode 100644 index 0000000..069a603 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/generate_binary_overlap_matrix_2d_x.cl @@ -0,0 +1,17 @@ + +__kernel void generate_binary_overlap_matrix_2d( + IMAGE_dst_matrix_TYPE dst_matrix, + IMAGE_src_label_map1_TYPE src_label_map1, + IMAGE_src_label_map2_TYPE src_label_map2 +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + + float label1 = READ_IMAGE(src_label_map1, sampler, POS_src_label_map1_INSTANCE(x, y, 0, 0)).x; + float label2 = READ_IMAGE(src_label_map2, sampler, POS_src_label_map2_INSTANCE(x, y, 0, 0)).x; + + WRITE_dst_matrix_IMAGE(dst_matrix, (POS_dst_matrix_INSTANCE(label1, label2, 0, 0)), CONVERT_dst_matrix_PIXEL_TYPE(1)); + WRITE_dst_matrix_IMAGE(dst_matrix, (POS_dst_matrix_INSTANCE(label2, label1, 0, 0)), CONVERT_dst_matrix_PIXEL_TYPE(1)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/generate_binary_overlap_matrix_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/generate_binary_overlap_matrix_3d_x.cl new file mode 100644 index 0000000..1a9ca64 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/generate_binary_overlap_matrix_3d_x.cl @@ -0,0 +1,18 @@ + +__kernel void generate_binary_overlap_matrix_3d( + IMAGE_dst_matrix_TYPE dst_matrix, + IMAGE_src_label_map1_TYPE src_label_map1, + IMAGE_src_label_map2_TYPE src_label_map2 +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + float label1 = READ_IMAGE(src_label_map1, sampler, POS_src_label_map1_INSTANCE(x, y, z, 0)).x; + float label2 = READ_IMAGE(src_label_map2, sampler, POS_src_label_map2_INSTANCE(x, y, z, 0)).x; + + WRITE_dst_matrix_IMAGE(dst_matrix, (POS_dst_matrix_INSTANCE(label1, label2, 0, 0)), CONVERT_dst_matrix_PIXEL_TYPE(1)); + WRITE_dst_matrix_IMAGE(dst_matrix, (POS_dst_matrix_INSTANCE(label2, label1, 0, 0)), CONVERT_dst_matrix_PIXEL_TYPE(1)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/generate_distance_matrix_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/generate_distance_matrix_x.cl new file mode 100644 index 0000000..2134595 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/generate_distance_matrix_x.cl @@ -0,0 +1,27 @@ + +__kernel void generate_distance_matrix( + IMAGE_dst_matrix_TYPE dst_matrix, + IMAGE_src_point_list1_TYPE src_point_list1, + IMAGE_src_point_list2_TYPE src_point_list2 +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + + int n_dimensions = GET_IMAGE_HEIGHT(src_point_list1); + int n_points = GET_IMAGE_WIDTH(src_point_list2); + + float positions[10]; + for (int i = 0; i < n_dimensions; i ++) { + positions[i] = READ_src_point_list1_IMAGE(src_point_list1, sampler, POS_src_point_list1_INSTANCE(x, i, 0, 0)).x; + } + + for (int j = 0; j < GET_IMAGE_WIDTH(src_point_list2); j ++) { + float sum = 0; + for (int i = 0; i < n_dimensions; i ++) { + sum = sum + pow(positions[i] - (float)READ_src_point_list2_IMAGE(src_point_list2, sampler, POS_src_point_list2_INSTANCE(j, i, 0, 0)).x, (float)2); + } + float out = sqrt(sum); + WRITE_dst_matrix_IMAGE(dst_matrix, POS_dst_matrix_INSTANCE(get_global_id(0)+1, j+1, 0, 0), CONVERT_dst_matrix_PIXEL_TYPE(out)); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/generate_touch_matrix_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/generate_touch_matrix_2d_x.cl new file mode 100644 index 0000000..c9e470d --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/generate_touch_matrix_2d_x.cl @@ -0,0 +1,28 @@ + +__kernel void generate_touch_matrix_2d( + IMAGE_dst_matrix_TYPE dst_matrix, + IMAGE_src_label_map_TYPE src_label_map +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + + float label = READ_src_label_map_IMAGE(src_label_map, sampler, POS_src_label_map_INSTANCE(x, y, 0, 0)).x; + if (x <= GET_IMAGE_WIDTH(src_label_map) - 1) { + float labelx = READ_src_label_map_IMAGE(src_label_map, sampler, POS_src_label_map_INSTANCE(x + 1, y, z, 0)).x; + if (label < labelx) { + WRITE_dst_matrix_IMAGE(dst_matrix, (POS_dst_matrix_INSTANCE(label, labelx, 0, 0)), CONVERT_dst_matrix_PIXEL_TYPE(1)); + } else if (label > labelx) { + WRITE_dst_matrix_IMAGE(dst_matrix, (POS_dst_matrix_INSTANCE(labelx, label, 0, 0)), CONVERT_dst_matrix_PIXEL_TYPE(1)); + } + } + if (y <= GET_IMAGE_HEIGHT(src_label_map) - 1) { + float labely = READ_src_label_map_IMAGE(src_label_map, sampler, POS_src_label_map_INSTANCE(x, y + 1, z, 0)).x; + if (label < labely) { + WRITE_dst_matrix_IMAGE(dst_matrix, (POS_dst_matrix_INSTANCE(label, labely, 0, 0)), CONVERT_dst_matrix_PIXEL_TYPE(1)); + } else if (label > labely) { + WRITE_dst_matrix_IMAGE(dst_matrix, (POS_dst_matrix_INSTANCE(labely, label, 0, 0)), CONVERT_dst_matrix_PIXEL_TYPE(1)); + } + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/generate_touch_matrix_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/generate_touch_matrix_3d_x.cl new file mode 100644 index 0000000..33cb48e --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/generate_touch_matrix_3d_x.cl @@ -0,0 +1,39 @@ + +__kernel void generate_touch_matrix_3d( + IMAGE_dst_matrix_TYPE dst_matrix, + IMAGE_src_label_map_TYPE src_label_map +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + float label = READ_src_label_map_IMAGE(src_label_map, sampler, POS_src_label_map_INSTANCE(x, y, z, 0)).x; + + + if (x <= GET_IMAGE_WIDTH(src_label_map) - 1) { + float labelx = READ_src_label_map_IMAGE(src_label_map, sampler, POS_src_label_map_INSTANCE(x + 1, y, z, 0)).x; + if (label < labelx) { + WRITE_dst_matrix_IMAGE(dst_matrix, (POS_dst_matrix_INSTANCE(label, labelx, 0, 0)), CONVERT_dst_matrix_PIXEL_TYPE(1)); + } else if (label > labelx) { + WRITE_dst_matrix_IMAGE(dst_matrix, (POS_dst_matrix_INSTANCE(labelx, label, 0, 0)), CONVERT_dst_matrix_PIXEL_TYPE(1)); + } + } + if (y <= GET_IMAGE_HEIGHT(src_label_map) - 1) { + float labely = READ_src_label_map_IMAGE(src_label_map, sampler, POS_src_label_map_INSTANCE(x, y + 1, z, 0)).x; + if (label < labely) { + WRITE_dst_matrix_IMAGE(dst_matrix, (POS_dst_matrix_INSTANCE(label, labely, 0, 0)), CONVERT_dst_matrix_PIXEL_TYPE(1)); + } else if (label > labely) { + WRITE_dst_matrix_IMAGE(dst_matrix, (POS_dst_matrix_INSTANCE(labely, label, 0, 0)), CONVERT_dst_matrix_PIXEL_TYPE(1)); + } + } + if (z <= GET_IMAGE_DEPTH(src_label_map) - 1) { + float labelz = READ_src_label_map_IMAGE(src_label_map, sampler, POS_src_label_map_INSTANCE(x, y, z + 1, 0)).x; + if (label < labelz) { + WRITE_dst_matrix_IMAGE(dst_matrix, (POS_dst_matrix_INSTANCE(label, labelz, 0, 0)), CONVERT_dst_matrix_PIXEL_TYPE(1)); + } else if (label > labelz) { + WRITE_dst_matrix_IMAGE(dst_matrix, (POS_dst_matrix_INSTANCE(labelz, label, 0, 0)), CONVERT_dst_matrix_PIXEL_TYPE(1)); + } + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/gradient_x_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/gradient_x_2d_x.cl new file mode 100644 index 0000000..df54a9f --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/gradient_x_2d_x.cl @@ -0,0 +1,20 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + +__kernel void gradient_x_2d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) +{ + const int i = get_global_id(0), j = get_global_id(1); + const int2 coord = (int2){i,j}; + const int2 coordA = (int2){i-1,j}; + const int2 coordB = (int2){i+1,j}; + + float valueA = READ_src_IMAGE(src, sampler, coordA).x; + float valueB = READ_src_IMAGE(src, sampler, coordB).x; + IMAGE_dst_PIXEL_TYPE res = CONVERT_dst_PIXEL_TYPE(valueB - valueA); + + WRITE_dst_IMAGE(dst, coord, res); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/gradient_x_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/gradient_x_3d_x.cl new file mode 100644 index 0000000..19b1702 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/gradient_x_3d_x.cl @@ -0,0 +1,21 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + +__kernel void gradient_x_3d +( + IMAGE_dst_TYPE dst, IMAGE_src_TYPE src +) +{ + const int i = get_global_id(0); + const int j = get_global_id(1); + const int k = get_global_id(2); + const int4 coord = (int4){i, j, k, 0}; + const int4 coordA = (int4){i-1, j, k, 0}; + const int4 coordB = (int4){i+1, j, k, 0}; + + float valueA = READ_src_IMAGE(src, sampler, coordA).x; + float valueB = READ_src_IMAGE(src, sampler, coordB).x; + IMAGE_dst_PIXEL_TYPE res = CONVERT_dst_PIXEL_TYPE(valueB - valueA); + + WRITE_dst_IMAGE(dst, coord, res); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/gradient_y_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/gradient_y_2d_x.cl new file mode 100644 index 0000000..125dd09 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/gradient_y_2d_x.cl @@ -0,0 +1,18 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void gradient_y_2d +( + IMAGE_dst_TYPE dst, IMAGE_src_TYPE src +) +{ + const int i = get_global_id(0), j = get_global_id(1); + const int2 coord = (int2){i,j}; + const int2 coordA = (int2){i,j-1}; + const int2 coordB = (int2){i,j+1}; + + float valueA = READ_src_IMAGE(src, sampler, coordA).x; + float valueB = READ_src_IMAGE(src, sampler, coordB).x; + IMAGE_dst_PIXEL_TYPE res = CONVERT_dst_PIXEL_TYPE(valueB - valueA); + + WRITE_dst_IMAGE(dst, coord, res); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/gradient_y_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/gradient_y_3d_x.cl new file mode 100644 index 0000000..7208d59 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/gradient_y_3d_x.cl @@ -0,0 +1,21 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + +__kernel void gradient_y_3d +( + IMAGE_dst_TYPE dst, IMAGE_src_TYPE src +) +{ + const int i = get_global_id(0); + const int j = get_global_id(1); + const int k = get_global_id(2); + const int4 coord = (int4){i, j, k, 0}; + const int4 coordA = (int4){i, j-1, k, 0}; + const int4 coordB = (int4){i, j+1, k, 0}; + + float valueA = READ_src_IMAGE(src, sampler, coordA).x; + float valueB = READ_src_IMAGE(src, sampler, coordB).x; + IMAGE_dst_PIXEL_TYPE res = CONVERT_dst_PIXEL_TYPE(valueB - valueA); + + WRITE_dst_IMAGE(dst, coord, res); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/gradient_z_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/gradient_z_3d_x.cl new file mode 100644 index 0000000..6be625e --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/gradient_z_3d_x.cl @@ -0,0 +1,21 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void gradient_z_3d +( + IMAGE_dst_TYPE dst, IMAGE_src_TYPE src +) +{ + const int i = get_global_id(0); + const int j = get_global_id(1); + const int k = get_global_id(2); + const int4 coord = (int4){i, j, k, 0}; + const int4 coordA = (int4){i, j, k-1, 0}; + const int4 coordB = (int4){i, j, k+1, 0}; + + float valueA = READ_src_IMAGE(src, sampler, coordA).x; + float valueB = READ_src_IMAGE(src, sampler, coordB).x; + IMAGE_dst_PIXEL_TYPE res = CONVERT_dst_PIXEL_TYPE(valueB - valueA); + + WRITE_dst_IMAGE(dst, coord, res); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/greater_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/greater_2d_x.cl new file mode 100644 index 0000000..b1f8960 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/greater_2d_x.cl @@ -0,0 +1,22 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void greater_2d( + IMAGE_src1_TYPE src1, + IMAGE_src2_TYPE src2, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + const float input2 = (float)READ_src2_IMAGE(src2, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 > input2) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/greater_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/greater_3d_x.cl new file mode 100644 index 0000000..507aaff --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/greater_3d_x.cl @@ -0,0 +1,23 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void greater_3d( + IMAGE_src1_TYPE src1, + IMAGE_src2_TYPE src2, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + const float input2 = (float)READ_sec2_IMAGE(src2, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 > input2) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/greater_constant_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/greater_constant_2d_x.cl new file mode 100644 index 0000000..633161a --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/greater_constant_2d_x.cl @@ -0,0 +1,21 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void greater_constant_2d( + IMAGE_src1_TYPE src1, + float scalar, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 > scalar) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/greater_constant_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/greater_constant_3d_x.cl new file mode 100644 index 0000000..3b8ecbf --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/greater_constant_3d_x.cl @@ -0,0 +1,22 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void greater_constant_3d( + IMAGE_src1_TYPE src1, + float scalar, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 > scalar) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/greater_or_equal_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/greater_or_equal_2d_x.cl new file mode 100644 index 0000000..22a7f30 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/greater_or_equal_2d_x.cl @@ -0,0 +1,22 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void greater_or_equal_2d( + IMAGE_src1_TYPE src1, + IMAGE_src2_TYPE src2, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + const float input2 = (float)READ_src2_IMAGE(src2, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 >= input2) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/greater_or_equal_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/greater_or_equal_3d_x.cl new file mode 100644 index 0000000..cc12527 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/greater_or_equal_3d_x.cl @@ -0,0 +1,23 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void greater_or_equal_3d( + IMAGE_src1_TYPE src1, + IMAGE_src2_TYPE src2, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + const float input2 = (float)READ_src2_IMAGE(src2, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 >= input2) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/greater_or_equal_constant_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/greater_or_equal_constant_2d_x.cl new file mode 100644 index 0000000..65bb797 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/greater_or_equal_constant_2d_x.cl @@ -0,0 +1,21 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void greater_or_equal_constant_2d( + IMAGE_src1_TYPE src1, + float scalar, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 >= scalar) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/greater_or_equal_constant_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/greater_or_equal_constant_3d_x.cl new file mode 100644 index 0000000..a5f2c63 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/greater_or_equal_constant_3d_x.cl @@ -0,0 +1,22 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void greater_or_equal_constant_3d( + IMAGE_src1_TYPE src1, + float scalar, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 >= scalar) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/histogram.cl b/src/main/java/net/haesleinhuepf/clij/kernels/histogram.cl deleted file mode 100644 index 743b331..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/histogram.cl +++ /dev/null @@ -1,92 +0,0 @@ -// adapted code from -// https://github.com/bgaster/opencl-book-samples/blob/master/src/Chapter_14/histogram/histogram_image.cl -// -// It was published unter BSD license according to -// https://code.google.com/archive/p/opencl-book-samples/ -// -// Book: OpenCL(R) Programming Guide -// Authors: Aaftab Munshi, Benedict Gaster, Timothy Mattson, James Fung, Dan Ginsburg -// ISBN-10: 0-321-74964-2 -// ISBN-13: 978-0-321-74964-2 -// Publisher: Addison-Wesley Professional -// URLs: http://safari.informit.com/9780132488006/ -// http://www.openclprogrammingguide.com -// -// -// - -#pragma OPENCL EXTENSION cl_khr_local_int32_base_atomics : enable - -// -// this kernel takes a RGBA 8-bit / channel input image and produces a partial histogram. -// the kernel is executed over multiple work-groups. for each work-group a partial histogram is generated -// partial_histogram is an array of num_groups * (256 * 3 * 32-bits/entry) entries -// we store 256 Red bins, followed by 256 Green bins and then the 256 Blue bins. -// - - -// Notes (haesleinhuepf) -// * dst_histogram must be a cl_buffer. Otherwise, GET_IMAGE_WIDTH(dst_histogram) would be no constant and allocating -// arrays with dynamic lengths is prohibited. -// -// - -const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - -kernel -void histogram_image_2d(DTYPE_IMAGE_IN_2D src, DTYPE_IMAGE_OUT_3D dst_histogram, float minimum, float maximum, int step_size_x, int step_size_y) -{ - int image_width = GET_IMAGE_WIDTH(src); - int image_height = GET_IMAGE_HEIGHT(src); - int y = get_global_id(0) * step_size_y; - float range = maximum - minimum; - - uint tmp_histogram[GET_IMAGE_WIDTH(dst_histogram)]; - for (int i = 0; i < GET_IMAGE_WIDTH(dst_histogram); i++) { - tmp_histogram[i] = 0; - } - - for (int x = 0; x < image_width; x+= step_size_x) { - float clr = READ_IMAGE_2D(src, sampler, (int2)(x, y)).x; - uint indx_x; - indx_x = convert_uint_sat( (clr - minimum) * (float)(GET_IMAGE_WIDTH(dst_histogram)) / range ); - tmp_histogram[indx_x]++; - } - - for (int idx = 0; idx < GET_IMAGE_WIDTH(dst_histogram); idx++) { - int4 pos = {idx, 0, y, 0}; - WRITE_IMAGE_3D(dst_histogram, pos, CONVERT_DTYPE_OUT(tmp_histogram[idx])); - } -} - -kernel -void histogram_image_3d(DTYPE_IMAGE_IN_3D src, DTYPE_IMAGE_OUT_3D dst_histogram, float minimum, float maximum, int step_size_x, int step_size_y, int step_size_z) -{ - int image_width = GET_IMAGE_WIDTH(src); - int image_height = GET_IMAGE_HEIGHT(src); - int image_depth = GET_IMAGE_DEPTH(src); - int y = get_global_id(0); - float range = maximum - minimum; - - uint tmp_histogram[GET_IMAGE_WIDTH(dst_histogram)]; - for (int i = 0; i < GET_IMAGE_WIDTH(dst_histogram); i++) { - tmp_histogram[i] = 0; - } - - for (int z = 0; z < image_depth; z+= step_size_z) { - for (int x = 0; x < image_width; x+= step_size_x) { - float clr = READ_IMAGE_3D(src, sampler, (int4)(x, y, z, 0)).x; - uint indx_x; - indx_x = convert_uint_sat( (clr - minimum) * (float)(GET_IMAGE_WIDTH(dst_histogram)) / range ); - tmp_histogram[indx_x]++; - } - } - - for (int idx = 0; idx < GET_IMAGE_WIDTH(dst_histogram); idx++) { - int4 pos = {idx, 0, y, 0}; - WRITE_IMAGE_3D(dst_histogram, pos, CONVERT_DTYPE_OUT(tmp_histogram[idx])); - } -} - - - diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/histogram_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/histogram_2d_x.cl new file mode 100644 index 0000000..460ee57 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/histogram_2d_x.cl @@ -0,0 +1,58 @@ +// adapted code from +// https://github.com/bgaster/opencl-book-samples/blob/master/src/Chapter_14/histogram/histogram_image.cl +// +// It was published unter BSD license according to +// https://code.google.com/archive/p/opencl-book-samples/ +// +// Book: OpenCL(R) Programming Guide +// Authors: Aaftab Munshi, Benedict Gaster, Timothy Mattson, James Fung, Dan Ginsburg +// ISBN-10: 0-321-74964-2 +// ISBN-13: 978-0-321-74964-2 +// Publisher: Addison-Wesley Professional +// URLs: http://safari.informit.com/9780132488006/ +// http://www.openclprogrammingguide.com +// +// +// + +#pragma OPENCL EXTENSION cl_khr_local_int32_base_atomics : enable + + +const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +kernel void histogram_2d( + IMAGE_src_TYPE src, + IMAGE_dst_histogram_TYPE dst_histogram, + float minimum, + float maximum, + int step_size_x, + int step_size_y +) +{ + int image_width = GET_IMAGE_WIDTH(src); + int image_height = GET_IMAGE_HEIGHT(src); + int y = get_global_id(0) * step_size_y; + float range = maximum - minimum; + + uint tmp_histogram[NUMBER_OF_HISTOGRAM_BINS]; + for (int i = 0; i < NUMBER_OF_HISTOGRAM_BINS; i++) { + tmp_histogram[i] = 0; + } + + for (int x = 0; x < image_width; x+= step_size_x) { + float clr = READ_src_IMAGE(src, sampler, (int2)(x, y)).x; + uint indx_x; + indx_x = convert_uint_sat( (clr - minimum) * (float)(GET_IMAGE_WIDTH(dst_histogram) - 1) / range ); + tmp_histogram[indx_x]++; + } + + for (int idx = 0; idx < GET_IMAGE_WIDTH(dst_histogram); idx++) { + int4 pos = {idx, 0, y, 0}; + WRITE_dst_histogram_IMAGE(dst_histogram, pos, CONVERT_dst_histogram_PIXEL_TYPE(tmp_histogram[idx])); + } +} + + + + + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/histogram_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/histogram_3d_x.cl new file mode 100644 index 0000000..6f24a79 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/histogram_3d_x.cl @@ -0,0 +1,59 @@ +// adapted code from +// https://github.com/bgaster/opencl-book-samples/blob/master/src/Chapter_14/histogram/histogram_image.cl +// +// It was published unter BSD license according to +// https://code.google.com/archive/p/opencl-book-samples/ +// +// Book: OpenCL(R) Programming Guide +// Authors: Aaftab Munshi, Benedict Gaster, Timothy Mattson, James Fung, Dan Ginsburg +// ISBN-10: 0-321-74964-2 +// ISBN-13: 978-0-321-74964-2 +// Publisher: Addison-Wesley Professional +// URLs: http://safari.informit.com/9780132488006/ +// http://www.openclprogrammingguide.com +// +// +// + +#pragma OPENCL EXTENSION cl_khr_local_int32_base_atomics : enable + +const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +kernel void histogram_3d( + IMAGE_src_TYPE src, + IMAGE_dst_histogram_TYPE dst_histogram, + float minimum, + float maximum, + int step_size_x, + int step_size_y, + int step_size_z +) +{ + int image_width = GET_IMAGE_WIDTH(src); + int image_height = GET_IMAGE_HEIGHT(src); + int image_depth = GET_IMAGE_DEPTH(src); + int y = get_global_id(0); + float range = maximum - minimum; + + uint tmp_histogram[NUMBER_OF_HISTOGRAM_BINS]; + for (int i = 0; i < NUMBER_OF_HISTOGRAM_BINS; i++) { + tmp_histogram[i] = 0; + } + + for (int z = 0; z < image_depth; z+= step_size_z) { + for (int x = 0; x < image_width; x+= step_size_x) { + float clr = READ_src_IMAGE(src, sampler, (int4)(x, y, z, 0)).x; + uint indx_x; + indx_x = convert_uint_sat( (clr - minimum) * (float)(GET_IMAGE_WIDTH(dst_histogram) - 1) / range ); + tmp_histogram[indx_x]++; + } + } + + for (int idx = 0; idx < GET_IMAGE_WIDTH(dst_histogram); idx++) { + int4 pos = {idx, 0, y, 0}; + WRITE_dst_histogram_IMAGE(dst_histogram, pos, CONVERT_dst_histogram_PIXEL_TYPE(tmp_histogram[idx])); + } +} + + + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/label_spots_in_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/label_spots_in_x.cl new file mode 100644 index 0000000..8a2ddb3 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/label_spots_in_x.cl @@ -0,0 +1,30 @@ + + +__kernel void label_spots_in_x( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + IMAGE_spotCountPerX_TYPE spotCountPerX, + IMAGE_spotCountPerXY_TYPE spotCountPerXY +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int y = get_global_id(1); + const int z = get_global_id(2); + + int startingIndex = 0; + for (int iz = 0; iz < z; iz++) { + startingIndex = startingIndex + READ_IMAGE(spotCountPerXY,sampler,POS_spotCountPerXY_INSTANCE(iz, 0, 0, 0)).x; + } + for (int iy = 0; iy < y; iy++) { + startingIndex = startingIndex + READ_IMAGE(spotCountPerX,sampler,POS_spotCountPerX_INSTANCE(z, iy, 0, 0)).x; + } + + for(int x = 0; x < GET_IMAGE_WIDTH(src); x++) + { + float value = READ_src_IMAGE(src,sampler,POS_src_INSTANCE(x,y,z,0)).x; + if (value != 0) { + startingIndex++; + WRITE_IMAGE(dst, POS_dst_INSTANCE(x,y,z,0), CONVERT_dst_PIXEL_TYPE(startingIndex)); + } + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/labelled_spots_to_point_list_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/labelled_spots_to_point_list_x.cl new file mode 100644 index 0000000..d5f42f0 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/labelled_spots_to_point_list_x.cl @@ -0,0 +1,28 @@ + +__kernel void labelled_spots_to_point_list ( + IMAGE_src_TYPE src, + IMAGE_dst_point_list_TYPE dst_point_list +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int sx = get_global_id(0); + const int sy = get_global_id(1); + const int sz = get_global_id(2); + + const int index = ((int)READ_src_IMAGE(src, sampler, POS_src_INSTANCE(sx, sy, sz, 0)).x) - 1; + if (index < 0) { // background pixel + return; + } + + int n_dimensions = GET_IMAGE_HEIGHT(dst_point_list); + + WRITE_dst_point_list_IMAGE(dst_point_list, POS_dst_point_list_INSTANCE(index, 0, 0, 0), CONVERT_dst_point_list_PIXEL_TYPE(sx)); + + if (n_dimensions > 1) { + WRITE_dst_point_list_IMAGE(dst_point_list, POS_dst_point_list_INSTANCE(index, 1, 0, 0), CONVERT_dst_point_list_PIXEL_TYPE(sy)); + } + if (n_dimensions > 2) { + WRITE_dst_point_list_IMAGE(dst_point_list, POS_dst_point_list_INSTANCE(index, 2, 0, 0), CONVERT_dst_point_list_PIXEL_TYPE(sz)); + } + +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/laplace_box_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/laplace_box_2d_x.cl new file mode 100644 index 0000000..79a00ad --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/laplace_box_2d_x.cl @@ -0,0 +1,38 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + +__kernel void laplace_box_2d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float valueCenter = READ_src_IMAGE(src, sampler, pos).x; + + float valueRight = READ_src_IMAGE(src, sampler, (pos + (int2){1, 0})).x; + float valueLeft = READ_src_IMAGE(src, sampler, (pos + (int2){-1, 0})).x; + float valueBottom = READ_src_IMAGE(src, sampler, (pos + (int2){0, 1})).x; + float valueTop = READ_src_IMAGE(src, sampler, (pos + (int2){0, -1})).x; + + float valueA = READ_src_IMAGE(src, sampler, (pos + (int2){-1, -1})).x; + float valueB = READ_src_IMAGE(src, sampler, (pos + (int2){1, -1})).x; + float valueC = READ_src_IMAGE(src, sampler, (pos + (int2){-1, 1})).x; + float valueD = READ_src_IMAGE(src, sampler, (pos + (int2){1, 1})).x; + + float result = valueCenter * 8.0 + + valueRight * -1.0 + + valueLeft * -1.0 + + valueTop * -1.0 + + valueBottom * -1.0 + + valueA * -1.0 + + valueB * -1.0 + + valueC * -1.0 + + valueD * -1.0; + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(result)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/laplace_box_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/laplace_box_3d_x.cl new file mode 100644 index 0000000..b9ee396 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/laplace_box_3d_x.cl @@ -0,0 +1,29 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void laplace_box_3d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float result = 0; + for (int ax = -1; ax <= 1; ax++) { + for (int ay = -1; ay <= 1; ay++) { + for (int az = -1; az <= 1; az++) { + if (ax == 0 && ay == 0 && az == 0) { + result = result + READ_src_IMAGE(src, sampler, pos).x; + } else { + result = result + READ_src_IMAGE(src, sampler, (pos + (int4){ax, ay, az, 0})).x * -1; + } + } + } + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(result)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/laplace_diamond_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/laplace_diamond_2d_x.cl new file mode 100644 index 0000000..3332e02 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/laplace_diamond_2d_x.cl @@ -0,0 +1,28 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void laplace_diamond_2d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float valueCenter = READ_src_IMAGE(src, sampler, pos).x; + + float valueRight = READ_src_IMAGE(src, sampler, (pos + (int2){1, 0})).x; + float valueLeft = READ_src_IMAGE(src, sampler, (pos + (int2){-1, 0})).x; + float valueBottom = READ_src_IMAGE(src, sampler, (pos + (int2){0, 1})).x; + float valueTop = READ_src_IMAGE(src, sampler, (pos + (int2){0, -1})).x; + + float result = valueCenter * 4.0 + + valueRight * -1.0 + + valueLeft * -1.0 + + valueTop * -1.0 + + valueBottom * -1.0; + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(result)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/laplace_diamond_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/laplace_diamond_3d_x.cl new file mode 100644 index 0000000..68f2f63 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/laplace_diamond_3d_x.cl @@ -0,0 +1,33 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void laplace_diamond_3d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float valueCenter = READ_src_IMAGE(src, sampler, pos).x; + + float valueRight = READ_src_IMAGE(src, sampler, (pos + (int4){1, 0, 0, 0})).x; + float valueLeft = READ_src_IMAGE(src, sampler, (pos + (int4){-1, 0, 0, 0})).x; + float valueBottom = READ_src_IMAGE(src, sampler, (pos + (int4){0, 1, 0, 0})).x; + float valueTop = READ_src_IMAGE(src, sampler, (pos + (int4){0, -1, 0, 0})).x; + float valueFront = READ_src_IMAGE(src, sampler, (pos + (int4){0, 0, 1, 0})).x; + float valueBack = READ_src_IMAGE(src, sampler, (pos + (int4){0, 0, -1, 0})).x; + + float result = valueCenter * 6.0 + + valueRight * -1.0 + + valueLeft * -1.0 + + valueTop * -1.0 + + valueBottom * -1.0 + + valueFront * -1.0 + + valueBack * -1.0; + + WRITE_dst_IMAGE(dst, pos, CONVERT_dst_PIXEL_TYPE(result)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/logarithm_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/logarithm_2d_x.cl new file mode 100644 index 0000000..ccb5aa9 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/logarithm_2d_x.cl @@ -0,0 +1,18 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void logarithm_2d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const float input = (float)READ_src_IMAGE(src, sampler, pos).x; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(log( input )); + + WRITE_dst_IMAGE (dst, pos, value); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/logarithm_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/logarithm_3d_x.cl new file mode 100644 index 0000000..d20fa37 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/logarithm_3d_x.cl @@ -0,0 +1,19 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void logarithm_3d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const float input = (float)READ_src_IMAGE(src, sampler, pos).x; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(log( input )); + + WRITE_dst_IMAGE (dst, pos, value); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/mask.cl b/src/main/java/net/haesleinhuepf/clij/kernels/mask.cl deleted file mode 100644 index 2d5bb45..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/mask.cl +++ /dev/null @@ -1,60 +0,0 @@ -__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - -__kernel void mask_3d(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_IN_3D mask, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - DTYPE_IN value = 0; - if (READ_IMAGE_3D(mask, sampler, pos).x != 0) { - value = READ_IMAGE_3D(src, sampler, pos).x; - } - - WRITE_IMAGE_3D (dst, pos, CONVERT_DTYPE_OUT(value)); -} - - -__kernel void mask_2d(DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_IN_2D mask, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - DTYPE_IN value = 0; - if (READ_IMAGE_2D(mask, sampler, pos).x != 0) { - value = READ_IMAGE_2D(src, sampler, pos).x; - } - - WRITE_IMAGE_2D (dst, pos, CONVERT_DTYPE_OUT(value)); -} - - -__kernel void maskStackWithPlane(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_IN_2D mask, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos3d = (int4){x,y,z,0}; - const int2 pos2d = (int2){x,y}; - - DTYPE_IN value = 0; - if (READ_IMAGE_2D(mask, sampler, pos2d).x != 0) { - value = READ_IMAGE_3D(src, sampler, pos3d).x; - } - - WRITE_IMAGE_3D (dst, pos3d, CONVERT_DTYPE_OUT(value)); -} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/mask_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/mask_2d_x.cl new file mode 100644 index 0000000..2c35827 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/mask_2d_x.cl @@ -0,0 +1,20 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void mask_2d( + IMAGE_src_TYPE src, + IMAGE_mask_TYPE mask, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + IMAGE_src_PIXEL_TYPE value = 0; + if (READ_mask_IMAGE(mask, sampler, pos).x != 0) { + value = READ_src_IMAGE(src, sampler, pos).x; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/mask_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/mask_3d_x.cl new file mode 100644 index 0000000..a5bbe5b --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/mask_3d_x.cl @@ -0,0 +1,21 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void mask_3d( + IMAGE_src_TYPE src, + IMAGE_mask_TYPE mask, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + IMAGE_src_PIXEL_TYPE value = 0; + if (READ_mask_IMAGE(mask, sampler, pos).x != 0) { + value = READ_src_IMAGE(src, sampler, pos).x; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/mask_label_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/mask_label_2d_x.cl new file mode 100644 index 0000000..69ded1a --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/mask_label_2d_x.cl @@ -0,0 +1,23 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + + +__kernel void mask_label_2d( + IMAGE_src_TYPE src, + IMAGE_src_label_map_TYPE src_label_map, + const float label_id, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float value = 0; + if (fabs(((float)READ_src_label_map_IMAGE(src_label_map, sampler, pos).x) - label_id) < 0.1) { + value = READ_src_IMAGE(src, sampler, pos).x; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/mask_label_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/mask_label_3d_x.cl new file mode 100644 index 0000000..6decbfc --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/mask_label_3d_x.cl @@ -0,0 +1,23 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void mask_label_3d( + IMAGE_src_TYPE src, + IMAGE_src_label_map_TYPE src_label_map, + const float label_id, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float value = 0; + if (fabs(((float)READ_src_label_map_IMAGE(src_label_map, sampler, pos).x) - label_id) < 0.1) { + value = READ_src_IMAGE(src, sampler, pos).x; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(value)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/mask_stack_with_plane_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/mask_stack_with_plane_3d_x.cl new file mode 100644 index 0000000..c9408dd --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/mask_stack_with_plane_3d_x.cl @@ -0,0 +1,22 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void mask_stack_with_plane_3d( + IMAGE_src_TYPE src, + IMAGE_mask_TYPE mask, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos3d = (int4){x,y,z,0}; + const int2 pos2d = (int2){x,y}; + + IMAGE_src_PIXEL_TYPE value = 0; + if (READ_mask_IMAGE(mask, sampler, pos2d).x != 0) { + value = READ_src_IMAGE(src, sampler, pos3d).x; + } + + WRITE_dst_IMAGE (dst, pos3d, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/math.cl b/src/main/java/net/haesleinhuepf/clij/kernels/math.cl deleted file mode 100644 index 42c32ed..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/math.cl +++ /dev/null @@ -1,20 +0,0 @@ -__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - -__kernel void multiplyStackWithPlanePixelwise(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_IN_2D src1, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos3d = (int4){x,y,z,0}; - const int2 pos2d = (int2){x,y}; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(READ_IMAGE_3D(src, sampler, pos3d).x * READ_IMAGE_2D(src1, sampler, pos2d).x); - - WRITE_IMAGE_3D (dst, pos3d, value); -} - - diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/math2D.cl b/src/main/java/net/haesleinhuepf/clij/kernels/math2D.cl deleted file mode 100644 index 7afde8f..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/math2D.cl +++ /dev/null @@ -1,184 +0,0 @@ -__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - -__kernel void multiplyPixelwise_2d(DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_IN_2D src1, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - const float value = (float)READ_IMAGE_2D(src, sampler, pos).x * READ_IMAGE_2D(src1, sampler, pos).x; - - WRITE_IMAGE_2D (dst, pos, CONVERT_DTYPE_OUT(value)); -} - -__kernel void dividePixelwise_2d(DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_IN_2D src1, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - const float value = (float)READ_IMAGE_2D(src, sampler, pos).x / READ_IMAGE_2D(src1, sampler, pos).x; - - WRITE_IMAGE_2D (dst, pos, CONVERT_DTYPE_OUT(value)); -} - -__kernel void addPixelwise_2d(DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_IN_2D src1, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(READ_IMAGE_2D(src, sampler, pos).x + READ_IMAGE_2D(src1, sampler, pos).x); - - WRITE_IMAGE_2D (dst, pos, value); -} - - -__kernel void addScalar_2d(DTYPE_IMAGE_IN_2D src, - float scalar, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(READ_IMAGE_2D(src, sampler, pos).x + scalar); - - WRITE_IMAGE_2D (dst, pos, value); -} - -__kernel void multiplyScalar_2d(DTYPE_IMAGE_IN_2D src, - float scalar, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(READ_IMAGE_2D(src, sampler, pos).x * scalar); - - WRITE_IMAGE_2D (dst, pos, value); -} - -__kernel void maxPixelwise_2d(DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_IN_2D src1, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - const DTYPE_IN input = READ_IMAGE_2D(src, sampler, pos).x; - const DTYPE_IN input1 = READ_IMAGE_2D(src1, sampler, pos).x; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(max(input, input1)); - - WRITE_IMAGE_2D (dst, pos, value); -} - -__kernel void minPixelwise_2d(DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_IN_2D src1, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - const DTYPE_IN input = READ_IMAGE_2D(src, sampler, pos).x; - const DTYPE_IN input1 = READ_IMAGE_2D(src1, sampler, pos).x; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(min(input, input1)); - - WRITE_IMAGE_2D (dst, pos, value); -} - -__kernel void maxPixelwiseScalar_2d(DTYPE_IMAGE_IN_2D src, - float valueB, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - const DTYPE_IN input = READ_IMAGE_2D(src, sampler, pos).x; - const DTYPE_IN input1 = valueB; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(max(input, input1)); - - WRITE_IMAGE_2D (dst, pos, value); -} - -__kernel void minPixelwiseScalar_2d(DTYPE_IMAGE_IN_2D src, - float valueB, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - const DTYPE_IN input = READ_IMAGE_2D(src, sampler, pos).x; - const DTYPE_IN input1 = valueB; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(min(input, input1)); - - WRITE_IMAGE_2D (dst, pos, value); -} - - -__kernel void power_2d(DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_OUT_2D dst, - float exponent - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - const DTYPE_IN input = READ_IMAGE_2D(src, sampler, pos).x; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(pow(input, exponent)); - - WRITE_IMAGE_2D (dst, pos, value); -} - - -__kernel void multiply_pixelwise_with_coordinate_2d(DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_OUT_2D dst, - int dimension - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(READ_IMAGE_2D(src, sampler, pos).x * get_global_id(dimension)); - - WRITE_IMAGE_2D (dst, pos, value); -} - diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/math3D.cl b/src/main/java/net/haesleinhuepf/clij/kernels/math3D.cl deleted file mode 100644 index 24e79ef..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/math3D.cl +++ /dev/null @@ -1,213 +0,0 @@ -__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - -__kernel void multiplyPixelwise_3d(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_IN_3D src1, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - const float value = (float)READ_IMAGE_3D(src, sampler, pos).x * READ_IMAGE_3D(src1, sampler, pos).x; - - WRITE_IMAGE_3D (dst, pos, CONVERT_DTYPE_OUT(value)); -} - -__kernel void dividePixelwise_3d(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_IN_3D src1, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - const float value = (float)READ_IMAGE_3D(src, sampler, pos).x / READ_IMAGE_3D(src1, sampler, pos).x; - - WRITE_IMAGE_3D (dst, pos, CONVERT_DTYPE_OUT(value)); -} - -__kernel void multiplySliceBySliceWithScalars(DTYPE_IMAGE_IN_3D src, - __constant float* scalars, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos3d = (int4){x,y,z,0}; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(READ_IMAGE_3D(src, sampler, pos3d).x * scalars[z]); - - WRITE_IMAGE_3D (dst, pos3d, value); -} - - -__kernel void addPixelwise_3d(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_IN_3D src1, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(READ_IMAGE_3D(src, sampler, pos).x + READ_IMAGE_3D(src1, sampler, pos).x); - - WRITE_IMAGE_3D (dst, pos, value); -} - - -__kernel void addScalar_3d(DTYPE_IMAGE_IN_3D src, - float scalar, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(READ_IMAGE_3D(src, sampler, pos).x + scalar); - - WRITE_IMAGE_3D (dst, pos, value); -} - -__kernel void multiplyScalar_3d(DTYPE_IMAGE_IN_3D src, - float scalar, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(READ_IMAGE_3D(src, sampler, pos).x * scalar); - - WRITE_IMAGE_3D (dst, pos, value); -} - -__kernel void maxPixelwise_3d(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_IN_3D src1, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - const DTYPE_IN input = READ_IMAGE_3D(src, sampler, pos).x; - const DTYPE_IN input1 = READ_IMAGE_3D(src1, sampler, pos).x; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(max(input, input1)); - - WRITE_IMAGE_3D (dst, pos, value); -} - -__kernel void minPixelwise_3d(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_IN_3D src1, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - const DTYPE_IN input = READ_IMAGE_3D(src, sampler, pos).x; - const DTYPE_IN input1 = READ_IMAGE_3D(src1, sampler, pos).x; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(min(input, input1)); - - WRITE_IMAGE_3D (dst, pos, value); -} - -__kernel void maxPixelwiseScalar_3d(DTYPE_IMAGE_IN_3D src, - float valueB, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - const DTYPE_IN input = READ_IMAGE_3D(src, sampler, pos).x; - const DTYPE_IN input1 = valueB; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(max(input, input1)); - - WRITE_IMAGE_3D (dst, pos, value); -} - -__kernel void minPixelwiseScalar_3d(DTYPE_IMAGE_IN_3D src, - float valueB, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - const DTYPE_IN input = READ_IMAGE_3D(src, sampler, pos).x; - const DTYPE_IN input1 = valueB; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(min(input, input1)); - - WRITE_IMAGE_3D (dst, pos, value); -} - -__kernel void power_3d(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst, - float exponent - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - const DTYPE_IN input = READ_IMAGE_3D(src, sampler, pos).x; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(pow(input, exponent)); - - WRITE_IMAGE_3D (dst, pos, value); -} - -__kernel void multiply_pixelwise_with_coordinate_3d(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst, - int dimension - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - const DTYPE_OUT value = CONVERT_DTYPE_OUT(READ_IMAGE_3D(src, sampler, pos).x * get_global_id(dimension)); - - WRITE_IMAGE_3D (dst, pos, value); -} - - - - diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/matrix_multiply_float_buffer.cl b/src/main/java/net/haesleinhuepf/clij/kernels/matrix_multiply_float_buffer.cl new file mode 100644 index 0000000..995b121 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/matrix_multiply_float_buffer.cl @@ -0,0 +1,259 @@ +// Origin: https://github.com/CNugteren/myGEMM/blob/master/src/kernels.cl + +// ================================================================================================= +// Project: +// Exploring the performance of general matrix-multiplication on an NVIDIA Tesla K40m GPU. +// +// File information: +// Institution.... SURFsara +// Author......... Cedric Nugteren +// Changed at..... 2014-11-06 +// License........ MIT license +// Tab-size....... 4 spaces +// Line length.... 100 characters +// +// ================================================================================================= +// +// Matrices in column-major format +// A: K columns, M rows +// B: N columns, K rows +// C: N columns, M rows +// +// N +// o-----o +// | | +// K | [B] | +// | | +// o-----o +// K N +// o-------o o-----o +// M | [A] | M | [C] | +// | | | | +// o-------o o-----o +// +// +// C-code for column-major matrix multiplication with alpha=1 and beta=0: +// +// for (int m=0; m max || z == 0) { - max = value; - } - } - WRITE_IMAGE_2D(dst_max,(int2)(x,y), CONVERT_DTYPE_OUT(max)); -} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/maximum_image_and_scalar_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_image_and_scalar_2d_x.cl new file mode 100644 index 0000000..980a5cc --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_image_and_scalar_2d_x.cl @@ -0,0 +1,20 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void maximum_image_and_scalar_2d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst, + float valueB +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const float input = READ_src_IMAGE(src, sampler, pos).x; + const float input1 = valueB; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(max(input, input1)); + + WRITE_dst_IMAGE(dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/maximum_image_and_scalar_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_image_and_scalar_3d_x.cl new file mode 100644 index 0000000..898a9d9 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_image_and_scalar_3d_x.cl @@ -0,0 +1,21 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void maximum_image_and_scalar_3d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst, + float valueB +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const float input = READ_src_IMAGE(src, sampler, pos).x; + const float input1 = valueB; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(max(input, input1)); + + WRITE_dst_IMAGE(dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/maximum_images_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_images_2d_x.cl new file mode 100644 index 0000000..1799fd7 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_images_2d_x.cl @@ -0,0 +1,20 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void maximum_images_2d( + IMAGE_src_TYPE src, + IMAGE_src1_TYPE src1, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const IMAGE_src_PIXEL_TYPE input = READ_src_IMAGE(src, sampler, pos).x; + const IMAGE_src1_PIXEL_TYPE input1 = READ_src1_IMAGE(src1, sampler, pos).x; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(max(input, input1)); + + WRITE_dst_IMAGE(dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/maximum_images_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_images_3d_x.cl new file mode 100644 index 0000000..95807a8 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_images_3d_x.cl @@ -0,0 +1,21 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void maximum_images_3d( + IMAGE_src_TYPE src, + IMAGE_src1_TYPE src1, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const float input = READ_src_IMAGE(src, sampler, pos).x; + const float input1 = READ_src1_IMAGE(src1, sampler, pos).x; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(max(input, input1)); + + WRITE_dst_IMAGE(dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/maximum_octagon_box_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_octagon_box_2d_x.cl new file mode 100644 index 0000000..209f7aa --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_octagon_box_2d_x.cl @@ -0,0 +1,49 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void maximum_octagon_box_2d +( + IMAGE_dst_TYPE dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float maximum = READ_src_IMAGE(src, sampler, pos).x; + float value = READ_src_IMAGE(src, sampler, (pos + (int2){-1, 0})).x; + if (maximum < value) { + maximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, -1})).x; + if (maximum < value) { + maximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){1, 0})).x; + if (maximum < value) { + maximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, 1})).x; + if (maximum < value) { + maximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){-1, -1})).x; + if (maximum < value) { + maximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){1, -1})).x; + if (maximum < value) { + maximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){1, 1})).x; + if (maximum < value) { + maximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){-1, 1})).x; + if (maximum < value) { + maximum = value; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(maximum)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/maximum_octagon_box_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_octagon_box_3d_x.cl new file mode 100644 index 0000000..e2e885c --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_octagon_box_3d_x.cl @@ -0,0 +1,27 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void maximum_octagon_box_3d +( + IMAGE_dst_TYPE dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float maximum = READ_src_IMAGE(src, sampler, pos).x; + for (int ax = -1; ax <= 1; ax++) { + for (int ay = -1; ay <= 1; ay++) { + for (int az = -1; az <= 1; az++) { + float value = READ_src_IMAGE(src, sampler, (pos + (int4){ax, ay, az, 0})).x; + if (maximum < value) { + maximum = value; + } + } + } + } + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(maximum)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/maximum_octagon_diamond_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_octagon_diamond_2d_x.cl new file mode 100644 index 0000000..7f222c4 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_octagon_diamond_2d_x.cl @@ -0,0 +1,33 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void maximum_octagon_diamond_2d +( + IMAGE_dst_TYPE dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float maximum = READ_src_IMAGE(src, sampler, pos).x; + float value = READ_src_IMAGE(src, sampler, (pos + (int2){-1, 0})).x; + if (maximum < value) { + maximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, -1})).x; + if (maximum < value) { + maximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){1, 0})).x; + if (maximum < value) { + maximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, 1})).x; + if (maximum < value) { + maximum = value; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(maximum)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/maximum_octagon_diamond_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_octagon_diamond_3d_x.cl new file mode 100644 index 0000000..34ef9d0 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_octagon_diamond_3d_x.cl @@ -0,0 +1,42 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void maximum_octagon_diamond_3d +( + IMAGE_dst_TYPE dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float maximum = READ_src_IMAGE(src, sampler, pos).x; + float value = READ_src_IMAGE(src, sampler, (pos + (int4){-1, 0, 0, 0})).x; + if (maximum < value) { + maximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){1, 0, 0, 0})).x; + if (maximum < value) { + maximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, -1, 0, 0})).x; + if (maximum < value) { + maximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 1, 0, 0})).x; + if (maximum < value) { + maximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 0, -1, 0})).x; + if (maximum < value) { + maximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 0, 1, 0})).x; + if (maximum < value) { + maximum = value; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(maximum)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/maximum_of_masked_pixels_3d_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_of_masked_pixels_3d_2d_x.cl new file mode 100644 index 0000000..252da8b --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_of_masked_pixels_3d_2d_x.cl @@ -0,0 +1,32 @@ + + +__kernel void maximum_of_masked_pixels_3d_2d( + IMAGE_dst_max_TYPE dst_max, + IMAGE_dst_mask_TYPE dst_mask, + IMAGE_mask_TYPE mask, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + float max = 0; + float mask_value = 0; + bool initial = true; + for(int z = 0; z < GET_IMAGE_DEPTH(src); z++) + { + float binary = READ_mask_IMAGE(mask,sampler,(int4)(x,y,z,0)).x; + + if (binary != 0) { + mask_value = 1; + float value = READ_src_IMAGE(src,sampler,(int4)(x,y,z,0)).x; + if (value > max || initial) { + max = value; + initial = false; + } + } + } + WRITE_dst_max_IMAGE(dst_max,(int2)(x,y), CONVERT_dst_max_PIXEL_TYPE(max)); + WRITE_dst_mask_IMAGE(dst_mask,(int2)(x,y), CONVERT_dst_mask_PIXEL_TYPE(mask_value)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/maximum_of_touching_neighbors_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_of_touching_neighbors_x.cl new file mode 100644 index 0000000..5d14edf --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_of_touching_neighbors_x.cl @@ -0,0 +1,43 @@ + +__kernel void maximum_value_of_touching_neighbors ( + IMAGE_src_values_TYPE src_values, + IMAGE_src_touch_matrix_TYPE src_touch_matrix, + IMAGE_dst_values_TYPE dst_values, + int x_correction +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int label_id = get_global_id(0); + const int label_count = get_global_size(0); + + bool initialized = false; + float maximum = 0; + + int y = label_id; + int x = 0; + for (x = 0; x < label_id; x++) { + float value = READ_IMAGE(src_touch_matrix, sampler, POS_src_touch_matrix_INSTANCE(x, y, 0, 0)).x; + if (value > 0) { + value = READ_IMAGE(src_values, sampler, POS_src_values_INSTANCE(x + x_correction, 0, 0, 0)).x; + if (maximum < value || !initialized) { + maximum = value; + initialized = true; + } + } + } + + x = label_id; + for (y = label_id; y < label_count; y++) { + float value = READ_IMAGE(src_touch_matrix, sampler, POS_src_touch_matrix_INSTANCE(x, y, 0, 0)).x; + if (value > 0 || y == label_id) { + value = READ_IMAGE(src_values, sampler, POS_src_values_INSTANCE(y + x_correction, 0, 0, 0)).x; + if (maximum < value || !initialized) { + maximum = value; + initialized = true; + } + } + } + + WRITE_IMAGE(dst_values, POS_dst_values_INSTANCE(label_id, 0, 0, 0), CONVERT_dst_values_PIXEL_TYPE(maximum)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/maximum_projection_3d_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_projection_3d_2d_x.cl new file mode 100644 index 0000000..d50a7e5 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_projection_3d_2d_x.cl @@ -0,0 +1,19 @@ + +__kernel void maximum_projection_3d_2d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + float max = 0; + for(int z = 0; z < GET_IMAGE_DEPTH(src); z++) + { + float value = READ_src_IMAGE(src,sampler,(int4)(x,y,z,0)).x; + if (value > max || z == 0) { + max = value; + } + } + WRITE_dst_IMAGE(dst,(int2)(x,y), CONVERT_dst_PIXEL_TYPE(max)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/maximum_separable_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_separable_2d_x.cl new file mode 100644 index 0000000..6e193a5 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_separable_2d_x.cl @@ -0,0 +1,26 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void maximum_separable_2d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int dim, + const int N, + const float s +) +{ + const int i = get_global_id(0), j = get_global_id(1); + const int2 coord = (int2)(i,j); + const int2 dir = (int2)(dim==0,dim==1); + + // center + const int c = (N-1)/2; + + float res = (float)READ_src_IMAGE(src,sampler,coord).x; + for (int v = -c; v <= c; v++) { + if (v != 0) { + res = max(res, (float)(READ_src_IMAGE(src,sampler,coord+v*dir).x)); + } + } + WRITE_dst_IMAGE(dst,coord, CONVERT_dst_PIXEL_TYPE(res)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/maximum_separable_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_separable_3d_x.cl new file mode 100644 index 0000000..1a6392a --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_separable_3d_x.cl @@ -0,0 +1,25 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void maximum_separable_3d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int dim, + const int N, + const float s +) +{ + const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); + const int4 coord = (int4)(i,j,k,0); + const int4 dir = (int4)(dim==0,dim==1,dim==2,0); + + // center + const int c = (N-1)/2; + + float res = READ_src_IMAGE(src,sampler,coord).x; + for (int v = -c; v <= c; v++) { + res = max(res, (float)READ_src_IMAGE(src,sampler,coord+v*dir).x); + } + WRITE_dst_IMAGE(dst,coord, CONVERT_dst_PIXEL_TYPE(res)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/maximum_slice_by_slice_sphere_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_slice_by_slice_sphere_3d_x.cl new file mode 100644 index 0000000..9980eb3 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_slice_by_slice_sphere_3d_x.cl @@ -0,0 +1,40 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void maximum_slice_by_slice_sphere_3d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int Nx, + const int Ny +) +{ + const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); + const int4 coord = (int4){i,j,k,0}; + + const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, 0, 0 }; + IMAGE_dst_PIXEL_TYPE maximumValue = CONVERT_dst_PIXEL_TYPE(READ_src_IMAGE(src,sampler,coord).x); + float aSquared = e.x * e.x; + float bSquared = e.y * e.y; + if (aSquared == 0) { + aSquared = FLT_MIN; + } + if (bSquared == 0) { + bSquared = FLT_MIN; + } + + for (int x = -e.x; x <= e.x; x++) { + float xSquared = x * x; + for (int y = -e.y; y <= e.y; y++) { + float ySquared = y * y; + if (xSquared / aSquared + ySquared / bSquared <= 1.0) { + IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(READ_src_IMAGE(src,sampler,coord+((int4){x,y,0,0})).x); + if (value > maximumValue) { + maximumValue = value; + } + } + } + } + + IMAGE_dst_PIXEL_TYPE res = maximumValue; + WRITE_dst_IMAGE(dst, coord, res); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/maximum_sphere_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_sphere_2d_x.cl new file mode 100644 index 0000000..bb59341 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_sphere_2d_x.cl @@ -0,0 +1,43 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void maximum_sphere_2d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int Nx, + const int Ny +) +{ + const int i = get_global_id(0), j = get_global_id(1); + const int2 coord = (int2){i,j}; + const int4 e = (int4) { (Nx-1)/2, (Ny-1)/2, 0, 0 }; + + IMAGE_dst_PIXEL_TYPE maximumValue = CONVERT_dst_PIXEL_TYPE(READ_src_IMAGE(src,sampler,coord).x); + float aSquared = e.x * e.x; + float bSquared = e.y * e.y; + if (aSquared == 0) { + aSquared = FLT_MIN; + } + if (bSquared == 0) { + bSquared = FLT_MIN; + } + + int count = 0; + + for (int x = -e.x; x <= e.x; x++) { + float xSquared = x * x; + for (int y = -e.y; y <= e.y; y++) { + float ySquared = y * y; + if (xSquared / aSquared + ySquared / bSquared <= 1.0) { + IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(READ_src_IMAGE(src,sampler,coord+((int2){x,y})).x); + if (value > maximumValue) { + maximumValue = value; + } + } + } + } + + IMAGE_dst_PIXEL_TYPE res = maximumValue; + + WRITE_dst_IMAGE(dst, coord, res); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/maximum_sphere_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_sphere_3d_x.cl new file mode 100644 index 0000000..45420cb --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_sphere_3d_x.cl @@ -0,0 +1,54 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void maximum_sphere_3d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int Nx, + const int Ny, + const int Nz +) +{ + const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); + const int4 coord = (int4){i,j,k,0}; + + + const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, (Nz-1)/2, 0 }; + float maximumValue = (float)READ_src_IMAGE(src,sampler,coord).x; + float aSquared = e.x * e.x; + float bSquared = e.y * e.y; + float cSquared = e.z * e.z; + if (aSquared == 0) { + aSquared = FLT_MIN; + } + if (bSquared == 0) { + bSquared = FLT_MIN; + } + if (cSquared == 0) { + cSquared = FLT_MIN; + } + + for (int x = -e.x; x <= e.x; x++) { + float xSquared = x * x; + for (int y = -e.y; y <= e.y; y++) { + float ySquared = y * y; + for (int z = -e.z; z <= e.z; z++) { + float zSquared = z * z; + if (xSquared / aSquared + ySquared / bSquared + zSquared / cSquared <= 1.0) { + + int x1 = coord.x + x; + int x2 = coord.y + y; + int x3 = coord.z + z; + const int4 pos = (int4){x1,x2,x3,0}; + float value_res = (float)READ_src_IMAGE(src,sampler,pos).x; + if (value_res > maximumValue) { + maximumValue = value_res; + } + } + } + } + } + + IMAGE_dst_PIXEL_TYPE res = CONVERT_dst_PIXEL_TYPE(maximumValue); + WRITE_dst_IMAGE(dst, coord, res); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/maximum_x_projection_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_x_projection_x.cl new file mode 100644 index 0000000..846c243 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_x_projection_x.cl @@ -0,0 +1,19 @@ + +__kernel void maximum_x_projection ( + IMAGE_dst_max_TYPE dst_max, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int z = get_global_id(0); + const int y = get_global_id(1); + float max = 0; + for(int x = 0; x < GET_IMAGE_WIDTH(src); x++) + { + float value = READ_src_IMAGE(src,sampler,POS_src_INSTANCE(x,y,z,0)).x; + if (value > max || x == 0) { + max = value; + } + } + WRITE_dst_max_IMAGE(dst_max,POS_dst_max_INSTANCE(z,y,0,0), CONVERT_dst_max_PIXEL_TYPE(max)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/maximum_y_projection_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_y_projection_x.cl new file mode 100644 index 0000000..f1bfd4f --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_y_projection_x.cl @@ -0,0 +1,19 @@ + +__kernel void maximum_y_projection ( + IMAGE_dst_max_TYPE dst_max, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int z = get_global_id(1); + float max = 0; + for(int y = 0; y < GET_IMAGE_HEIGHT(src); y++) + { + float value = READ_src_IMAGE(src,sampler,POS_src_INSTANCE(x,y,z,0)).x; + if (value > max || y == 0) { + max = value; + } + } + WRITE_dst_max_IMAGE(dst_max,POS_dst_max_INSTANCE(x,z,0,0), CONVERT_dst_max_PIXEL_TYPE(max)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/maximum_z_projection_bounded_3d_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_z_projection_bounded_3d_2d_x.cl new file mode 100644 index 0000000..cd000f8 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_z_projection_bounded_3d_2d_x.cl @@ -0,0 +1,32 @@ + +__kernel void maximum_z_projection_bounded( + IMAGE_dst_max_TYPE dst_max, + IMAGE_src_TYPE src, + int min_z, + int max_z +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + float max = 0; + + int start = 0; + if (min_z > start) { + start = min_z; + } + + int end = GET_IMAGE_DEPTH(src) - 1; + if (max_z < end) { + end = max_z; + } + + for(int z = start; z <= end; z++) + { + float value = READ_IMAGE(src,sampler,(int4)(x,y,z,0)).x; + if (value > max || z == start) { + max = value; + } + } + WRITE_IMAGE(dst_max,(int2)(x,y), CONVERT_dst_max_PIXEL_TYPE(max)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/maximum_z_projection_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_z_projection_x.cl new file mode 100644 index 0000000..a8cfee4 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/maximum_z_projection_x.cl @@ -0,0 +1,21 @@ + +__kernel void maximum_z_projection( + IMAGE_dst_max_TYPE dst_max, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + float max = 0; + for(int z = 0; z < GET_IMAGE_DEPTH(src); z++) + { + POS_src_TYPE pos = POS_src_INSTANCE(x,y,z,0); + float value = READ_src_IMAGE(src,sampler,pos).x; + if (value > max || z == 0) { + max = value; + } + } + POS_dst_max_TYPE pos = POS_dst_max_INSTANCE(x,y,0,0); + WRITE_dst_max_IMAGE(dst_max, pos, CONVERT_dst_max_PIXEL_TYPE(max)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/mean_of_touching_neighbors_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/mean_of_touching_neighbors_x.cl new file mode 100644 index 0000000..953d260 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/mean_of_touching_neighbors_x.cl @@ -0,0 +1,42 @@ + +__kernel void mean_value_of_touching_neighbors ( + IMAGE_src_values_TYPE src_values, + IMAGE_src_touch_matrix_TYPE src_touch_matrix, + IMAGE_dst_values_TYPE dst_values, + int x_correction +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int label_id = get_global_id(0); + const int label_count = get_global_size(0); + + int count = 0; + float sum = 0; + + int y = label_id; + int x = 0; + for (x = 0; x < label_id; x++) { + float value = READ_IMAGE(src_touch_matrix, sampler, POS_src_touch_matrix_INSTANCE(x, y, 0, 0)).x; + if (value > 0) { + sum = sum + READ_IMAGE(src_values, sampler, POS_src_values_INSTANCE(x + x_correction, 0, 0, 0)).x; + count++; + } + } + + // assume the object is included in mean calculation + sum = sum + READ_IMAGE(src_values, sampler, POS_src_values_INSTANCE(label_id + x_correction, 0, 0, 0)).x; + count++; + + x = label_id; + for (y = label_id + 1; y < label_count; y++) { + float value = READ_IMAGE(src_touch_matrix, sampler, POS_src_touch_matrix_INSTANCE(x, y, 0, 0)).x; + if (value > 0) { + sum = sum + READ_IMAGE(src_values, sampler, POS_src_values_INSTANCE(y + x_correction, 0, 0, 0)).x; + count++; + } + } + + float average = sum / count; + WRITE_IMAGE(dst_values, POS_dst_values_INSTANCE(label_id, 0, 0, 0), CONVERT_dst_values_PIXEL_TYPE(average)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/mean_separable_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/mean_separable_2d_x.cl new file mode 100644 index 0000000..c93ec7c --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/mean_separable_2d_x.cl @@ -0,0 +1,28 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void mean_separable_2d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int dim, + const int N, + const float s +) +{ + const int i = get_global_id(0); + const int j = get_global_id(1); + const int2 coord = (int2)(i,j); + const int2 dir = (int2)(dim==0,dim==1); + + // center + const int c = (N-1)/2; + + float res = 0; + float count = 0; + for (int v = -c; v <= c; v++) { + res += (float)READ_src_IMAGE(src,sampler,coord+v*dir).x; + count += 1; + } + res /= count; + WRITE_dst_IMAGE(dst,coord, CONVERT_dst_PIXEL_TYPE(res)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/mean_separable_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/mean_separable_3d_x.cl new file mode 100644 index 0000000..d149f05 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/mean_separable_3d_x.cl @@ -0,0 +1,30 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void mean_separable_3d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int dim, + const int N, + const float s +) +{ + const int i = get_global_id(0); + const int j = get_global_id(1); + const int k = get_global_id(2); + + const int4 coord = (int4)(i,j,k,0); + const int4 dir = (int4)(dim==0, dim==1, dim==2, 0); + + // center + const int c = (N-1)/2; + + float res = 0; + float count = 0; + for (int v = -c; v <= c; v++) { + res = res + (float)READ_src_IMAGE(src,sampler,coord + v * dir).x; + count = count + 1; + } + res /= count; + WRITE_dst_IMAGE(dst,coord, CONVERT_dst_PIXEL_TYPE(res)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/mean_slice_by_slice_sphere_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/mean_slice_by_slice_sphere_3d_x.cl new file mode 100644 index 0000000..c10c21b --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/mean_slice_by_slice_sphere_3d_x.cl @@ -0,0 +1,43 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void mean_slice_by_slice_sphere_3d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int Nx, + const int Ny +) +{ + const int i = get_global_id(0); + const int j = get_global_id(1); + const int k = get_global_id(2); + const int4 coord = (int4){i,j,k,0}; + + const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, 0, 0 }; + + float aSquared = e.x * e.x; + float bSquared = e.y * e.y; + if (aSquared == 0) { + aSquared = FLT_MIN; + } + if (bSquared == 0) { + bSquared = FLT_MIN; + } + + float sum = 0; + int count = 0; + + for (int x = -e.x; x <= e.x; x++) { + float xSquared = x * x; + for (int y = -e.y; y <= e.y; y++) { + float ySquared = y * y; + if (xSquared / aSquared + ySquared / bSquared <= 1.0) { + sum = sum + READ_src_IMAGE(src,sampler,coord+((int4){x,y,0,0})).x; + count++; + } + } + } + + IMAGE_dst_PIXEL_TYPE res = CONVERT_dst_PIXEL_TYPE(sum / count); + WRITE_dst_IMAGE(dst, coord, res); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/mean_sphere_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/mean_sphere_2d_x.cl new file mode 100644 index 0000000..a486cc1 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/mean_sphere_2d_x.cl @@ -0,0 +1,41 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void mean_sphere_2d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int Nx, + const int Ny +) +{ + const int i = get_global_id(0); + const int j = get_global_id(1); + const int2 coord = (int2){i,j}; + + const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, 0, 0 }; + int count = 0; + float sum = 0; + + float aSquared = e.x * e.x; + float bSquared = e.y * e.y; + if (aSquared == 0) { + aSquared = FLT_MIN; + } + if (bSquared == 0) { + bSquared = FLT_MIN; + } + + for (int x = -e.x; x <= e.x; x++) { + float xSquared = x * x; + for (int y = -e.y; y <= e.y; y++) { + float ySquared = y * y; + if (xSquared / aSquared + ySquared / bSquared <= 1.0) { + sum = sum + READ_src_IMAGE(src,sampler,coord+((int2){x,y})).x; + count++; + } + } + } + + IMAGE_dst_PIXEL_TYPE res = CONVERT_dst_PIXEL_TYPE(sum / count); + WRITE_dst_IMAGE(dst, coord, res); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/mean_sphere_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/mean_sphere_3d_x.cl new file mode 100644 index 0000000..687dc81 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/mean_sphere_3d_x.cl @@ -0,0 +1,57 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void mean_sphere_3d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int Nx, + const int Ny, + const int Nz +) +{ + const int i = get_global_id(0); + const int j = get_global_id(1); + const int k = get_global_id(2); + const int4 coord = (int4){i,j,k,0}; + + const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, (Nz-1)/2, 0 }; + int count = 0; + float sum = 0; + + float aSquared = e.x * e.x; + float bSquared = e.y * e.y; + float cSquared = e.z * e.z; + if (aSquared == 0) { + aSquared = FLT_MIN; + } + if (bSquared == 0) { + bSquared = FLT_MIN; + } + if (cSquared == 0) { + cSquared = FLT_MIN; + } + + for (int x = -e.x; x <= e.x; x++) { + float xSquared = x * x; + for (int y = -e.y; y <= e.y; y++) { + float ySquared = y * y; + for (int z = -e.z; z <= e.z; z++) { + float zSquared = z * z; + if (xSquared / aSquared + ySquared / bSquared + zSquared / cSquared <= 1.0) { + + int x1 = coord.x + x; + int x2 = coord.y + y; + int x3 = coord.z + z; + const int4 pos = (int4){x1,x2,x3,0}; + float value_res = (float)READ_src_IMAGE(src,sampler,pos).x; + sum = sum + value_res; + count++; + } + } + } + } + + + IMAGE_dst_PIXEL_TYPE res = CONVERT_dst_PIXEL_TYPE(sum / count); + WRITE_dst_IMAGE(dst, coord, res); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/mean_x_projection_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/mean_x_projection_x.cl new file mode 100644 index 0000000..c29d675 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/mean_x_projection_x.cl @@ -0,0 +1,18 @@ + +__kernel void mean_x_projection ( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int z = get_global_id(0); + const int y = get_global_id(1); + float sum = 0; + int count = 0; + for(int x = 0; x < GET_IMAGE_WIDTH(src); x++) + { + sum = sum + READ_src_IMAGE(src,sampler,POS_src_INSTANCE(x,y,z,0)).x; + count++; + } + WRITE_dst_IMAGE(dst,POS_dst_INSTANCE(z,y,0,0), CONVERT_dst_PIXEL_TYPE(sum / count)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/mean_y_projection_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/mean_y_projection_x.cl new file mode 100644 index 0000000..ac04af5 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/mean_y_projection_x.cl @@ -0,0 +1,18 @@ + +__kernel void mean_y_projection ( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int z = get_global_id(1); + float sum = 0; + int count = 0; + for(int y = 0; y < GET_IMAGE_HEIGHT(src); y++) + { + sum = sum + READ_src_IMAGE(src,sampler,POS_src_INSTANCE(x,y,z,0)).x; + count++; + } + WRITE_dst_IMAGE(dst,POS_dst_INSTANCE(x,z,0,0), CONVERT_dst_PIXEL_TYPE(sum / count)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/mean_z_projection_bounded_3d_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/mean_z_projection_bounded_3d_2d_x.cl new file mode 100644 index 0000000..f5e9410 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/mean_z_projection_bounded_3d_2d_x.cl @@ -0,0 +1,32 @@ + +__kernel void mean_z_projection_bounded_3d_2d( + DTYPE_IMAGE_OUT_2D dst_mean, + DTYPE_IMAGE_IN_3D src, + int min_z, + int max_z +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + float sum = 0; + float count = 1; + + int start = 0; + if (min_z > start) { + start = min_z; + } + + int end = GET_IMAGE_IN_DEPTH(src) - 1; + if (max_z < end) { + end = max_z; + } + + for(int z = start; z <= end; z++) + { + float value = READ_IMAGE_3D(src,sampler,(int4)(x,y,z,0)).x; + sum = sum + value; + count = count + 1; + } + WRITE_IMAGE_2D(dst_mean,(int2)(x,y), CONVERT_DTYPE_OUT(sum / count)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/mean_z_projection_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/mean_z_projection_x.cl new file mode 100644 index 0000000..51ad9fd --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/mean_z_projection_x.cl @@ -0,0 +1,19 @@ + + +__kernel void mean_z_projection( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + float sum = 0; + int count = 0; + for(int z = 0; z < GET_IMAGE_DEPTH(src); z++) + { + sum = sum + READ_src_IMAGE(src,sampler,POS_src_INSTANCE(x,y,z,0)).x; + count++; + } + WRITE_dst_IMAGE(dst,POS_dst_INSTANCE(x,y,0,0), CONVERT_dst_PIXEL_TYPE(sum / count)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/median_box_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/median_box_2d_x.cl new file mode 100644 index 0000000..6a27b8e --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/median_box_2d_x.cl @@ -0,0 +1,56 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +inline void sort(IMAGE_dst_PIXEL_TYPE array[], int array_size) +{ + IMAGE_dst_PIXEL_TYPE temp; + for(int i = 0; i < array_size; i++) { + int j; + temp = array[i]; + for(j = i - 1; j >= 0 && temp < array[j]; j--) { + array[j+1] = array[j]; + } + array[j+1] = temp; + } +} + +inline IMAGE_dst_PIXEL_TYPE median(IMAGE_dst_PIXEL_TYPE array[], int array_size) +{ + sort(array, array_size); + return array[array_size / 2]; +} + +__kernel void median_box_2d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int Nx, + const int Ny +) +{ + const int i = get_global_id(0), j = get_global_id(1); + const int2 coord = (int2){i,j}; + + int array_size = Nx * Ny; + IMAGE_dst_PIXEL_TYPE array[MAX_ARRAY_SIZE]; + + const int4 e = (int4) { (Nx-1)/2, (Ny-1)/2, 0, 0 }; + + float aSquared = e.x * e.x; + float bSquared = e.y * e.y; + + int count = 0; + + for (int x = -e.x; x <= e.x; x++) { + for (int y = -e.y; y <= e.y; y++) { + array[count] = (IMAGE_dst_PIXEL_TYPE)READ_src_IMAGE(src,sampler,coord+((int2){x,y})).x; + count++; + } + } + array_size = count; + //copyBoxNeighborhoodToArray(src, array, coord, Nx, Ny); + + IMAGE_dst_PIXEL_TYPE res = median(array, array_size); + WRITE_dst_IMAGE(dst, coord, res); +} + + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/median_box_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/median_box_3d_x.cl new file mode 100644 index 0000000..8342e21 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/median_box_3d_x.cl @@ -0,0 +1,66 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +inline void sort(IMAGE_dst_PIXEL_TYPE array[], int array_size) +{ + IMAGE_dst_PIXEL_TYPE temp; + for(int i = 0; i < array_size; i++) { + int j; + temp = array[i]; + for(j = i - 1; j >= 0 && temp < array[j]; j--) { + array[j+1] = array[j]; + } + array[j+1] = temp; + } +} + +inline IMAGE_dst_PIXEL_TYPE median(IMAGE_dst_PIXEL_TYPE array[], int array_size) +{ + sort(array, array_size); + return array[array_size / 2]; +} + + +__kernel void median_box_3d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int Nx, + const int Ny, + const int Nz +) +{ + const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); + const int4 coord = (int4){i,j,k,0}; + + int array_size = Nx * Ny * Nz; + IMAGE_dst_PIXEL_TYPE array[MAX_ARRAY_SIZE]; + + // centers + const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, (Nz-1)/2, 0 }; + + int count = 0; + + float aSquared = e.x * e.x; + float bSquared = e.y * e.y; + float cSquared = e.z * e.z; + + for (int x = -e.x; x <= e.x; x++) { + for (int y = -e.y; y <= e.y; y++) { + for (int z = -e.z; z <= e.z; z++) { + int x1 = coord.x + x; + int x2 = coord.y + y; + int x3 = coord.z + z; + const int4 pos = (int4){x1,x2,x3,0}; + float value_res = (float)READ_src_IMAGE(src,sampler,pos).x; + array[count] = value_res; + count++; + } + } + } + array_size = count; + // = copyBoxVolumeNeighborhoodToArray(src, array, coord, Nx, Ny, Nz); + + IMAGE_dst_PIXEL_TYPE res = median(array, array_size); + WRITE_dst_IMAGE(dst, coord, res); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/median_of_touching_neighbors_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/median_of_touching_neighbors_x.cl new file mode 100644 index 0000000..70c38b6 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/median_of_touching_neighbors_x.cl @@ -0,0 +1,64 @@ + + +inline void sort(float array[], int array_size) +{ + float temp; + for(int i = 0; i < array_size; i++) { + int j; + temp = array[i]; + for(j = i - 1; j >= 0 && temp < array[j]; j--) { + array[j+1] = array[j]; + } + array[j+1] = temp; + } +} + +inline float median(float array[], int array_size) +{ + sort(array, array_size); + return array[array_size / 2]; +} + +__kernel void median_value_of_touching_neighbors ( + IMAGE_src_values_TYPE src_values, + IMAGE_src_touch_matrix_TYPE src_touch_matrix, + IMAGE_dst_values_TYPE dst_values, + int x_correction +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int label_id = get_global_id(0); + const int label_count = get_global_size(0); + + float array[MAX_ARRAY_SIZE]; + + int count = 0; + float sum = 0; + + int y = label_id; + int x = 0; + for (x = 0; x < label_id; x++) { + float value = READ_IMAGE(src_touch_matrix, sampler, POS_src_touch_matrix_INSTANCE(x, y, 0, 0)).x; + if (value > 0) { + array[count] = READ_IMAGE(src_values, sampler, POS_src_values_INSTANCE(x + x_correction, 0, 0, 0)).x; + count++; + } + } + + // assume the object is included in mean calculation + array[count] = READ_IMAGE(src_values, sampler, POS_src_values_INSTANCE(label_id + x_correction, 0, 0, 0)).x; + count++; + + x = label_id; + for (y = label_id + 1; y < label_count; y++) { + float value = READ_IMAGE(src_touch_matrix, sampler, POS_src_touch_matrix_INSTANCE(x, y, 0, 0)).x; + if (value > 0) { + array[count] = READ_IMAGE(src_values, sampler, POS_src_values_INSTANCE(y + x_correction, 0, 0, 0)).x; + count++; + } + } + + float med = median(array, count); + WRITE_IMAGE(dst_values, POS_dst_values_INSTANCE(label_id, 0, 0, 0), CONVERT_dst_values_PIXEL_TYPE(med)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/median_slice_by_slice_box_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/median_slice_by_slice_box_3d_x.cl new file mode 100644 index 0000000..4c245a5 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/median_slice_by_slice_box_3d_x.cl @@ -0,0 +1,58 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +inline void sort(IMAGE_dst_PIXEL_TYPE array[], int array_size) +{ + IMAGE_dst_PIXEL_TYPE temp; + for(int i = 0; i < array_size; i++) { + int j; + temp = array[i]; + for(j = i - 1; j >= 0 && temp < array[j]; j--) { + array[j+1] = array[j]; + } + array[j+1] = temp; + } +} + +inline IMAGE_dst_PIXEL_TYPE median(IMAGE_dst_PIXEL_TYPE array[], int array_size) +{ + sort(array, array_size); + return array[array_size / 2]; +} + +__kernel void median_slice_by_slice_box_3d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int Nx, + const int Ny +) +{ + const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); + const int4 coord = (int4){i,j,k,0}; + + int array_size = Nx * Ny; + IMAGE_dst_PIXEL_TYPE array[MAX_ARRAY_SIZE]; + + + // centers + const int4 e = (int4) { (Nx-1)/2, (Ny-1)/2, 0, 0 }; + + float aSquared = e.x * e.x; + float bSquared = e.y * e.y; + + int count = 0; + + for (int x = -e.x; x <= e.x; x++) { + float xSquared = x * x; + for (int y = -e.y; y <= e.y; y++) { + array[count] = (IMAGE_dst_PIXEL_TYPE)READ_src_IMAGE(src,sampler,coord+((int4){x,y,0,0})).x; + count++; + } + } + array_size = count; + //copyBoxSliceNeighborhoodToArray(src, array, coord, Nx, Ny); + + IMAGE_dst_PIXEL_TYPE res = median(array, array_size); + WRITE_dst_IMAGE(dst, coord, res); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/median_slice_by_slice_sphere_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/median_slice_by_slice_sphere_3d_x.cl new file mode 100644 index 0000000..f12a8ed --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/median_slice_by_slice_sphere_3d_x.cl @@ -0,0 +1,60 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +inline void sort(IMAGE_dst_PIXEL_TYPE array[], int array_size) +{ + IMAGE_dst_PIXEL_TYPE temp; + for(int i = 0; i < array_size; i++) { + int j; + temp = array[i]; + for(j = i - 1; j >= 0 && temp < array[j]; j--) { + array[j+1] = array[j]; + } + array[j+1] = temp; + } +} + +inline IMAGE_dst_PIXEL_TYPE median(IMAGE_dst_PIXEL_TYPE array[], int array_size) +{ + sort(array, array_size); + return array[array_size / 2]; +} + +__kernel void median_slice_by_slice_sphere_3d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int Nx, + const int Ny +) +{ + const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); + const int4 coord = (int4){i,j,k,0}; + + int array_size = Nx * Ny; + IMAGE_dst_PIXEL_TYPE array[MAX_ARRAY_SIZE]; + + // centers + const int4 e = (int4) { (Nx-1)/2, (Ny-1)/2, 0, 0 }; + + float aSquared = e.x * e.x; + float bSquared = e.y * e.y; + + int count = 0; + + for (int x = -e.x; x <= e.x; x++) { + float xSquared = x * x; + for (int y = -e.y; y <= e.y; y++) { + float ySquared = y * y; + if (xSquared / aSquared + ySquared / bSquared <= 1.0) { + array[count] = (IMAGE_dst_PIXEL_TYPE)READ_src_IMAGE(src,sampler,coord+((int4){x,y,0,0})).x; + count++; + } + } + } + array_size = count; + //copySliceNeighborhoodToArray(src, array, coord, Nx, Ny); + + IMAGE_dst_PIXEL_TYPE res = median(array, array_size); + WRITE_dst_IMAGE(dst, coord, res); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/median_sphere_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/median_sphere_2d_x.cl new file mode 100644 index 0000000..d3c20df --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/median_sphere_2d_x.cl @@ -0,0 +1,64 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +inline void sort(IMAGE_dst_PIXEL_TYPE array[], int array_size) +{ + IMAGE_dst_PIXEL_TYPE temp; + for(int i = 0; i < array_size; i++) { + int j; + temp = array[i]; + for(j = i - 1; j >= 0 && temp < array[j]; j--) { + array[j+1] = array[j]; + } + array[j+1] = temp; + } +} + +inline IMAGE_dst_PIXEL_TYPE median(IMAGE_dst_PIXEL_TYPE array[], int array_size) +{ + sort(array, array_size); + return array[array_size / 2]; +} + +__kernel void median_sphere_2d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int Nx, + const int Ny +) +{ + const int i = get_global_id(0), j = get_global_id(1); + const int2 coord = (int2){i,j}; + + int array_size = Nx * Ny; + IMAGE_dst_PIXEL_TYPE array[MAX_ARRAY_SIZE]; + + + const int4 e = (int4) { (Nx-1)/2, (Ny-1)/2, 0, 0 }; + + float aSquared = e.x * e.x; + float bSquared = e.y * e.y; + if (aSquared == 0) { + aSquared = FLT_MIN; + } + if (bSquared == 0) { + bSquared = FLT_MIN; + } + + int count = 0; + + for (int x = -e.x; x <= e.x; x++) { + float xSquared = x * x; + for (int y = -e.y; y <= e.y; y++) { + float ySquared = y * y; + if (xSquared / aSquared + ySquared / bSquared <= 1.0) { + array[count] = (IMAGE_dst_PIXEL_TYPE)READ_src_IMAGE(src,sampler,coord+((int2){x,y})).x; + count++; + } + } + } + array_size = count; + + IMAGE_dst_PIXEL_TYPE res = median(array, array_size); + WRITE_dst_IMAGE(dst, coord, res); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/median_sphere_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/median_sphere_3d_x.cl new file mode 100644 index 0000000..92c085e --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/median_sphere_3d_x.cl @@ -0,0 +1,80 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +inline void sort(IMAGE_dst_PIXEL_TYPE array[], int array_size) +{ + IMAGE_dst_PIXEL_TYPE temp; + for(int i = 0; i < array_size; i++) { + int j; + temp = array[i]; + for(j = i - 1; j >= 0 && temp < array[j]; j--) { + array[j+1] = array[j]; + } + array[j+1] = temp; + } +} + +inline IMAGE_dst_PIXEL_TYPE median(IMAGE_dst_PIXEL_TYPE array[], int array_size) +{ + sort(array, array_size); + return array[array_size / 2]; +} + +__kernel void median_sphere_3d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int Nx, + const int Ny, + const int Nz +) +{ + const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); + const int4 coord = (int4){i,j,k,0}; + + int array_size = Nx * Ny * Nz; + IMAGE_dst_PIXEL_TYPE array[MAX_ARRAY_SIZE]; + + // centers + const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, (Nz-1)/2, 0 }; + + int count = 0; + + float aSquared = e.x * e.x; + float bSquared = e.y * e.y; + float cSquared = e.z * e.z; + if (aSquared == 0) { + aSquared = FLT_MIN; + } + if (bSquared == 0) { + bSquared = FLT_MIN; + } + if (cSquared == 0) { + cSquared = FLT_MIN; + } + + for (int x = -e.x; x <= e.x; x++) { + float xSquared = x * x; + for (int y = -e.y; y <= e.y; y++) { + float ySquared = y * y; + for (int z = -e.z; z <= e.z; z++) { + float zSquared = z * z; + if (xSquared / aSquared + ySquared / bSquared + zSquared / cSquared <= 1.0) { + int x1 = coord.x + x; + int x2 = coord.y + y; + int x3 = coord.z + z; + const int4 pos = (int4){x1,x2,x3,0}; + float value_res = (float)READ_src_IMAGE(src,sampler,pos).x; + array[count] = value_res; + count++; + } + } + } + } + + array_size = count; + //copyVolumeNeighborhoodToArray(src, array, coord, Nx, Ny, Nz); + + IMAGE_dst_PIXEL_TYPE res = median(array, array_size); + WRITE_dst_IMAGE(dst, coord, res); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/median_z_projection_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/median_z_projection_x.cl new file mode 100644 index 0000000..f7878c0 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/median_z_projection_x.cl @@ -0,0 +1,45 @@ + +inline void sort(IMAGE_dst_PIXEL_TYPE array[], int array_size) +{ + IMAGE_dst_PIXEL_TYPE temp; + for(int i = 0; i < array_size; i++) { + int j; + temp = array[i]; + for(j = i - 1; j >= 0 && temp < array[j]; j--) { + array[j+1] = array[j]; + } + array[j+1] = temp; + } +} + +inline IMAGE_dst_PIXEL_TYPE median(IMAGE_dst_PIXEL_TYPE array[], int array_size) +{ + sort(array, array_size); + return array[array_size / 2]; +} + + +__kernel void median_z_projection +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) +{ + IMAGE_dst_PIXEL_TYPE array[MAX_ARRAY_SIZE]; + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + + int count = 0; + for(int z = 0; z < GET_IMAGE_DEPTH(src); z++) + { + array[count] = (float)(READ_src_IMAGE(src,sampler,POS_src_INSTANCE(x,y,z,0)).x); + count++; + } + + IMAGE_dst_PIXEL_TYPE res = median(array, count); + + WRITE_dst_IMAGE(dst,POS_dst_INSTANCE(x,y,0,0), CONVERT_dst_PIXEL_TYPE(res)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_distance_of_touching_neighbors_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_distance_of_touching_neighbors_x.cl new file mode 100644 index 0000000..847c45b --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_distance_of_touching_neighbors_x.cl @@ -0,0 +1,38 @@ + +__kernel void minimum_distance_of_touching_neighbors ( + IMAGE_src_distance_matrix_TYPE src_distance_matrix, + IMAGE_src_touch_matrix_TYPE src_touch_matrix, + IMAGE_dst_minimum_distance_list_TYPE dst_minimum_distance_list +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int label_id = get_global_id(0); + const int label_count = get_global_size(0); + + float minimum = 0; + + int y = label_id; + int x = 0; + for (x = 0; x < label_id; x++) { + POS_src_touch_matrix_TYPE pos = POS_src_touch_matrix_INSTANCE(x, y, 0, 0); + float value = READ_src_touch_matrix_IMAGE(src_touch_matrix, sampler, pos).x; + if (value > 0) { + if (minimum > value || minimum == 0) { + minimum = READ_src_distance_matrix_IMAGE(src_distance_matrix, sampler, pos).x; + } + } + } + x = label_id; + for (y = label_id + 1; y < label_count; y++) { + POS_src_touch_matrix_TYPE pos = POS_src_touch_matrix_INSTANCE(x, y, 0, 0); + float value = READ_src_touch_matrix_IMAGE(src_touch_matrix, sampler, pos).x; + if (value > 0) { + if (minimum > value || minimum == 0) { + minimum = READ_src_distance_matrix_IMAGE(src_distance_matrix, sampler, pos).x; + } + } + } + + WRITE_dst_minimum_distance_list_IMAGE(dst_minimum_distance_list, (POS_dst_minimum_distance_list_INSTANCE(label_id, 0, 0, 0)), CONVERT_dst_minimum_distance_list_PIXEL_TYPE(minimum)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_image_and_scalar_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_image_and_scalar_2d_x.cl new file mode 100644 index 0000000..c6ab918 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_image_and_scalar_2d_x.cl @@ -0,0 +1,23 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + +__kernel void minimum_image_and_scalar_2d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst, + float valueB +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const float input = READ_src_IMAGE(src, sampler, pos).x; + const float input1 = valueB; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(min(input, input1)); + + WRITE_dst_IMAGE(dst, pos, value); +} + + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_image_and_scalar_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_image_and_scalar_3d_x.cl new file mode 100644 index 0000000..46adcf3 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_image_and_scalar_3d_x.cl @@ -0,0 +1,21 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void minimum_image_and_scalar_3d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst, + float valueB +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const float input = READ_src_IMAGE(src, sampler, pos).x; + const float input1 = valueB; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(min(input, input1)); + + WRITE_dst_IMAGE(dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_images_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_images_2d_x.cl new file mode 100644 index 0000000..7759a58 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_images_2d_x.cl @@ -0,0 +1,20 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void minimum_images_2d( + IMAGE_src_TYPE src, + IMAGE_src1_TYPE src1, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const float input = READ_src_IMAGE(src, sampler, pos).x; + const float input1 = READ_src1_IMAGE(src1, sampler, pos).x; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(min(input, input1)); + + WRITE_dst_IMAGE(dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_images_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_images_3d_x.cl new file mode 100644 index 0000000..888da24 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_images_3d_x.cl @@ -0,0 +1,21 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void minimum_images_3d( + IMAGE_src_TYPE src, + IMAGE_src1_TYPE src1, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const float input = READ_src_IMAGE(src, sampler, pos).x; + const float input1 = READ_src1_IMAGE(src1, sampler, pos).x; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(min(input, input1)); + + WRITE_dst_IMAGE(dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_octagon_box_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_octagon_box_2d_x.cl new file mode 100644 index 0000000..4e91b9a --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_octagon_box_2d_x.cl @@ -0,0 +1,49 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void minimum_octagon_box_2d +( + IMAGE_dst_TYPE dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float minimum = READ_src_IMAGE(src, sampler, pos).x; + float value = READ_src_IMAGE(src, sampler, (pos + (int2){-1, 0})).x; + if (minimum > value) { + minimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, -1})).x; + if (minimum > value) { + minimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){1, 0})).x; + if (minimum > value) { + minimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, 1})).x; + if (minimum > value) { + minimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){-1, -1})).x; + if (minimum > value) { + minimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){1, -1})).x; + if (minimum > value) { + minimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){1, 1})).x; + if (minimum > value) { + minimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){-1, 1})).x; + if (minimum > value) { + minimum = value; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(minimum)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_octagon_box_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_octagon_box_3d_x.cl new file mode 100644 index 0000000..744623b --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_octagon_box_3d_x.cl @@ -0,0 +1,27 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void minimum_octagon_box_3d +( + IMAGE_dst_TYPE dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float minimum = READ_src_IMAGE(src, sampler, pos).x; + for (int ax = -1; ax <= 1; ax++) { + for (int ay = -1; ay <= 1; ay++) { + for (int az = -1; az <= 1; az++) { + float value = READ_src_IMAGE(src, sampler, (pos + (int4){ax, ay, az, 0})).x; + if (minimum > value) { + minimum = value; + } + } + } + } + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(minimum)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_octagon_diamond_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_octagon_diamond_2d_x.cl new file mode 100644 index 0000000..642c595 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_octagon_diamond_2d_x.cl @@ -0,0 +1,33 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void minimum_octagon_diamond_2d +( + IMAGE_dst_TYPE dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float minimum = READ_src_IMAGE(src, sampler, pos).x; + float value = READ_src_IMAGE(src, sampler, (pos + (int2){-1, 0})).x; + if (minimum > value) { + minimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, -1})).x; + if (minimum > value) { + minimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){1, 0})).x; + if (minimum > value) { + minimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, 1})).x; + if (minimum > value) { + minimum = value; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(minimum)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_octagon_diamond_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_octagon_diamond_3d_x.cl new file mode 100644 index 0000000..b429594 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_octagon_diamond_3d_x.cl @@ -0,0 +1,42 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void minimum_octagon_diamond_3d +( + IMAGE_dst_TYPE dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float minimum = READ_src_IMAGE(src, sampler, pos).x; + float value = READ_src_IMAGE(src, sampler, (pos + (int4){-1, 0, 0, 0})).x; + if (minimum > value) { + minimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){1, 0, 0, 0})).x; + if (minimum > value) { + minimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, -1, 0, 0})).x; + if (minimum > value) { + minimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 1, 0, 0})).x; + if (minimum > value) { + minimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 0, -1, 0})).x; + if (minimum > value) { + minimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 0, 1, 0})).x; + if (minimum > value) { + minimum = value; + } + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(minimum)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_of_masked_pixels_3d_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_of_masked_pixels_3d_2d_x.cl new file mode 100644 index 0000000..c8cf9c8 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_of_masked_pixels_3d_2d_x.cl @@ -0,0 +1,32 @@ + + +__kernel void minimum_of_masked_pixels_3d_2d( + IMAGE_dst_min_TYPE dst_min, + IMAGE_dst_mask_TYPE dst_mask, + IMAGE_mask_TYPE mask, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + float min = 0; + float mask_value = 0; + bool initial = true; + for(int z = 0; z < GET_IMAGE_DEPTH(src); z++) + { + float binary = READ_mask_IMAGE(mask,sampler,(int4)(x,y,z,0)).x; + + if (binary != 0) { + mask_value = 1; + float value = READ_src_IMAGE(src,sampler,(int4)(x,y,z,0)).x; + if (value < min || initial) { + min = value; + initial = false; + } + } + } + WRITE_dst_min_IMAGE(dst_min,(int2)(x,y), CONVERT_dst_min_PIXEL_TYPE(min)); + WRITE_dst_mask_IMAGE(dst_mask,(int2)(x,y), CONVERT_dst_mask_PIXEL_TYPE(mask_value)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_of_touching_neighbors_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_of_touching_neighbors_x.cl new file mode 100644 index 0000000..c4bec68 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_of_touching_neighbors_x.cl @@ -0,0 +1,43 @@ + +__kernel void minimum_value_of_touching_neighbors ( + IMAGE_src_values_TYPE src_values, + IMAGE_src_touch_matrix_TYPE src_touch_matrix, + IMAGE_dst_values_TYPE dst_values, + int x_correction +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int label_id = get_global_id(0); + const int label_count = get_global_size(0); + + bool initialized = false; + float minimum = 0; + + int y = label_id; + int x = 0; + for (x = 0; x < label_id; x++) { + float value = READ_IMAGE(src_touch_matrix, sampler, POS_src_touch_matrix_INSTANCE(x, y, 0, 0)).x; + if (value > 0) { + value = READ_IMAGE(src_values, sampler, POS_src_values_INSTANCE(x + x_correction, 0, 0, 0)).x; + if (minimum > value || !initialized) { + minimum = value; + initialized = true; + } + } + } + + x = label_id; + for (y = label_id; y < label_count; y++) { + float value = READ_IMAGE(src_touch_matrix, sampler, POS_src_touch_matrix_INSTANCE(x, y, 0, 0)).x; + if (value > 0 || y == label_id) { + value = READ_IMAGE(src_values, sampler, POS_src_values_INSTANCE(y + x_correction, 0, 0, 0)).x; + if (minimum > value || !initialized) { + minimum = value; + initialized = true; + } + } + } + + WRITE_IMAGE(dst_values, POS_dst_values_INSTANCE(label_id, 0, 0, 0), CONVERT_dst_values_PIXEL_TYPE(minimum)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_projection_3d_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_projection_3d_2d_x.cl new file mode 100644 index 0000000..320bfa1 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_projection_3d_2d_x.cl @@ -0,0 +1,19 @@ + +__kernel void minimum_projection_3d_2d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + float min = 0; + for(int z = 0; z < GET_IMAGE_DEPTH(src); z++) + { + float value = READ_src_IMAGE(src,sampler,(int4)(x,y,z,0)).x; + if (value < min || z == 0) { + min = value; + } + } + WRITE_dst_IMAGE(dst,(int2)(x,y), CONVERT_dst_PIXEL_TYPE(min)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_separable_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_separable_2d_x.cl new file mode 100644 index 0000000..337c245 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_separable_2d_x.cl @@ -0,0 +1,26 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void minimum_separable_2d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int dim, + const int N, + const float s +) +{ + const int i = get_global_id(0), j = get_global_id(1); + const int2 coord = (int2)(i,j); + const int2 dir = (int2)(dim==0,dim==1); + + // center + const int c = (N-1)/2; + + float res = (float)(READ_src_IMAGE(src,sampler,coord).x); + for (int v = -c; v <= c; v++) { + if (v != 0) { + res = min(res, (float)(READ_src_IMAGE(src,sampler,coord+v*dir).x)); + } + } + WRITE_dst_IMAGE(dst,coord, CONVERT_dst_PIXEL_TYPE(res)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_separable_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_separable_3d_x.cl new file mode 100644 index 0000000..16a2f40 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_separable_3d_x.cl @@ -0,0 +1,24 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void minimum_separable_3d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int dim, + const int N, + const float s +) +{ + const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); + const int4 coord = (int4)(i,j,k,0); + const int4 dir = (int4)(dim==0,dim==1,dim==2,0); + + // center + const int c = (N-1)/2; + + float res = READ_src_IMAGE(src,sampler,coord).x; + for (int v = -c; v <= c; v++) { + res = min(res, (float)READ_src_IMAGE(src,sampler,coord+v*dir).x); + } + WRITE_dst_IMAGE(dst,coord, CONVERT_dst_PIXEL_TYPE(res)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_slice_by_slice_sphere_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_slice_by_slice_sphere_3d_x.cl new file mode 100644 index 0000000..ce52415 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_slice_by_slice_sphere_3d_x.cl @@ -0,0 +1,41 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void minimum_slice_by_slice_sphere_3d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int Nx, + const int Ny +) +{ + const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); + const int4 coord = (int4){i,j,k,0}; + + const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, 0, 0 }; + + IMAGE_dst_PIXEL_TYPE minimumValue = CONVERT_dst_PIXEL_TYPE(READ_src_IMAGE(src,sampler,coord).x); + float aSquared = e.x * e.x; + float bSquared = e.y * e.y; + if (aSquared == 0) { + aSquared = FLT_MIN; + } + if (bSquared == 0) { + bSquared = FLT_MIN; + } + + for (int x = -e.x; x <= e.x; x++) { + float xSquared = x * x; + for (int y = -e.y; y <= e.y; y++) { + float ySquared = y * y; + if (xSquared / aSquared + ySquared / bSquared <= 1.0) { + IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(READ_src_IMAGE(src,sampler,coord+((int4){x,y,0,0})).x); + if (value < minimumValue) { + minimumValue = value; + } + } + } + } + + IMAGE_dst_PIXEL_TYPE res = minimumValue; + WRITE_dst_IMAGE(dst, coord, res); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_sphere_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_sphere_2d_x.cl new file mode 100644 index 0000000..779743f --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_sphere_2d_x.cl @@ -0,0 +1,49 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void minimum_sphere_2d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int Nx, + const int Ny +) +{ + const int i = get_global_id(0), j = get_global_id(1); + const int2 coord = (int2){i,j}; + + const int4 e = (int4) { (Nx-1)/2, (Ny-1)/2, 0, 0 }; + + IMAGE_dst_PIXEL_TYPE minimumValue = CONVERT_dst_PIXEL_TYPE(READ_src_IMAGE(src,sampler,coord).x); + float aSquared = e.x * e.x; + float bSquared = e.y * e.y; + if (aSquared == 0) { + aSquared = FLT_MIN; + } + if (bSquared == 0) { + bSquared = FLT_MIN; + } + if (aSquared == 0) { + aSquared = FLT_MIN; + } + if (bSquared == 0) { + bSquared = FLT_MIN; + } + + int count = 0; + + for (int x = -e.x; x <= e.x; x++) { + float xSquared = x * x; + for (int y = -e.y; y <= e.y; y++) { + float ySquared = y * y; + if (xSquared / aSquared + ySquared / bSquared <= 1.0) { + IMAGE_dst_PIXEL_TYPE value = (IMAGE_dst_PIXEL_TYPE)READ_src_IMAGE(src,sampler,coord+((int2){x,y})).x; + if (value < minimumValue) { + minimumValue = value; + } + } + } + } + + IMAGE_dst_PIXEL_TYPE res = minimumValue; + WRITE_dst_IMAGE(dst, coord, res); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_sphere_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_sphere_3d_x.cl new file mode 100644 index 0000000..28407c1 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_sphere_3d_x.cl @@ -0,0 +1,54 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void minimum_sphere_3d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const int Nx, + const int Ny, + const int Nz +) +{ + const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); + const int4 coord = (int4){i,j,k,0}; + + const int4 e = (int4) {(Nx-1)/2, (Ny-1)/2, (Nz-1)/2, 0 }; + float minimumValue = (float)READ_src_IMAGE(src,sampler,coord).x; + float aSquared = e.x * e.x; + float bSquared = e.y * e.y; + float cSquared = e.z * e.z; + if (aSquared == 0) { + aSquared = FLT_MIN; + } + if (bSquared == 0) { + bSquared = FLT_MIN; + } + if (cSquared == 0) { + cSquared = FLT_MIN; + } + + for (int x = -e.x; x <= e.x; x++) { + float xSquared = x * x; + for (int y = -e.y; y <= e.y; y++) { + float ySquared = y * y; + for (int z = -e.z; z <= e.z; z++) { + float zSquared = z * z; + if (xSquared / aSquared + ySquared / bSquared + zSquared / cSquared <= 1.0) { + + int x1 = coord.x + x; + int x2 = coord.y + y; + int x3 = coord.z + z; + const int4 pos = (int4){x1,x2,x3,0}; + float value_res = (float)READ_src_IMAGE(src,sampler,pos).x; + if (value_res < minimumValue) { + minimumValue = value_res; + } + } + } + } + } + + + IMAGE_dst_PIXEL_TYPE res = CONVERT_dst_PIXEL_TYPE(minimumValue); + WRITE_dst_IMAGE(dst, coord, res); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_x_projection_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_x_projection_x.cl new file mode 100644 index 0000000..789e6dc --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_x_projection_x.cl @@ -0,0 +1,19 @@ + +__kernel void minimum_x_projection ( + IMAGE_dst_min_TYPE dst_min, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int z = get_global_id(0); + const int y = get_global_id(1); + float min = 0; + for(int x = 0; x < GET_IMAGE_WIDTH(src); x++) + { + float value = READ_src_IMAGE(src,sampler,POS_src_INSTANCE(x,y,z,0)).x; + if (value < min || x == 0) { + min = value; + } + } + WRITE_dst_min_IMAGE(dst_min,POS_dst_min_INSTANCE(z,y,0,0), CONVERT_dst_min_PIXEL_TYPE(min)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_y_projection_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_y_projection_x.cl new file mode 100644 index 0000000..0dd8b22 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_y_projection_x.cl @@ -0,0 +1,19 @@ + +__kernel void minimum_y_projection ( + IMAGE_dst_min_TYPE dst_min, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int z = get_global_id(1); + float min = 0; + for(int y = 0; y < GET_IMAGE_HEIGHT(src); y++) + { + float value = READ_src_IMAGE(src,sampler,POS_src_INSTANCE(x,y,z,0)).x; + if (value < min || y == 0) { + min = value; + } + } + WRITE_dst_min_IMAGE(dst_min,POS_dst_min_INSTANCE(x,z,0,0), CONVERT_dst_min_PIXEL_TYPE(min)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_z_projection_bounded_3d_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_z_projection_bounded_3d_2d_x.cl new file mode 100644 index 0000000..d71437d --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_z_projection_bounded_3d_2d_x.cl @@ -0,0 +1,32 @@ + +__kernel void minimum_z_projection_bounded_3d_2d( + IMAGE_dst_min_TYPE dst_min, + IMAGE_src_TYPE src, + int min_z, + int max_z +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + float min = 0; + + int start = 0; + if (min_z > start) { + start = min_z; + } + + int end = GET_IMAGE_DEPTH(src) - 1; + if (max_z < end) { + end = max_z; + } + + for(int z = start; z <= end; z++) + { + float value = READ_src_IMAGE(src,sampler,(int4)(x,y,z,0)).x; + if (value < min || z == start) { + min = value; + } + } + WRITE_dst_min_IMAGE(dst_min,(int2)(x,y), CONVERT_dst_min_PIXEL_TYPEmin)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_z_projection_thresholded_bounded_3d_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_z_projection_thresholded_bounded_3d_2d_x.cl new file mode 100644 index 0000000..da8dc45 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_z_projection_thresholded_bounded_3d_2d_x.cl @@ -0,0 +1,35 @@ + +__kernel void minimum_z_projection_thresholded_bounded_3d_2d( + IMAGE_dst_min_TYPE dst_min, + IMAGE_src_TYPE src, + float threshold_intensity, + int min_z, + int max_z +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + float min = 0; + + int start = 0; + if (min_z > start) { + start = min_z; + } + + int end = GET_IMAGE_DEPTH(src) - 1; + if (max_z < end) { + end = max_z; + } + + bool initialized = 0; + for(int z = start; z <= end; z++) + { + float value = READ_src_IMAGE(src,sampler,(int4)(x,y,z,0)).x; + if ((threshold_intensity < value) && (value < min || initialized == 0)) { + min = value; + initialized = 1; + } + } + WRITE_dst_min_IMAGE(dst_min,(int2)(x,y), CONVERT_dst_min_PIXEL_TYPE(min)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/minimum_z_projection_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_z_projection_x.cl new file mode 100644 index 0000000..5c71392 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/minimum_z_projection_x.cl @@ -0,0 +1,19 @@ + +__kernel void minimum_z_projection( + IMAGE_dst_min_TYPE dst_min, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + float min = 0; + for(int z = 0; z < GET_IMAGE_DEPTH(src); z++) + { + float value = READ_src_IMAGE(src,sampler,POS_src_INSTANCE(x,y,z,0)).x; + if (value < min || z == 0) { + min = value; + } + } + WRITE_dst_min_IMAGE(dst_min,POS_dst_min_INSTANCE(x,y,0,0), CONVERT_dst_min_PIXEL_TYPE(min)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/multiply_image_and_coordinate_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/multiply_image_and_coordinate_2d_x.cl new file mode 100644 index 0000000..b10d990 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/multiply_image_and_coordinate_2d_x.cl @@ -0,0 +1,18 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void multiply_image_and_coordinate_2d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst, + int dimension +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(READ_src_IMAGE(src, sampler, pos).x * get_global_id(dimension)); + + WRITE_dst_IMAGE (dst, pos, value); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/multiply_image_and_coordinate_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/multiply_image_and_coordinate_3d_x.cl new file mode 100644 index 0000000..404f5c2 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/multiply_image_and_coordinate_3d_x.cl @@ -0,0 +1,18 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void multiply_image_and_coordinate_3d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst, + int dimension +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(READ_src_IMAGE(src, sampler, pos).x * get_global_id(dimension)); + + WRITE_dst_IMAGE(dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/multiply_image_and_scalar_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/multiply_image_and_scalar_2d_x.cl new file mode 100644 index 0000000..95b6a77 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/multiply_image_and_scalar_2d_x.cl @@ -0,0 +1,17 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void multiply_image_and_scalar_2d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst, + float scalar +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(READ_src_IMAGE(src, sampler, pos).x * scalar); + + WRITE_dst_IMAGE (dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/multiply_image_and_scalar_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/multiply_image_and_scalar_3d_x.cl new file mode 100644 index 0000000..cc5a387 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/multiply_image_and_scalar_3d_x.cl @@ -0,0 +1,18 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void multiply_image_and_scalar_3d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst, + float scalar +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(READ_src_IMAGE(src, sampler, pos).x * scalar); + + WRITE_dst_IMAGE(dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/multiply_images_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/multiply_images_2d_x.cl new file mode 100644 index 0000000..26f3ca2 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/multiply_images_2d_x.cl @@ -0,0 +1,18 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void multiply_images_2d( + IMAGE_src_TYPE src, + IMAGE_src1_TYPE src1, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const float value = (float)READ_src_IMAGE(src, sampler, pos).x * READ_src1_IMAGE(src1, sampler, pos).x; + + WRITE_dst_IMAGE(dst, pos, CONVERT_dst_PIXEL_TYPE(value)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/multiply_images_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/multiply_images_3d_x.cl new file mode 100644 index 0000000..ac5bfba --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/multiply_images_3d_x.cl @@ -0,0 +1,18 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void multiply_images_3d( + IMAGE_src_TYPE src, + IMAGE_src1_TYPE src1, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const float value = (float)READ_src_IMAGE(src, sampler, pos).x * READ_src1_IMAGE(src1, sampler, pos).x; + + WRITE_dst_IMAGE(dst, pos, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/multiply_matrix_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/multiply_matrix_x.cl new file mode 100644 index 0000000..73667e2 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/multiply_matrix_x.cl @@ -0,0 +1,21 @@ + +__kernel void multiply_matrix( + IMAGE_dst_matrix_TYPE dst_matrix, + IMAGE_src1_TYPE src1, + IMAGE_src2_TYPE src2 +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int dx = get_global_id(0); + const int dy = get_global_id(1); + + int n_x = GET_IMAGE_WIDTH(src1); + + float sum = 0; + for (int i = 0; i < n_x; i ++) { + sum = sum + READ_src1_IMAGE(src1, sampler, POS_src1_INSTANCE(i, dy,0,0)).x * READ_src2_IMAGE(src2, sampler, POS_src2_INSTANCE(dx, i,0,0)).x; + } + float out = sum; + WRITE_dst_matrix_IMAGE(dst_matrix, POS_dst_matrix_INSTANCE(dx, dy, 0, 0), CONVERT_dst_matrix_PIXEL_TYPE(out)); + +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/multiply_stack_with_plane_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/multiply_stack_with_plane_3d_x.cl new file mode 100644 index 0000000..ecd70b3 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/multiply_stack_with_plane_3d_x.cl @@ -0,0 +1,21 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void multiply_stack_with_plane_3d( + IMAGE_src_TYPE src, + IMAGE_src1_TYPE src1, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos3d = (int4){x,y,z,0}; + const int2 pos2d = (int2){x,y}; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(READ_src_IMAGE(src, sampler, pos3d).x * READ_src1_IMAGE(src1, sampler, pos2d).x); + + WRITE_dst_IMAGE (dst, pos3d, value); +} + + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/multiply_stack_with_scalars_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/multiply_stack_with_scalars_x.cl new file mode 100644 index 0000000..3f5beb4 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/multiply_stack_with_scalars_x.cl @@ -0,0 +1,22 @@ +__kernel void multiply_stack_with_scalars( + IMAGE_src_TYPE src, + IMAGE_src_scalar_list_TYPE src_scalar_list, + IMAGE_dst_TYPE dst +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos3d = (int4){x,y,z,0}; + const POS_src_scalar_list_TYPE pos1d = POS_src_scalar_list_INSTANCE(z, 0, 0, 0); + + const float value1 = READ_src_IMAGE(src, sampler, pos3d).x; + const float value2 = READ_src_scalar_list_IMAGE(src_scalar_list, sampler, pos1d).x; + + const float value = value1 * value2; + + WRITE_IMAGE (dst, pos3d, CONVERT_dst_PIXEL_TYPE(value)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/n_shortest_distances_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/n_shortest_distances_x.cl new file mode 100644 index 0000000..871c0f5 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/n_shortest_distances_x.cl @@ -0,0 +1,51 @@ + +__kernel void find_n_closest_points( + IMAGE_src_distancematrix_TYPE src_distancematrix, + IMAGE_dst_distancelist_TYPE dst_distancelist, + IMAGE_dst_indexlist_TYPE dst_indexlist +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int pointIndex = get_global_id(0); + + // so many point candidates are available: + const int height = GET_IMAGE_HEIGHT(src_distancematrix); + + // so many minima need to be found: + const int n = GET_IMAGE_HEIGHT(dst_indexlist); + + float distances[1000]; + float indices[1000]; + + int initialized_values = 0; + + for (int y = 0; y < height; y++) { + float distance = READ_src_distancematrix_IMAGE(src_distancematrix, sampler, POS_src_distancematrix_INSTANCE(pointIndex, y, 0, 0)).x; + + if (initialized_values < n) { + initialized_values++; + distances[initialized_values - 1] = distance; + indices[initialized_values - 1] = y; + } + // sort by insert + for (int i = initialized_values - 1; i >= 0; i--) { + if (distance > distances[i]) { + break; + } + if (distance < distances[i] && (i == 0 || distance >= distances[i - 1])) { + for (int j = initialized_values - 1; j > i; j--) { + indices[j] = indices[j - 1]; + distances[j] = distances[j - 1]; + } + distances[i] = distance; + indices[i] = y; + break; + } + } + } + + for (int i = 0; i < initialized_values; i++) { + WRITE_dst_distancelist_IMAGE(dst_distancelist, POS_dst_distancelist_INSTANCE(pointIndex, i, 0, 0), CONVERT_dst_distancelist_PIXEL_TYPE(distances[i])); + WRITE_dst_indexlist_IMAGE(dst_indexlist, POS_dst_indexlist_INSTANCE(pointIndex, i, 0, 0), CONVERT_dst_indexlist_PIXEL_TYPE(indices[i])); + } +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/n_shortest_points_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/n_shortest_points_x.cl new file mode 100644 index 0000000..34105fc --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/n_shortest_points_x.cl @@ -0,0 +1,49 @@ + +__kernel void find_n_closest_points( + IMAGE_src_distancematrix_TYPE src_distancematrix, + IMAGE_dst_indexlist_TYPE dst_indexlist +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int pointIndex = get_global_id(0); + + // so many point candidates are available: + const int height = GET_IMAGE_HEIGHT(src_distancematrix); + + // so many minima need to be found: + const int n = GET_IMAGE_HEIGHT(dst_indexlist); + + float distances[1000]; + float indices[1000]; + + int initialized_values = 0; + + for (int y = 0; y < height; y++) { + float distance = READ_src_distancematrix_IMAGE(src_distancematrix, sampler, POS_src_distancematrix_INSTANCE(pointIndex, y, 0, 0)).x; + + if (initialized_values < n) { + initialized_values++; + distances[initialized_values - 1] = distance; + indices[initialized_values - 1] = y; + } + // sort by insert + for (int i = initialized_values - 1; i >= 0; i--) { + if (distance > distances[i]) { + break; + } + if (distance < distances[i] && (i == 0 || distance >= distances[i - 1])) { + for (int j = initialized_values - 1; j > i; j--) { + indices[j] = indices[j - 1]; + distances[j] = distances[j - 1]; + } + distances[i] = distance; + indices[i] = y; + break; + } + } + } + + for (int i = 0; i < initialized_values; i++) { + WRITE_dst_indexlist_IMAGE(dst_indexlist, POS_dst_indexlist_INSTANCE(pointIndex, i, 0, 0), CONVERT_dst_indexlist_PIXEL_TYPE(indices[i])); + } +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/neighbors.cl b/src/main/java/net/haesleinhuepf/clij/kernels/neighbors.cl deleted file mode 100644 index f310bda..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/neighbors.cl +++ /dev/null @@ -1,95 +0,0 @@ -__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - -__kernel void gradientX_2d -( - DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src -) -{ - const int i = get_global_id(0), j = get_global_id(1); - const int2 coord = (int2){i,j}; - const int2 coordA = (int2){i-1,j}; - const int2 coordB = (int2){i+1,j}; - - DTYPE_IN valueA = (DTYPE_OUT)READ_IMAGE_2D(src, sampler, coordA).x; - DTYPE_IN valueB = (DTYPE_OUT)READ_IMAGE_2D(src, sampler, coordB).x; - DTYPE_OUT res = CONVERT_DTYPE_OUT(valueB - valueA); - - WRITE_IMAGE_2D(dst, coord, res); -} - - -__kernel void gradientY_2d -( - DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src -) -{ - const int i = get_global_id(0), j = get_global_id(1); - const int2 coord = (int2){i,j}; - const int2 coordA = (int2){i,j-1}; - const int2 coordB = (int2){i,j+1}; - - DTYPE_IN valueA = (DTYPE_OUT)READ_IMAGE_2D(src, sampler, coordA).x; - DTYPE_IN valueB = (DTYPE_OUT)READ_IMAGE_2D(src, sampler, coordB).x; - DTYPE_OUT res = CONVERT_DTYPE_OUT(valueB - valueA); - - WRITE_IMAGE_2D(dst, coord, res); -} - -__kernel void gradientX_3d -( - DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src -) -{ - const int i = get_global_id(0); - const int j = get_global_id(1); - const int k = get_global_id(2); - const int4 coord = (int4){i, j, k, 0}; - const int4 coordA = (int4){i-1, j, k, 0}; - const int4 coordB = (int4){i+1, j, k, 0}; - - DTYPE_IN valueA = (DTYPE_OUT)READ_IMAGE_3D(src, sampler, coordA).x; - DTYPE_IN valueB = (DTYPE_OUT)READ_IMAGE_3D(src, sampler, coordB).x; - DTYPE_OUT res = CONVERT_DTYPE_OUT(valueB - valueA); - - WRITE_IMAGE_3D(dst, coord, res); -} - -__kernel void gradientY_3d -( - DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src -) -{ - const int i = get_global_id(0); - const int j = get_global_id(1); - const int k = get_global_id(2); - const int4 coord = (int4){i, j, k, 0}; - const int4 coordA = (int4){i, j-1, k, 0}; - const int4 coordB = (int4){i, j+1, k, 0}; - - DTYPE_IN valueA = (DTYPE_OUT)READ_IMAGE_3D(src, sampler, coordA).x; - DTYPE_IN valueB = (DTYPE_OUT)READ_IMAGE_3D(src, sampler, coordB).x; - DTYPE_OUT res = CONVERT_DTYPE_OUT(valueB - valueA); - - WRITE_IMAGE_3D(dst, coord, res); -} - -__kernel void gradientZ_3d -( - DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src -) -{ - const int i = get_global_id(0); - const int j = get_global_id(1); - const int k = get_global_id(2); - const int4 coord = (int4){i, j, k, 0}; - const int4 coordA = (int4){i, j, k-1, 0}; - const int4 coordB = (int4){i, j, k+1, 0}; - - DTYPE_IN valueA = (DTYPE_OUT)READ_IMAGE_3D(src, sampler, coordA).x; - DTYPE_IN valueB = (DTYPE_OUT)READ_IMAGE_3D(src, sampler, coordB).x; - DTYPE_OUT res = CONVERT_DTYPE_OUT(valueB - valueA); - - WRITE_IMAGE_3D(dst, coord, res); -} - diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_maximum_box_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_maximum_box_2d_x.cl new file mode 100644 index 0000000..099bae4 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_maximum_box_2d_x.cl @@ -0,0 +1,31 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void nonzero_maximum_box_2d +( + IMAGE_dst_TYPE dst, IMAGE_flag_dst_TYPE flag_dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float foundMaximum = READ_src_IMAGE(src, sampler, pos).x; + if (foundMaximum != 0) { + float originalValue = foundMaximum; + for (int ax = -1; ax <= 1; ax++) { + for (int ay = -1; ay <= 1; ay++) { + float value = READ_src_IMAGE(src, sampler, (pos + (int2){ax, ay})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + } + } + + if (foundMaximum != originalValue) { + WRITE_flag_dst_IMAGE(flag_dst,(int4)(0,0,0,0),1); + } + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(foundMaximum)); + } +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_maximum_box_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_maximum_box_3d_x.cl new file mode 100644 index 0000000..ae9e655 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_maximum_box_3d_x.cl @@ -0,0 +1,48 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void nonzero_maximum_box_3d +( + IMAGE_dst_TYPE dst, IMAGE_flag_dst_TYPE flag_dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float foundMaximum = READ_src_IMAGE(src, sampler, pos).x; + if (foundMaximum != 0) { + float originalValue = foundMaximum; + float value = READ_src_IMAGE(src, sampler, (pos + (int4){1, 0, 0, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){-1, 0, 0, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 1, 0, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, -1, 0, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 0, 1, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 0, -1, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + + if (foundMaximum != originalValue) { + WRITE_flag_dst_IMAGE(flag_dst,(int4)(0,0,0,0),1); + } + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(foundMaximum)); + } +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_maximum_diamond_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_maximum_diamond_2d_x.cl new file mode 100644 index 0000000..cc5b620 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_maximum_diamond_2d_x.cl @@ -0,0 +1,38 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void nonzero_maximum_diamond_2d +( + IMAGE_dst_TYPE dst, IMAGE_flag_dst_TYPE flag_dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float foundMaximum = READ_src_IMAGE(src, sampler, pos).x; + if (foundMaximum != 0) { + float originalValue = foundMaximum; + float value = READ_src_IMAGE(src, sampler, (pos + (int2){1, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){-1, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, 1})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, -1})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + + if (foundMaximum != originalValue) { + WRITE_flag_dst_IMAGE(flag_dst,(int4)(0,0,0,0),1); + } + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(foundMaximum)); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_maximum_diamond_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_maximum_diamond_3d_x.cl new file mode 100644 index 0000000..24e2e1b --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_maximum_diamond_3d_x.cl @@ -0,0 +1,47 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void nonzero_maximum_diamond_3d +( + IMAGE_dst_TYPE dst, IMAGE_flag_dst_TYPE flag_dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float foundMaximum = READ_src_IMAGE(src, sampler, pos).x; + if (foundMaximum != 0) { + float originalValue = foundMaximum; + float value = READ_src_IMAGE(src, sampler, (pos + (int4){1, 0, 0, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){-1, 0, 0, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 1, 0, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, -1, 0, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 0, 1, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 0, -1, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + + if (foundMaximum != originalValue) { + WRITE_flag_dst_IMAGE(flag_dst,(int4)(0,0,0,0),1); + } + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(foundMaximum)); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_minimum_box_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_minimum_box_2d_x.cl new file mode 100644 index 0000000..3ea05d5 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_minimum_box_2d_x.cl @@ -0,0 +1,30 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void nonzero_minimum_box_2d +( + IMAGE_dst_TYPE dst, IMAGE_flag_dst_TYPE flag_dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float foundMinimum = READ_src_IMAGE(src, sampler, pos).x; + if (foundMinimum != 0) { + float originalValue = foundMinimum; + for (int ax = -1; ax <= 1; ax++) { + for (int ay = -1; ay <= 1; ay++) { + float value = READ_src_IMAGE(src, sampler, (pos + (int2){ax, ay})).x; + if ( value < foundMinimum && value > 0) { + foundMinimum = value; + } + } + } + + if (foundMinimum != originalValue) { + WRITE_flag_dst_IMAGE(flag_dst,(int4)(0,0,0,0),1); + } + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(foundMinimum)); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_minimum_box_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_minimum_box_3d_x.cl new file mode 100644 index 0000000..ac3154f --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_minimum_box_3d_x.cl @@ -0,0 +1,33 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void nonzero_minimum_box_3d +( + IMAGE_dst_TYPE dst, IMAGE_flag_dst_TYPE flag_dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float foundMinimum = READ_src_IMAGE(src, sampler, pos).x; + if (foundMinimum != 0) { + float originalValue = foundMinimum; + for (int ax = -1; ax <= 1; ax++) { + for (int ay = -1; ay <= 1; ay++) { + for (int az = -1; az <= 1; az++) { + float value = READ_src_IMAGE(src, sampler, (pos + (int4){ax, ay, az, 0})).x; + if ( value < foundMinimum && value > 0) { + foundMinimum = value; + } + } + } + } + + if (foundMinimum != originalValue) { + WRITE_flag_dst_IMAGE(flag_dst,(int4)(0,0,0,0),1); + } + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(foundMinimum)); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_minimum_diamond_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_minimum_diamond_2d_x.cl new file mode 100644 index 0000000..9fb2bd0 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_minimum_diamond_2d_x.cl @@ -0,0 +1,38 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void nonzero_minimum_diamond_2d +( + IMAGE_dst_TYPE dst, IMAGE_flag_dst_TYPE flag_dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float foundMinimum = READ_src_IMAGE(src, sampler, pos).x; + if (foundMinimum != 0) { + float originalValue = foundMinimum; + float value = READ_src_IMAGE(src, sampler, (pos + (int2){1, 0})).x; + if ( value < foundMinimum && value > 0) { + foundMinimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){-1, 0})).x; + if ( value < foundMinimum && value > 0) { + foundMinimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, 1})).x; + if ( value < foundMinimum && value > 0) { + foundMinimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, -1})).x; + if ( value < foundMinimum && value > 0) { + foundMinimum = value; + } + + if (foundMinimum != originalValue) { + WRITE_flag_dst_IMAGE(flag_dst,(int4)(0,0,0,0),1); + } + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(foundMinimum)); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_minimum_diamond_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_minimum_diamond_3d_x.cl new file mode 100644 index 0000000..5b89940 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/nonzero_minimum_diamond_3d_x.cl @@ -0,0 +1,47 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void nonzero_minimum_diamond_3d +( + IMAGE_dst_TYPE dst, IMAGE_flag_dst_TYPE flag_dst, IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float foundMinimum = READ_src_IMAGE(src, sampler, pos).x; + if (foundMinimum != 0) { + float originalValue = foundMinimum; + float value = READ_src_IMAGE(src, sampler, (pos + (int4){1, 0, 0, 0})).x; + if ( value < foundMinimum && value > 0) { + foundMinimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){-1, 0, 0, 0})).x; + if ( value < foundMinimum && value > 0) { + foundMinimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 1, 0, 0})).x; + if ( value < foundMinimum && value > 0) { + foundMinimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, -1, 0, 0})).x; + if ( value < foundMinimum && value > 0) { + foundMinimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 0, 1, 0})).x; + if ( value < foundMinimum && value > 0) { + foundMinimum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 0, -1, 0})).x; + if ( value < foundMinimum && value > 0) { + foundMinimum = value; + } + + if (foundMinimum != originalValue) { + WRITE_flag_dst_IMAGE(flag_dst,(int4)(0,0,0,0),1); + } + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(foundMinimum)); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/not_equal_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/not_equal_2d_x.cl new file mode 100644 index 0000000..25c180e --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/not_equal_2d_x.cl @@ -0,0 +1,22 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void not_equal_2d( + IMAGE_src1_TYPE src1, + IMAGE_src2_TYPE src2, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + const float input2 = (float)READ_src2_IMAGE(src2, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 != input2) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/not_equal_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/not_equal_3d_x.cl new file mode 100644 index 0000000..873b48a --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/not_equal_3d_x.cl @@ -0,0 +1,23 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void not_equal_3d( + IMAGE_src1_TYPE src1, + IMAGE_src2_TYPE src2, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + const float input2 = (float)READ_sec2_IMAGE(src2, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 != input2) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/not_equal_constant_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/not_equal_constant_2d_x.cl new file mode 100644 index 0000000..0abc7e1 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/not_equal_constant_2d_x.cl @@ -0,0 +1,21 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void not_equal_constant_2d( + IMAGE_src1_TYPE src1, + float scalar, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 != scalar) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/not_equal_constant_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/not_equal_constant_3d_x.cl new file mode 100644 index 0000000..745fb5e --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/not_equal_constant_3d_x.cl @@ -0,0 +1,22 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void not_equal_constant_3d( + IMAGE_src1_TYPE src1, + float scalar, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 != scalar) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/onlyzero_overwrite_maximum_box_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/onlyzero_overwrite_maximum_box_2d_x.cl new file mode 100644 index 0000000..739f77e --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/onlyzero_overwrite_maximum_box_2d_x.cl @@ -0,0 +1,57 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void onlyzero_overwrite_maximum_box_2d +( + IMAGE_dst_TYPE dst, + IMAGE_flag_dst_TYPE flag_dst, + IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float foundMaximum = READ_src_IMAGE(src, sampler, pos).x; + if (foundMaximum == 0) { + float originalValue = foundMaximum; + float value = READ_src_IMAGE(src, sampler, (pos + (int2){1, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){-1, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, 1})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, -1})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + + value = READ_src_IMAGE(src, sampler, (pos + (int2){1, 1})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){-1, 1})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){-1, -1})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){1, -1})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + + if (foundMaximum != originalValue) { + WRITE_flag_dst_IMAGE(flag_dst,(int4)(0,0,0,0),1); + } + } + WRITE_dst_IMAGE(dst, pos, CONVERT_dst_PIXEL_TYPE(foundMaximum)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/onlyzero_overwrite_maximum_box_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/onlyzero_overwrite_maximum_box_3d_x.cl new file mode 100644 index 0000000..15e4846 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/onlyzero_overwrite_maximum_box_3d_x.cl @@ -0,0 +1,35 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void onlyzero_overwrite_maximum_box_3d +( + IMAGE_dst_TYPE dst, + IMAGE_flag_dst_TYPE flag_dst, + IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float originalValue = READ_src_IMAGE(src, sampler, pos).x; + float foundMaximum = originalValue; + if (foundMaximum == 0) { + for (int x = -1; x <= 1; x++) { + for (int y = -1; y <= 1; y++) { + for (int z = -1; z <= 1; z++) { + float value = READ_src_IMAGE(src, sampler, (pos + (int4){x, y, z, 0})).x; + if (value > foundMaximum) { + foundMaximum = value; + } + } + } + } + } + if (foundMaximum != originalValue) { + WRITE_flag_dst_IMAGE(flag_dst,(int4)(0,0,0,0),1); + } + + WRITE_dst_IMAGE(dst, pos, CONVERT_dst_PIXEL_TYPE(foundMaximum)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/onlyzero_overwrite_maximum_diamond_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/onlyzero_overwrite_maximum_diamond_2d_x.cl new file mode 100644 index 0000000..346f641 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/onlyzero_overwrite_maximum_diamond_2d_x.cl @@ -0,0 +1,40 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void onlyzero_overwrite_maximum_diamond_2d +( + IMAGE_dst_TYPE dst, + IMAGE_flag_dst_TYPE flag_dst, + IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float foundMaximum = READ_src_IMAGE(src, sampler, pos).x; + if (foundMaximum == 0) { + float originalValue = foundMaximum; + float value = READ_src_IMAGE(src, sampler, (pos + (int2){1, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){-1, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, 1})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int2){0, -1})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + + if (foundMaximum != originalValue) { + WRITE_flag_dst_IMAGE(flag_dst,(int4)(0,0,0,0),1); + } + } + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(foundMaximum)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/onlyzero_overwrite_maximum_diamond_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/onlyzero_overwrite_maximum_diamond_3d_x.cl new file mode 100644 index 0000000..dc1c530 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/onlyzero_overwrite_maximum_diamond_3d_x.cl @@ -0,0 +1,49 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void onlyzero_overwrite_maximum_diamond_3d +( + IMAGE_dst_TYPE dst, + IMAGE_flag_dst_TYPE flag_dst, + IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float foundMaximum = READ_src_IMAGE(src, sampler, pos).x; + if (foundMaximum == 0) { + float originalValue = foundMaximum; + float value = READ_src_IMAGE(src, sampler, (pos + (int4){1, 0, 0, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){-1, 0, 0, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 1, 0, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, -1, 0, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 0, 1, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + value = READ_src_IMAGE(src, sampler, (pos + (int4){0, 0, -1, 0})).x; + if ( value > foundMaximum && value > 0) { + foundMaximum = value; + } + + if (foundMaximum != originalValue) { + WRITE_flag_dst_IMAGE(flag_dst,(int4)(0,0,0,0),1); + } + } + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(foundMaximum)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/paste_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/paste_2d_x.cl new file mode 100644 index 0000000..4aa2250 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/paste_2d_x.cl @@ -0,0 +1,21 @@ + +__kernel void paste_2d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + int destination_x, + int destination_y +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int dx = get_global_id(0) + destination_x; + const int dy = get_global_id(1) + destination_y; + + const int sx = get_global_id(0); + const int sy = get_global_id(1); + + const POS_dst_TYPE dpos = POS_dst_INSTANCE(dx, dy, 0, 0); + const POS_src_TYPE spos = POS_src_INSTANCE(sx, sy, 0, 0); + + const float out = READ_src_IMAGE(src, sampler, spos).x; + WRITE_dst_IMAGE(dst,dpos, CONVERT_dst_PIXEL_TYPE(out)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/paste_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/paste_3d_x.cl new file mode 100644 index 0000000..ceebcef --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/paste_3d_x.cl @@ -0,0 +1,26 @@ +__kernel void paste_3d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + int destination_x, + int destination_y, + int destination_z +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int dx = get_global_id(0) + destination_x; + const int dy = get_global_id(1) + destination_y; + const int dz = get_global_id(2) + destination_z; + + + const int sx = get_global_id(0); + const int sy = get_global_id(1); + const int sz = get_global_id(2); + + + const POS_dst_TYPE dpos = POS_dst_INSTANCE(dx, dy, dz, 0); + const POS_src_TYPE spos = POS_src_INSTANCE(sx, sy, sz, 0); + + const float out = READ_src_IMAGE(src, sampler, spos).x; + WRITE_dst_IMAGE(dst, dpos, CONVERT_dst_PIXEL_TYPE(out)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/piv.cl b/src/main/java/net/haesleinhuepf/clij/kernels/piv.cl new file mode 100644 index 0000000..4575c31 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/piv.cl @@ -0,0 +1,102 @@ + +__kernel void cross_correlation_3d( DTYPE_IMAGE_IN_3D src1, + DTYPE_IMAGE_IN_3D mean_src1, + DTYPE_IMAGE_IN_3D src2, + DTYPE_IMAGE_IN_3D mean_src2, + DTYPE_IMAGE_OUT_3D dst, + int radiusx, + int radiusy, + int radiusz, + int ix, + int iy, + int iz) +{ + + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + int4 pos = {get_global_id(0), get_global_id(1), get_global_id(2), 0}; + int4 deltaPos = {get_global_id(0), get_global_id(1), get_global_id(2), 0}; + + int4 deltaPosI = {get_global_id(0), get_global_id(1), get_global_id(2), 0}; + + + float sum1 = 0; + float sum2 = 0; + float sum3 = 0; + for(int kx = -radiusx; kx < radiusx + 1; kx++) + { + deltaPos.x = get_global_id(0) + kx; + deltaPosI.x = get_global_id(0) + kx + ix; + for(int ky = -radiusy; ky < radiusy + 1; ky++) + { + deltaPos.y = get_global_id(1) + ky; + deltaPosI.y = get_global_id(1) + ky + iy; + for(int kz = -radiusz; kz < radiusz + 1; kz++) + { + deltaPos.z = get_global_id(2) + kz; + deltaPosI.z = get_global_id(2) + kz + iz; + + float Ia = READ_IMAGE_3D(src1, sampler, deltaPos).x; + float meanIa = READ_IMAGE_3D(mean_src1, sampler, deltaPos).x; + + float Ib = READ_IMAGE_3D(src2, sampler, deltaPosI).x; + float meanIb = READ_IMAGE_3D(mean_src2, sampler, deltaPosI).x; + + sum1 = sum1 + (Ia - meanIa) * (Ib - meanIb); + sum2 = sum2 + pow((float)(Ia - meanIa), (float)2.0); + sum3 = sum3 + pow((float)(Ib - meanIb), (float)2.0); + } + } + } + + float result = sum1 / pow((float)(sum2 * sum3), (float)0.5); + + WRITE_IMAGE_3D(dst, pos, (DTYPE_OUT) result); +} + +__kernel void index_projection_3d( DTYPE_IMAGE_IN_3D index_src1, + DTYPE_IMAGE_IN_3D index_map_src1, + DTYPE_IMAGE_OUT_3D dst, + int indexDimension, + int fixed1, + int fixedDimension1, + int fixed2, + int fixedDimension2 + ) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + int4 pos = {get_global_id(0), get_global_id(1), get_global_id(2), 0}; + float index = READ_IMAGE_3D(index_src1, sampler, pos).x; + + int4 indexPos = {0, 0, 0, 0}; + if (indexDimension == 0) { + indexPos.x = index; + } else if (indexDimension == 1) { + indexPos.y = index; + } else if (indexDimension == 2) { + indexPos.z = index; + } + + if (fixedDimension1 == 0) { + indexPos.x = fixed1; + } else if (fixedDimension1 == 1) { + indexPos.y = fixed1; + } else if (fixedDimension1 == 2) { + indexPos.z = fixed1; + } + + if (fixedDimension2 == 0) { + indexPos.x = fixed2; + } else if (fixedDimension2 == 1) { + indexPos.y = fixed2; + } else if (fixedDimension2 == 2) { + indexPos.z = fixed2; + } + + float value = READ_IMAGE_3D(index_map_src1, sampler, indexPos).x; + + WRITE_IMAGE_3D(dst, pos, (DTYPE_OUT) value); +} + + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/pointindexlist_to_mesh_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/pointindexlist_to_mesh_3d_x.cl new file mode 100644 index 0000000..bc922a1 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/pointindexlist_to_mesh_3d_x.cl @@ -0,0 +1,44 @@ +__kernel void pointindexlist_to_mesh_3d( +IMAGE_src_pointlist_TYPE src_pointlist, +IMAGE_src_indexlist_TYPE src_indexlist, +IMAGE_dst_mesh_TYPE dst_mesh) { + + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int pointIndex = get_global_id(0); + if (pointIndex == 0) { + return; + } + const float pointAx = READ_src_pointlist_IMAGE(src_pointlist, sampler, POS_src_pointlist_INSTANCE(pointIndex - 1, 0, 0, 0)).x; + const float pointAy = READ_src_pointlist_IMAGE(src_pointlist, sampler, POS_src_pointlist_INSTANCE(pointIndex - 1, 1, 0, 0)).x; + const float pointAz = READ_src_pointlist_IMAGE(src_pointlist, sampler, POS_src_pointlist_INSTANCE(pointIndex - 1, 2, 0, 0)).x; + + //int4 pointA = (int4){pointAx, pointAy, pointAz, 0}; + + // so many point candidates are available: + const int num_pointBs = GET_IMAGE_HEIGHT(src_indexlist); + for (int pointB = 0; pointB < num_pointBs; pointB++) { + const float pointBIndex = READ_src_indexlist_IMAGE(src_indexlist, sampler, POS_src_indexlist_INSTANCE(pointIndex, pointB, 0, 0)).x - 1; + if (pointBIndex < 0) { + continue; + } + + const float pointBx = READ_src_pointlist_IMAGE(src_pointlist, sampler, POS_src_pointlist_INSTANCE(pointBIndex, 0, 0, 0)).x; + const float pointBy = READ_src_pointlist_IMAGE(src_pointlist, sampler, POS_src_pointlist_INSTANCE(pointBIndex, 2, 0, 0)).x; + const float pointBz = READ_src_pointlist_IMAGE(src_pointlist, sampler, POS_src_pointlist_INSTANCE(pointBIndex, 3, 0, 0)).x; + + // draw line from A to B + float distanceX = pow(pointAx - pointBx, (float)2.0); + float distanceY = pow(pointAy - pointBy, (float)2.0); + float distanceZ = pow(pointAz - pointBz, (float)2.0); + + float distance = sqrt(distanceX + distanceY + distanceZ); + for (float d = 0; d < distance; d = d + 0.5) { + POS_dst_mesh_TYPE tPos = POS_dst_mesh_INSTANCE(pointAx + (pointBx - pointAx) * d / distance, + pointAy + (pointBy - pointAy) * d / distance, + pointAz + (pointBz - pointAz) * d / distance, + 0); + WRITE_dst_mesh_IMAGE(dst_mesh, tPos, 1); + } + } +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/power_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/power_2d_x.cl new file mode 100644 index 0000000..0c4800d --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/power_2d_x.cl @@ -0,0 +1,19 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void power_2d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst, + float exponent +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const IMAGE_src_PIXEL_TYPE input = READ_src_IMAGE(src, sampler, pos).x; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(pow(input, exponent)); + + WRITE_dst_IMAGE (dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/power_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/power_3d_x.cl new file mode 100644 index 0000000..a7d567e --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/power_3d_x.cl @@ -0,0 +1,20 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void power_3d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst, + float exponent +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const IMAGE_src_PIXEL_TYPE input = READ_src_IMAGE(src, sampler, pos).x; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(pow(input, exponent)); + + WRITE_dst_IMAGE (dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/power_images_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/power_images_2d_x.cl new file mode 100644 index 0000000..4ccc4f5 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/power_images_2d_x.cl @@ -0,0 +1,20 @@ + + +__kernel void power_images_2d( + IMAGE_dst_TYPE dst, + IMAGE_src1_TYPE src1, + IMAGE_src2_TYPE src2 +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + const int2 pos = (int2){x, y}; + + float a = READ_IMAGE(src1, sampler, pos).x; + float b = READ_IMAGE(src2, sampler, pos).x; + float result = pow(a, b); + + float out = result; + WRITE_IMAGE(dst, pos, CONVERT_dst_PIXEL_TYPE(out)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/power_images_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/power_images_3d_x.cl new file mode 100644 index 0000000..a6e0c7b --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/power_images_3d_x.cl @@ -0,0 +1,21 @@ + + +__kernel void power_images_3d( + IMAGE_dst_TYPE dst, + IMAGE_src1_TYPE src1, + IMAGE_src2_TYPE src2 +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + const int4 pos = (int4){x, y, z, 0}; + + float a = READ_IMAGE(src1, sampler, pos).x; + float b = READ_IMAGE(src2, sampler, pos).x; + float result = pow(a, b); + + float out = result; + WRITE_IMAGE(dst, pos, CONVERT_dst_PIXEL_TYPE(out)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/projections.cl b/src/main/java/net/haesleinhuepf/clij/kernels/projections.cl deleted file mode 100644 index e1f0282..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/projections.cl +++ /dev/null @@ -1,98 +0,0 @@ - - -__kernel void mean_project_3d_2d( - DTYPE_IMAGE_OUT_2D dst, - DTYPE_IMAGE_IN_3D src -) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int x = get_global_id(0); - const int y = get_global_id(1); - float sum = 0; - int count = 0; - for(int z = 0; z < GET_IMAGE_IN_DEPTH(src); z++) - { - sum = sum + READ_IMAGE_3D(src,sampler,(int4)(x,y,z,0)).x; - count++; - } - WRITE_IMAGE_2D(dst,(int2)(x,y), CONVERT_DTYPE_OUT(sum / count)); -} - - -__kernel void min_project_3d_2d( - DTYPE_IMAGE_OUT_2D dst_min, - DTYPE_IMAGE_IN_3D src -) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int x = get_global_id(0); - const int y = get_global_id(1); - float min = 0; - for(int z = 0; z < GET_IMAGE_IN_DEPTH(src); z++) - { - float value = READ_IMAGE_3D(src,sampler,(int4)(x,y,z,0)).x; - if (value < min || z == 0) { - min = value; - } - } - WRITE_IMAGE_2D(dst_min,(int2)(x,y), CONVERT_DTYPE_OUT(min)); -} - - -__kernel void max_project_dim_select_3d_2d( - DTYPE_IMAGE_OUT_2D dst_max, - DTYPE_IMAGE_IN_3D src, - int projection_x, - int projection_y, - int projection_dim -) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - int4 sourcePos = (int4)(0,0,0,0); - int2 targetPos = (int2)(get_global_id(0), get_global_id(1)); - - if (projection_x == 0) { - sourcePos.x = get_global_id(0); - } else if (projection_x == 1) { - sourcePos.y = get_global_id(0); - } else { - sourcePos.z = get_global_id(0); - } - if (projection_y == 0) { - sourcePos.x = get_global_id(1); - } else if (projection_y == 1) { - sourcePos.y = get_global_id(1); - } else { - sourcePos.z = get_global_id(1); - } - - - int max_d = 0; - if (projection_dim == 0) { - max_d = GET_IMAGE_IN_WIDTH(src); - } else if (projection_dim == 1) { - max_d = GET_IMAGE_IN_HEIGHT(src); - } else { - max_d = GET_IMAGE_IN_DEPTH(src); - } - - DTYPE_IN max = 0; - for(int d = 0; d < max_d; d++) - { - if (projection_dim == 0) { - sourcePos.x = d; - } else if (projection_dim == 0) { - sourcePos.y = d; - } else { - sourcePos.z = d; - } - DTYPE_IN value = READ_IMAGE_3D(src,sampler, sourcePos).x; - if (value > max || d == 0) { - max = value; - } - } - WRITE_IMAGE_2D(dst_max,targetPos, CONVERT_DTYPE_OUT(max)); -} - - - diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/radialProjection.cl b/src/main/java/net/haesleinhuepf/clij/kernels/radialProjection.cl deleted file mode 100644 index 8194a96..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/radialProjection.cl +++ /dev/null @@ -1,26 +0,0 @@ - -__kernel void radialProjection3d( - DTYPE_IMAGE_OUT_3D dst, - DTYPE_IMAGE_IN_3D src, - float deltaAngle -) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const float imageHalfWidth = GET_IMAGE_IN_WIDTH(src) / 2; - const float imageHalfHeight = GET_IMAGE_IN_HEIGHT(src) / 2; - - float angleInRad = ((float)z) * deltaAngle / 180.0 * M_PI; - //float maxRadius = sqrt(pow(imageHalfWidth, 2.0f) + pow(imageHalfHeight, 2.0f)); - float radius = x; - - const int sx = (int)(imageHalfWidth + sin(angleInRad) * radius); - const int sy = (int)(imageHalfHeight + cos(angleInRad) * radius); - const int sz = y; - - DTYPE_IN value = READ_IMAGE_3D(src,sampler,(int4)(sx,sy,sz,0)).x; - WRITE_IMAGE_3D(dst,(int4)(x,y,z,0), CONVERT_DTYPE_OUT(value)); -} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/replace_intensities_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/replace_intensities_x.cl new file mode 100644 index 0000000..3c6f9db --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/replace_intensities_x.cl @@ -0,0 +1,22 @@ + +const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void replace_intensities +( + IMAGE_dst_TYPE dst, IMAGE_src_TYPE src, + IMAGE_map_TYPE map +) +{ + const int i = get_global_id(0); + const int j = get_global_id(1); + const int k = get_global_id(2); + + const int w = GET_IMAGE_WIDTH(src); + const int h = GET_IMAGE_HEIGHT(src); + + int index = (int)(READ_IMAGE(src,sampler,POS_src_INSTANCE(i,j,k,0)).x); + float replacement = (float)(READ_IMAGE(map,sampler,POS_map_INSTANCE(index,0,0,0)).x); + + WRITE_IMAGE(dst, POS_dst_INSTANCE(i,j,k,0), CONVERT_dst_PIXEL_TYPE(replacement)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/replace_intensity_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/replace_intensity_x.cl new file mode 100644 index 0000000..8ce3f0c --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/replace_intensity_x.cl @@ -0,0 +1,27 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void replace_intensity +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + const float in, + const float out +) +{ + const int i = get_global_id(0); + const int j = get_global_id(1); + const int k = get_global_id(2); + + const int w = GET_IMAGE_WIDTH(src); + const int h = GET_IMAGE_HEIGHT(src); + const int d = GET_IMAGE_DEPTH(src); + + float pixelindex = i * h * d + j * d + k; + float value = (float)(READ_src_IMAGE(src,sampler, POS_src_INSTANCE(i,j,k,0)).x); + if (value == in) { + WRITE_dst_IMAGE(dst, POS_dst_INSTANCE(i,j,k,0), CONVERT_dst_PIXEL_TYPE(out)); + } else { + WRITE_dst_IMAGE(dst, POS_dst_INSTANCE(i,j,k,0), CONVERT_dst_PIXEL_TYPE(value)); + } +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/replace_pixels_if_zero_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/replace_pixels_if_zero_x.cl new file mode 100644 index 0000000..f332fcd --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/replace_pixels_if_zero_x.cl @@ -0,0 +1,23 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void replace_pixels_if_zero( + IMAGE_src1_TYPE src1, + IMAGE_src1_TYPE src2, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const POS_src1_TYPE pos1 = POS_src1_INSTANCE(x,y,z,0); + const POS_src2_TYPE pos2 = POS_src2_INSTANCE(x,y,z,0); + + float value = READ_IMAGE(src1, sampler, pos1).x; + if (value == 0) { + value = READ_IMAGE(src2, sampler, pos2).x; + } + + const POS_dst_TYPE pos = POS_dst_INSTANCE(x,y,z,0); + WRITE_dst_IMAGE(dst, pos, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/reslice_bottom_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/reslice_bottom_3d_x.cl new file mode 100644 index 0000000..fb4f398 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/reslice_bottom_3d_x.cl @@ -0,0 +1,19 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void reslice_bottom_3d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int sx = get_global_id(0); + const int sy = get_global_id(2); + const int sz = get_global_id(1); + + const int dx = get_global_id(0); + const int dy = get_global_id(1); + const int dz = get_global_size(2) - get_global_id(2) - 1; + + const IMAGE_src_PIXEL_TYPE out = READ_src_IMAGE(src,sampler,(int4)(sx,sy,sz,0)).x; + WRITE_dst_IMAGE(dst,(int4)(dx,dy,dz,0), CONVERT_dst_PIXEL_TYPE(out)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/reslice_left_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/reslice_left_3d_x.cl new file mode 100644 index 0000000..a46976a --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/reslice_left_3d_x.cl @@ -0,0 +1,20 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void reslice_left_3d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int sx = get_global_id(2); + const int sy = get_global_id(0); + const int sz = get_global_id(1); + + const int dx = get_global_id(0); + const int dy = get_global_id(1); + const int dz = get_global_id(2); + + const IMAGE_src_PIXEL_TYPE out = READ_src_IMAGE(src,sampler,(int4)(sx,sy,sz,0)).x; + WRITE_dst_IMAGE(dst,(int4)(dx,dy,dz,0), CONVERT_dst_PIXEL_TYPE(out)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/reslice_radial_interpolate_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/reslice_radial_interpolate_2d_x.cl new file mode 100644 index 0000000..ca93dc8 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/reslice_radial_interpolate_2d_x.cl @@ -0,0 +1,42 @@ + #ifndef SAMPLER_FILTER +#define SAMPLER_FILTER CLK_FILTER_LINEAR +#endif + +#ifndef SAMPLER_ADDRESS +#define SAMPLER_ADDRESS CLK_ADDRESS_CLAMP +#endif + +__kernel void reslice_radial_2d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + float deltaAngle, + float centerX, + float centerY, + float startAngleDegrees, + float scaleX, + float scaleY +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_TRUE | SAMPLER_ADDRESS | SAMPLER_FILTER; + + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + uint Nx = GET_IMAGE_WIDTH(src); + uint Ny = GET_IMAGE_HEIGHT(src); + uint Nz = GET_IMAGE_DEPTH(src); + + const float imageHalfWidth = GET_IMAGE_WIDTH(src) / 2; + const float imageHalfHeight = GET_IMAGE_HEIGHT(src) / 2; + + float angleInRad = (((float)z) * deltaAngle + startAngleDegrees) / 180.0 * M_PI; + //float maxRadius = sqrt(pow(imageHalfWidth, 2.0f) + pow(imageHalfHeight, 2.0f)); + float radius = x; + + const float sx = (centerX + sin(angleInRad) * radius * scaleX) + 0.5f; + const float sy = (centerY + cos(angleInRad) * radius * scaleY) + 0.5f; + const float sz = y + 0.5f; + + IMAGE_src_PIXEL_TYPE value = READ_src_IMAGE(src,sampler,(float2)(sx / Nx, sy / Ny)).x; + WRITE_dst_IMAGE(dst,(int4)(x, y, z, 0), CONVERT_dst_PIXEL_TYPE(value)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/reslice_radial_interpolate_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/reslice_radial_interpolate_3d_x.cl new file mode 100644 index 0000000..3ad713b --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/reslice_radial_interpolate_3d_x.cl @@ -0,0 +1,42 @@ + #ifndef SAMPLER_FILTER +#define SAMPLER_FILTER CLK_FILTER_LINEAR +#endif + +#ifndef SAMPLER_ADDRESS +#define SAMPLER_ADDRESS CLK_ADDRESS_CLAMP +#endif + +__kernel void reslice_radial_3d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + float deltaAngle, + float centerX, + float centerY, + float startAngleDegrees, + float scaleX, + float scaleY +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_TRUE | SAMPLER_ADDRESS | SAMPLER_FILTER; + + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + uint Nx = GET_IMAGE_WIDTH(src); + uint Ny = GET_IMAGE_HEIGHT(src); + uint Nz = GET_IMAGE_DEPTH(src); + + const float imageHalfWidth = GET_IMAGE_WIDTH(src) / 2; + const float imageHalfHeight = GET_IMAGE_HEIGHT(src) / 2; + + float angleInRad = (((float)z) * deltaAngle + startAngleDegrees) / 180.0 * M_PI; + //float maxRadius = sqrt(pow(imageHalfWidth, 2.0f) + pow(imageHalfHeight, 2.0f)); + float radius = x; + + const float sx = (centerX + sin(angleInRad) * radius * scaleX) + 0.5f; + const float sy = (centerY + cos(angleInRad) * radius * scaleY) + 0.5f; + const float sz = y + 0.5f; + + IMAGE_src_PIXEL_TYPE value = READ_src_IMAGE(src,sampler,(float4)(sx / Nx, sy / Ny, sz / Nz, 0)).x; + WRITE_dst_IMAGE(dst,(int4)(x, y, z, 0), CONVERT_dst_PIXEL_TYPE(value)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/reslice_right_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/reslice_right_3d_x.cl new file mode 100644 index 0000000..44bacb2 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/reslice_right_3d_x.cl @@ -0,0 +1,20 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void reslice_right_3d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int sx = get_global_id(2); + const int sy = get_global_id(0); + const int sz = get_global_id(1); + + const int dx = get_global_id(0); + const int dy = get_global_id(1); + const int dz = get_global_size(2) - get_global_id(2) - 1; + + const IMAGE_src_PIXEL_TYPE out = READ_src_IMAGE(src,sampler,(int4)(sx,sy,sz,0)).x; + WRITE_dst_IMAGE(dst,(int4)(dx,dy,dz,0), CONVERT_dst_PIXEL_TYPE(out)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/reslice_top_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/reslice_top_3d_x.cl new file mode 100644 index 0000000..3839f41 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/reslice_top_3d_x.cl @@ -0,0 +1,19 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void reslice_top_3d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int sx = get_global_id(0); + const int sy = get_global_id(2); + const int sz = get_global_id(1); + + const int dx = get_global_id(0); + const int dy = get_global_id(1); + const int dz = get_global_id(2); + + const IMAGE_src_PIXEL_TYPE out = READ_src_IMAGE(src,sampler,(int4)(sx,sy,sz,0)).x; + WRITE_dst_IMAGE(dst,(int4)(dx,dy,dz,0), CONVERT_dst_PIXEL_TYPE(out)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/reslicing.cl b/src/main/java/net/haesleinhuepf/clij/kernels/reslicing.cl deleted file mode 100644 index 9cdaa86..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/reslicing.cl +++ /dev/null @@ -1,65 +0,0 @@ -__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - - -__kernel void reslice_bottom_3d(DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int sx = get_global_id(0); - const int sy = get_global_id(2); - const int sz = get_global_id(1); - - const int dx = get_global_id(0); - const int dy = get_global_id(1); - const int dz = get_global_size(2) - get_global_id(2) - 1; - - const DTYPE_IN out = READ_IMAGE_3D(src,sampler,(int4)(sx,sy,sz,0)).x; - WRITE_IMAGE_3D(dst,(int4)(dx,dy,dz,0), CONVERT_DTYPE_OUT(out)); -} - -__kernel void reslice_left_3d(DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int sx = get_global_id(2); - const int sy = get_global_id(0); - const int sz = get_global_id(1); - - const int dx = get_global_id(0); - const int dy = get_global_id(1); - const int dz = get_global_id(2); - - const DTYPE_IN out = READ_IMAGE_3D(src,sampler,(int4)(sx,sy,sz,0)).x; - WRITE_IMAGE_3D(dst,(int4)(dx,dy,dz,0), CONVERT_DTYPE_OUT(out)); -} - - -__kernel void reslice_right_3d(DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int sx = get_global_id(2); - const int sy = get_global_id(0); - const int sz = get_global_id(1); - - const int dx = get_global_id(0); - const int dy = get_global_id(1); - const int dz = get_global_size(2) - get_global_id(2) - 1; - - const DTYPE_IN out = READ_IMAGE_3D(src,sampler,(int4)(sx,sy,sz,0)).x; - WRITE_IMAGE_3D(dst,(int4)(dx,dy,dz,0), CONVERT_DTYPE_OUT(out)); -} - - -__kernel void reslice_top_3d(DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int sx = get_global_id(0); - const int sy = get_global_id(2); - const int sz = get_global_id(1); - - const int dx = get_global_id(0); - const int dy = get_global_id(1); - const int dz = get_global_id(2); - - const DTYPE_IN out = READ_IMAGE_3D(src,sampler,(int4)(sx,sy,sz,0)).x; - WRITE_IMAGE_3D(dst,(int4)(dx,dy,dz,0), CONVERT_DTYPE_OUT(out)); -} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/rotate.cl b/src/main/java/net/haesleinhuepf/clij/kernels/rotate.cl deleted file mode 100644 index 9dfb018..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/rotate.cl +++ /dev/null @@ -1,60 +0,0 @@ -__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - - -__kernel void rotate_left_3d(DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int sx = get_global_size(1) - get_global_id(1) - 1; - const int sy = get_global_id(0); - const int sz = get_global_id(2); - - const int dx = get_global_id(0); - const int dy = get_global_id(1); - const int dz = get_global_id(2); - - const DTYPE_IN out = READ_IMAGE_3D(src,sampler,(int4)(sx,sy,sz,0)).x; - WRITE_IMAGE_3D(dst,(int4)(dx,dy,dz,0), CONVERT_DTYPE_OUT(out)); -} - -__kernel void rotate_right_3d(DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int sx = get_global_id(1); - const int sy = get_global_size(0) - get_global_id(0) - 1; - const int sz = get_global_id(2); - - const int dx = get_global_id(0); - const int dy = get_global_id(1); - const int dz = get_global_id(2); - - const DTYPE_IN out = READ_IMAGE_3D(src,sampler,(int4)(sx,sy,sz,0)).x; - WRITE_IMAGE_3D(dst,(int4)(dx,dy,dz,0), CONVERT_DTYPE_OUT(out)); -} - -__kernel void rotate_left_2d(DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int sx = get_global_size(1) - get_global_id(1) - 1; - const int sy = get_global_id(0); - - const int dx = get_global_id(0); - const int dy = get_global_id(1); - - const DTYPE_IN out = READ_IMAGE_2D(src,sampler,(int2)(sx,sy)).x; - WRITE_IMAGE_2D(dst,(int2)(dx,dy), CONVERT_DTYPE_OUT(out)); -} - - -__kernel void rotate_right_2d(DTYPE_IMAGE_OUT_2D dst, DTYPE_IMAGE_IN_2D src) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int sx = get_global_id(1); - const int sy = get_global_size(0) - get_global_id(0) - 1; - - const int dx = get_global_id(0); - const int dy = get_global_id(1); - - const DTYPE_IN out = READ_IMAGE_2D(src,sampler,(int2)(sx,sy)).x; - WRITE_IMAGE_2D(dst,(int2)(dx,dy), CONVERT_DTYPE_OUT(out)); -} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/rotate_clockwise_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/rotate_clockwise_2d_x.cl new file mode 100644 index 0000000..16490be --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/rotate_clockwise_2d_x.cl @@ -0,0 +1,18 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + +__kernel void rotate_right_2d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int sx = get_global_id(1); + const int sy = get_global_size(0) - get_global_id(0) - 1; + + const int dx = get_global_id(0); + const int dy = get_global_id(1); + + const IMAGE_src_PIXEL_TYPE out = READ_src_IMAGE(src,sampler,(int2)(sx,sy)).x; + WRITE_dst_IMAGE(dst,(int2)(dx,dy), CONVERT_dst_PIXEL_TYPE(out)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/rotate_clockwise_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/rotate_clockwise_3d_x.cl new file mode 100644 index 0000000..b8751dd --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/rotate_clockwise_3d_x.cl @@ -0,0 +1,19 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void rotate_right_3d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int sx = get_global_id(1); + const int sy = get_global_size(0) - get_global_id(0) - 1; + const int sz = get_global_id(2); + + const int dx = get_global_id(0); + const int dy = get_global_id(1); + const int dz = get_global_id(2); + + const IMAGE_src_PIXEL_TYPE out = READ_src_IMAGE(src,sampler,(int4)(sx,sy,sz,0)).x; + WRITE_dst_IMAGE(dst,(int4)(dx,dy,dz,0), CONVERT_dst_PIXEL_TYPE(out)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/rotate_counter_clockwise_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/rotate_counter_clockwise_2d_x.cl new file mode 100644 index 0000000..b3bff39 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/rotate_counter_clockwise_2d_x.cl @@ -0,0 +1,20 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + + +__kernel void rotate_left_2d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int sx = get_global_size(1) - get_global_id(1) - 1; + const int sy = get_global_id(0); + + const int dx = get_global_id(0); + const int dy = get_global_id(1); + + const IMAGE_src_PIXEL_TYPE out = READ_src_IMAGE(src,sampler,(int2)(sx,sy)).x; + WRITE_dst_IMAGE(dst,(int2)(dx,dy), CONVERT_dst_PIXEL_TYPE(out)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/rotate_counter_clockwise_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/rotate_counter_clockwise_3d_x.cl new file mode 100644 index 0000000..ba8b366 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/rotate_counter_clockwise_3d_x.cl @@ -0,0 +1,22 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + + +__kernel void rotate_left_3d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int sx = get_global_size(1) - get_global_id(1) - 1; + const int sy = get_global_id(0); + const int sz = get_global_id(2); + + const int dx = get_global_id(0); + const int dy = get_global_id(1); + const int dz = get_global_id(2); + + const IMAGE_src_PIXEL_TYPE out = READ_src_IMAGE(src,sampler,(int4)(sx,sy,sz,0)).x; + WRITE_dst_IMAGE(dst,(int4)(dx,dy,dz,0), CONVERT_dst_PIXEL_TYPE(out)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set.cl deleted file mode 100644 index bc43a83..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/set.cl +++ /dev/null @@ -1,22 +0,0 @@ - -__kernel void set_3d(DTYPE_IMAGE_OUT_3D dst, - float value - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - WRITE_IMAGE_3D (dst, (int4)(x,y,z,0), CONVERT_DTYPE_OUT(value)); -} - - -__kernel void set_2d(DTYPE_IMAGE_OUT_2D dst, - float value - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - WRITE_IMAGE_2D (dst, (int2)(x,y), CONVERT_DTYPE_OUT(value)); -} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_2d_x.cl new file mode 100644 index 0000000..8c8f578 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_2d_x.cl @@ -0,0 +1,11 @@ + +__kernel void set_2d( + IMAGE_dst_TYPE dst, + float value +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + WRITE_dst_IMAGE (dst, (int2)(x,y), CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_3d_x.cl new file mode 100644 index 0000000..aa0f3d5 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_3d_x.cl @@ -0,0 +1,13 @@ + +__kernel void set_3d( + IMAGE_dst_TYPE dst, + float value +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + WRITE_dst_IMAGE (dst, (int4)(x,y,z,0), CONVERT_dst_PIXEL_TYPE(value)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_column_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_column_2d_x.cl new file mode 100644 index 0000000..3ffcec0 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_column_2d_x.cl @@ -0,0 +1,12 @@ + +__kernel void set_column_2d( + IMAGE_dst_TYPE dst, + int column, + float value +) +{ + const int x = column; + const int y = get_global_id(1); + + WRITE_dst_IMAGE (dst, (int2)(x,y), CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_column_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_column_3d_x.cl new file mode 100644 index 0000000..6a4a7e5 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_column_3d_x.cl @@ -0,0 +1,14 @@ + +__kernel void set_column_3d( + IMAGE_dst_TYPE dst, + int column, + float value +) +{ + const int x = column; + const int y = get_global_id(1); + const int z = get_global_id(2); + + WRITE_dst_IMAGE (dst, (int4)(x,y,z,0), CONVERT_dst_PIXEL_TYPE(value)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_image_borders_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_image_borders_2d_x.cl new file mode 100644 index 0000000..c296f03 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_image_borders_2d_x.cl @@ -0,0 +1,13 @@ + +__kernel void set_image_borders_2d( + IMAGE_dst_TYPE dst, + float value +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + if (x == 0 || x == GET_IMAGE_WIDTH(dst) - 1 || y == 0 || y == GET_IMAGE_HEIGHT(dst) - 1) { + WRITE_dst_IMAGE (dst, POS_dst_INSTANCE(x,y,0,0), CONVERT_dst_PIXEL_TYPE(value)); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_image_borders_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_image_borders_3d_x.cl new file mode 100644 index 0000000..7ad3329 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_image_borders_3d_x.cl @@ -0,0 +1,14 @@ + +__kernel void set_image_borders_3d( + IMAGE_dst_TYPE dst, + float value +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + if (x == 0 || x == GET_IMAGE_WIDTH(dst) - 1 || y == 0 || y == GET_IMAGE_HEIGHT(dst) - 1 || z == 0 || z == GET_IMAGE_DEPTH(dst) - 1) { + WRITE_dst_IMAGE (dst, POS_dst_INSTANCE(x,y,z,0), CONVERT_dst_PIXEL_TYPE(value)); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_nonzero_pixels_to_pixelindex_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_nonzero_pixels_to_pixelindex_x.cl new file mode 100644 index 0000000..0c6b9f1 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_nonzero_pixels_to_pixelindex_x.cl @@ -0,0 +1,24 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void set_nonzero_pixels_to_pixelindex +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) +{ + const int i = get_global_id(0); + const int j = get_global_id(1); + const int k = get_global_id(2); + + const int w = GET_IMAGE_WIDTH(src); + const int h = GET_IMAGE_HEIGHT(src); + const int d = GET_IMAGE_DEPTH(src); + + float pixelindex = i * h * d + j * d + k; + float value = (float)(READ_src_IMAGE(src,sampler,POS_src_INSTANCE(i,j,k,0)).x); + if (value != 0) { + WRITE_dst_IMAGE(dst, POS_dst_INSTANCE(i,j,k,0),pixelindex); + } else { + WRITE_dst_IMAGE(dst, POS_dst_INSTANCE(i,j,k,0), 0); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_plane_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_plane_2d_x.cl new file mode 100644 index 0000000..ccb76aa --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_plane_2d_x.cl @@ -0,0 +1,14 @@ + +__kernel void set_plane_2d( + IMAGE_dst_TYPE dst, + int plane, + float value +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = plane; + + WRITE_dst_IMAGE (dst, (int4)(x,y,plane,0), CONVERT_dst_PIXEL_TYPE(value)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_plane_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_plane_3d_x.cl new file mode 100644 index 0000000..1c9d846 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_plane_3d_x.cl @@ -0,0 +1,14 @@ + +__kernel void set_plane_3d( + IMAGE_dst_TYPE dst, + int plane, + float value +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = plane; + + WRITE_dst_IMAGE (dst, (int4)(x,y,z,0), CONVERT_dst_PIXEL_TYPE(value)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_ramp_x_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_ramp_x_2d_x.cl new file mode 100644 index 0000000..0615d2a --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_ramp_x_2d_x.cl @@ -0,0 +1,11 @@ + +__kernel void set_ramp_x_2d( + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + WRITE_dst_IMAGE (dst, (int2)(x,y), CONVERT_dst_PIXEL_TYPE(x)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_ramp_x_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_ramp_x_3d_x.cl new file mode 100644 index 0000000..bb80534 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_ramp_x_3d_x.cl @@ -0,0 +1,12 @@ + +__kernel void set_ramp_x_3d( + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + WRITE_dst_IMAGE (dst, (int4)(x,y,z,0), CONVERT_dst_PIXEL_TYPE(x)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_ramp_y_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_ramp_y_2d_x.cl new file mode 100644 index 0000000..c63656a --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_ramp_y_2d_x.cl @@ -0,0 +1,11 @@ + +__kernel void set_ramp_y_2d( + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + WRITE_dst_IMAGE (dst, (int2)(x,y), CONVERT_dst_PIXEL_TYPE(y)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_ramp_y_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_ramp_y_3d_x.cl new file mode 100644 index 0000000..b00380e --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_ramp_y_3d_x.cl @@ -0,0 +1,12 @@ + +__kernel void set_ramp_y_3d( + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + WRITE_dst_IMAGE (dst, (int4)(x,y,z,0), CONVERT_dst_PIXEL_TYPE(y)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_ramp_z_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_ramp_z_2d_x.cl new file mode 100644 index 0000000..492c8fc --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_ramp_z_2d_x.cl @@ -0,0 +1,11 @@ + +__kernel void set_ramp_z_2d( + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + WRITE_dst_IMAGE (dst, (int2)(x,y), 0); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_ramp_z_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_ramp_z_3d_x.cl new file mode 100644 index 0000000..2307fb4 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_ramp_z_3d_x.cl @@ -0,0 +1,12 @@ + +__kernel void set_ramp_z_3d( + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + WRITE_dst_IMAGE (dst, (int4)(x,y,z,0), CONVERT_dst_PIXEL_TYPE(z)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_row_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_row_2d_x.cl new file mode 100644 index 0000000..b0c65e1 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_row_2d_x.cl @@ -0,0 +1,12 @@ + +__kernel void set_row_2d( + IMAGE_dst_TYPE dst, + int row, + float value +) +{ + const int x = get_global_id(0); + const int y = row; + + WRITE_dst_IMAGE (dst, (int2)(x,y), CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_row_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_row_3d_x.cl new file mode 100644 index 0000000..63458ec --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_row_3d_x.cl @@ -0,0 +1,14 @@ + +__kernel void set_row_3d( + IMAGE_dst_TYPE dst, + int row, + float value +) +{ + const int x = get_global_id(0); + const int y = row; + const int z = get_global_id(2); + + WRITE_dst_IMAGE (dst, (int4)(x,y,z,0), CONVERT_dst_PIXEL_TYPE(value)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_where_x_equals_y_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_where_x_equals_y_2d_x.cl new file mode 100644 index 0000000..219b3d6 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_where_x_equals_y_2d_x.cl @@ -0,0 +1,12 @@ + +__kernel void set_where_x_equals_y_2d( + IMAGE_dst_TYPE dst, + float value +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + if (x == y) { + WRITE_IMAGE (dst, (int2)(x,y), CONVERT_dst_PIXEL_TYPE(value)); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_where_x_equals_y_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_where_x_equals_y_3d_x.cl new file mode 100644 index 0000000..df9bf53 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_where_x_equals_y_3d_x.cl @@ -0,0 +1,14 @@ + +__kernel void set_where_x_equals_y_3d( + IMAGE_dst_TYPE dst, + float value +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + if (x == y) { + WRITE_IMAGE (dst, (int4)(x,y,z,0), CONVERT_dst_PIXEL_TYPE(value)); + } +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_where_x_greater_than_y_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_where_x_greater_than_y_2d_x.cl new file mode 100644 index 0000000..232d22c --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_where_x_greater_than_y_2d_x.cl @@ -0,0 +1,12 @@ + +__kernel void set_where_x_greater_than_y_2d( + IMAGE_dst_TYPE dst, + float value +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + if (x > y) { + WRITE_IMAGE (dst, (int2)(x,y), CONVERT_dst_PIXEL_TYPE(value)); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_where_x_greater_than_y_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_where_x_greater_than_y_3d_x.cl new file mode 100644 index 0000000..9d8b14d --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_where_x_greater_than_y_3d_x.cl @@ -0,0 +1,14 @@ + +__kernel void set_where_x_greater_than_y_3d( + IMAGE_dst_TYPE dst, + float value +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + if (x > y) { + WRITE_IMAGE (dst, (int4)(x,y,z,0), CONVERT_dst_PIXEL_TYPE(value)); + } +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_where_x_smaller_than_y_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_where_x_smaller_than_y_2d_x.cl new file mode 100644 index 0000000..bb7aaa7 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_where_x_smaller_than_y_2d_x.cl @@ -0,0 +1,12 @@ + +__kernel void set_where_x_smaller_than_y_2d( + IMAGE_dst_TYPE dst, + float value +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + if (x < y) { + WRITE_IMAGE (dst, (int2)(x,y), CONVERT_dst_PIXEL_TYPE(value)); + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/set_where_x_smaller_than_y_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/set_where_x_smaller_than_y_3d_x.cl new file mode 100644 index 0000000..85f1c4f --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/set_where_x_smaller_than_y_3d_x.cl @@ -0,0 +1,14 @@ + +__kernel void set_where_x_smaller_than_y_3d( + IMAGE_dst_TYPE dst, + float value +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + if (x < y) { + WRITE_IMAGE (dst, (int4)(x,y,z,0), CONVERT_dst_PIXEL_TYPE(value)); + } +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/smaller_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/smaller_2d_x.cl new file mode 100644 index 0000000..77065f3 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/smaller_2d_x.cl @@ -0,0 +1,22 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void smaller_2d( + IMAGE_src1_TYPE src1, + IMAGE_src2_TYPE src2, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + const float input2 = (float)READ_src2_IMAGE(src2, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 < input2) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/smaller_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/smaller_3d_x.cl new file mode 100644 index 0000000..af0d7e4 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/smaller_3d_x.cl @@ -0,0 +1,23 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void smaller_3d( + IMAGE_src1_TYPE src1, + IMAGE_src2_TYPE src2, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + const float input2 = (float)READ_sec2_IMAGE(src2, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 < input2) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/smaller_constant_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/smaller_constant_2d_x.cl new file mode 100644 index 0000000..00b41a8 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/smaller_constant_2d_x.cl @@ -0,0 +1,21 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void smaller_constant_2d( + IMAGE_src1_TYPE src1, + float scalar, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 < scalar) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/smaller_constant_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/smaller_constant_3d_x.cl new file mode 100644 index 0000000..8ef32f9 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/smaller_constant_3d_x.cl @@ -0,0 +1,22 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void smaller_constant_3d( + IMAGE_src1_TYPE src1, + float scalar, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 < scalar) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/smaller_or_equal_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/smaller_or_equal_2d_x.cl new file mode 100644 index 0000000..3b8f47e --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/smaller_or_equal_2d_x.cl @@ -0,0 +1,22 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void smaller_or_equal_2d( + IMAGE_src1_TYPE src1, + IMAGE_src2_TYPE src2, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + const float input2 = (float)READ_src2_IMAGE(src2, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 <= input2) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/smaller_or_equal_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/smaller_or_equal_3d_x.cl new file mode 100644 index 0000000..d31c81a --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/smaller_or_equal_3d_x.cl @@ -0,0 +1,23 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void smaller_or_equal_3d( + IMAGE_src1_TYPE src1, + IMAGE_src2_TYPE src2, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + const float input2 = (float)READ_sec2_IMAGE(src2, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 <= input2) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/smaller_or_equal_constant_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/smaller_or_equal_constant_2d_x.cl new file mode 100644 index 0000000..9e6eb07 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/smaller_or_equal_constant_2d_x.cl @@ -0,0 +1,21 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void smaller_or_equal_constant_2d( + IMAGE_src1_TYPE src1, + float scalar, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 <= scalar) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/smaller_or_equal_constant_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/smaller_or_equal_constant_3d_x.cl new file mode 100644 index 0000000..3f71b30 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/smaller_or_equal_constant_3d_x.cl @@ -0,0 +1,22 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void smaller_or_equal_constant_3d( + IMAGE_src1_TYPE src1, + float scalar, + IMAGE_dst_TYPE dst +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const float input1 = (float)READ_src1_IMAGE(src1, sampler, pos).x; + + IMAGE_dst_PIXEL_TYPE value = 0; + if (input1 <= scalar) { + value = 1; + } + WRITE_dst_IMAGE (dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/sobel_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/sobel_2d_x.cl new file mode 100644 index 0000000..5fa4e2a --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/sobel_2d_x.cl @@ -0,0 +1,43 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void sobel_2d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float valueCenter = READ_src_IMAGE(src, sampler, pos).x; + + float valueRight = READ_src_IMAGE(src, sampler, (pos + (int2){1, 0})).x; + float valueLeft = READ_src_IMAGE(src, sampler, (pos + (int2){-1, 0})).x; + float valueBottom = READ_src_IMAGE(src, sampler, (pos + (int2){0, 1})).x; + float valueTop = READ_src_IMAGE(src, sampler, (pos + (int2){0, -1})).x; + + float valueTopLeft = READ_src_IMAGE(src, sampler, (pos + (int2){-1, -1})).x; + float valueTopRight = READ_src_IMAGE(src, sampler, (pos + (int2){1, -1})).x; + float valueBottomLeft = READ_src_IMAGE(src, sampler, (pos + (int2){-1, 1})).x; + float valueBottomRight = READ_src_IMAGE(src, sampler, (pos + (int2){1, 1})).x; + + float result_x = valueTopLeft * -1.0 + + valueLeft * -2.0 + + valueBottomLeft * -1.0 + + valueTopRight * 1.0 + + valueRight * 2.0 + + valueBottomRight * 1.0; + + float result_y = valueTopLeft * -1.0 + + valueTop * -2.0 + + valueTopRight * -1.0 + + valueBottomLeft * 1.0 + + valueBottom * 2.0 + + valueBottomRight * 1.0; + + float result = sqrt(result_x * result_x + result_y * result_y); + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(result)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/sobel_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/sobel_3d_x.cl new file mode 100644 index 0000000..f7bdf35 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/sobel_3d_x.cl @@ -0,0 +1,57 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void sobel_3d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) +{ + + /*need 3 operations with 3 kernels for 3d sobel*/ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + int gy[3][3][3]; + int gx[3][3][3]; + int gz[3][3][3]; + + int hx[3]={1,2,1}; + int hy[3]={1,2,1}; + int hz[3]={1,2,1}; + + int hpx[3]={1,0,-1}; + int hpy[3]={1,0,-1}; + int hpz[3]={1,0,-1}; + + float sum_x,sum_y,sum_z; + int m,n,k; + + /*build the kernels i.e. h'_x(x,y,z)=h'(x)h(y)h(z)=gx(x,y,z)*/ + for(m=0;m<=2;m++) { + for(n=0;n<=2;n++) { + for(k=0;k<=2;k++){ + gx[m][n][k] = hpx[m] * hy[n] * hz[k]; + gy[m][n][k] = hx[m] * hpy[n] * hz[k]; + gz[m][n][k] = hx[m] * hy[n] * hpz[k]; + } + } + } + + sum_x=0,sum_y=0,sum_z=0; + for(m=0;m<=2;m++){ + for(n=0;n<=2;n++){ + for(k=0;k<=3;k++){ + sum_x += gx[m][n][k]*(READ_src_IMAGE(src, sampler, (pos + (int4){m-1, n-1,k-1, 0})).x); + sum_y += gy[m][n][k]*(READ_src_IMAGE(src, sampler, (pos + (int4){m-1, n-1,k-1, 0})).x); + sum_z += gz[m][n][k]*(READ_src_IMAGE(src, sampler, (pos + (int4){m-1, n-1,k-1, 0})).x); + } + } + } + + float result = sqrt(sum_x * sum_x + sum_y * sum_y + sum_z * sum_z); + + WRITE_dst_IMAGE (dst, pos, CONVERT_dst_PIXEL_TYPE(result)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/stacksplitting.cl b/src/main/java/net/haesleinhuepf/clij/kernels/stacksplitting.cl deleted file mode 100644 index e3609aa..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/stacksplitting.cl +++ /dev/null @@ -1,220 +0,0 @@ -__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - -__kernel void split_2_stacks(DTYPE_IMAGE_IN_3D src, DTYPE_IMAGE_OUT_3D dst0, DTYPE_IMAGE_OUT_3D dst1){ - - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - - WRITE_IMAGE_3D(dst0,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(const int4)(i,j,2*k,0)).x)); - WRITE_IMAGE_3D(dst1,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,2*k+1,0)).x)); -} - -__kernel void split_3_stacks(DTYPE_IMAGE_IN_3D src, DTYPE_IMAGE_OUT_3D dst0, DTYPE_IMAGE_OUT_3D dst1, DTYPE_IMAGE_OUT_3D dst2){ - - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - - WRITE_IMAGE_3D(dst0,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(const int4)(i,j,3*k,0)).x)); - WRITE_IMAGE_3D(dst1,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,3*k+1,0)).x)); - WRITE_IMAGE_3D(dst2,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,3*k+2,0)).x)); -} - -__kernel void split_4_stacks(DTYPE_IMAGE_IN_3D src, DTYPE_IMAGE_OUT_3D dst0, DTYPE_IMAGE_OUT_3D dst1, DTYPE_IMAGE_OUT_3D dst2, DTYPE_IMAGE_OUT_3D dst3){ - - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - - WRITE_IMAGE_3D(dst0,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(const int4)(i,j,4*k,0)).x)); - WRITE_IMAGE_3D(dst1,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,4*k+1,0)).x)); - WRITE_IMAGE_3D(dst2,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,4*k+2,0)).x)); - WRITE_IMAGE_3D(dst3,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,4*k+3,0)).x)); -} - -__kernel void split_5_stacks(DTYPE_IMAGE_IN_3D src, DTYPE_IMAGE_OUT_3D dst0, DTYPE_IMAGE_OUT_3D dst1, DTYPE_IMAGE_OUT_3D dst2, DTYPE_IMAGE_OUT_3D dst3, DTYPE_IMAGE_OUT_3D dst4){ - - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - - WRITE_IMAGE_3D(dst0,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(const int4)(i,j,5*k,0)).x)); - WRITE_IMAGE_3D(dst1,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,5*k+1,0)).x)); - WRITE_IMAGE_3D(dst2,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,5*k+2,0)).x)); - WRITE_IMAGE_3D(dst3,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,5*k+3,0)).x)); - WRITE_IMAGE_3D(dst4,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,5*k+4,0)).x)); -} - - -__kernel void split_6_stacks(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst0, - DTYPE_IMAGE_OUT_3D dst1, - DTYPE_IMAGE_OUT_3D dst2, - DTYPE_IMAGE_OUT_3D dst3, - DTYPE_IMAGE_OUT_3D dst4, - DTYPE_IMAGE_OUT_3D dst5 - ){ - - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - - WRITE_IMAGE_3D(dst0,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(const int4)(i,j,6*k,0)).x)); - WRITE_IMAGE_3D(dst1,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,6*k+1,0)).x)); - WRITE_IMAGE_3D(dst2,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,6*k+2,0)).x)); - WRITE_IMAGE_3D(dst3,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,6*k+3,0)).x)); - WRITE_IMAGE_3D(dst4,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,6*k+4,0)).x)); - WRITE_IMAGE_3D(dst5,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,6*k+5,0)).x)); -} - - -__kernel void split_7_stacks(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst0, - DTYPE_IMAGE_OUT_3D dst1, - DTYPE_IMAGE_OUT_3D dst2, - DTYPE_IMAGE_OUT_3D dst3, - DTYPE_IMAGE_OUT_3D dst4, - DTYPE_IMAGE_OUT_3D dst5, - DTYPE_IMAGE_OUT_3D dst6 - ){ - - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - - WRITE_IMAGE_3D(dst0,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(const int4)(i,j,7*k,0)).x)); - WRITE_IMAGE_3D(dst1,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,7*k+1,0)).x)); - WRITE_IMAGE_3D(dst2,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,7*k+2,0)).x)); - WRITE_IMAGE_3D(dst3,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,7*k+3,0)).x)); - WRITE_IMAGE_3D(dst4,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,7*k+4,0)).x)); - WRITE_IMAGE_3D(dst5,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,7*k+5,0)).x)); - WRITE_IMAGE_3D(dst6,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,7*k+6,0)).x)); -} - -__kernel void split_8_stacks(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst0, - DTYPE_IMAGE_OUT_3D dst1, - DTYPE_IMAGE_OUT_3D dst2, - DTYPE_IMAGE_OUT_3D dst3, - DTYPE_IMAGE_OUT_3D dst4, - DTYPE_IMAGE_OUT_3D dst5, - DTYPE_IMAGE_OUT_3D dst6, - DTYPE_IMAGE_OUT_3D dst7 - ){ - - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - - WRITE_IMAGE_3D(dst0,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(const int4)(i,j,8*k,0)).x)); - WRITE_IMAGE_3D(dst1,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,8*k+1,0)).x)); - WRITE_IMAGE_3D(dst2,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,8*k+2,0)).x)); - WRITE_IMAGE_3D(dst3,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,8*k+3,0)).x)); - WRITE_IMAGE_3D(dst4,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,8*k+4,0)).x)); - WRITE_IMAGE_3D(dst5,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,8*k+5,0)).x)); - WRITE_IMAGE_3D(dst6,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,8*k+6,0)).x)); - WRITE_IMAGE_3D(dst7,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,8*k+7,0)).x)); -} - - -__kernel void split_9_stacks(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst0, - DTYPE_IMAGE_OUT_3D dst1, - DTYPE_IMAGE_OUT_3D dst2, - DTYPE_IMAGE_OUT_3D dst3, - DTYPE_IMAGE_OUT_3D dst4, - DTYPE_IMAGE_OUT_3D dst5, - DTYPE_IMAGE_OUT_3D dst6, - DTYPE_IMAGE_OUT_3D dst7, - DTYPE_IMAGE_OUT_3D dst8 - ){ - - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - - WRITE_IMAGE_3D(dst0,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(const int4)(i,j,9*k,0)).x)); - WRITE_IMAGE_3D(dst1,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,9*k+1,0)).x)); - WRITE_IMAGE_3D(dst2,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,9*k+2,0)).x)); - WRITE_IMAGE_3D(dst3,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,9*k+3,0)).x)); - WRITE_IMAGE_3D(dst4,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,9*k+4,0)).x)); - WRITE_IMAGE_3D(dst5,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,9*k+5,0)).x)); - WRITE_IMAGE_3D(dst6,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,9*k+6,0)).x)); - WRITE_IMAGE_3D(dst7,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,9*k+7,0)).x)); - WRITE_IMAGE_3D(dst8,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,9*k+8,0)).x)); -} - -__kernel void split_10_stacks(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst0, - DTYPE_IMAGE_OUT_3D dst1, - DTYPE_IMAGE_OUT_3D dst2, - DTYPE_IMAGE_OUT_3D dst3, - DTYPE_IMAGE_OUT_3D dst4, - DTYPE_IMAGE_OUT_3D dst5, - DTYPE_IMAGE_OUT_3D dst6, - DTYPE_IMAGE_OUT_3D dst7, - DTYPE_IMAGE_OUT_3D dst8, - DTYPE_IMAGE_OUT_3D dst9 - ){ - - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - - WRITE_IMAGE_3D(dst0,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(const int4)(i,j,10*k,0)).x)); - WRITE_IMAGE_3D(dst1,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,10*k+1,0)).x)); - WRITE_IMAGE_3D(dst2,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,10*k+2,0)).x)); - WRITE_IMAGE_3D(dst3,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,10*k+3,0)).x)); - WRITE_IMAGE_3D(dst4,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,10*k+4,0)).x)); - WRITE_IMAGE_3D(dst5,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,10*k+5,0)).x)); - WRITE_IMAGE_3D(dst6,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,10*k+6,0)).x)); - WRITE_IMAGE_3D(dst7,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,10*k+7,0)).x)); - WRITE_IMAGE_3D(dst8,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,10*k+8,0)).x)); - WRITE_IMAGE_3D(dst9,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,10*k+9,0)).x)); -} - - -__kernel void split_11_stacks(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst0, - DTYPE_IMAGE_OUT_3D dst1, - DTYPE_IMAGE_OUT_3D dst2, - DTYPE_IMAGE_OUT_3D dst3, - DTYPE_IMAGE_OUT_3D dst4, - DTYPE_IMAGE_OUT_3D dst5, - DTYPE_IMAGE_OUT_3D dst6, - DTYPE_IMAGE_OUT_3D dst7, - DTYPE_IMAGE_OUT_3D dst8, - DTYPE_IMAGE_OUT_3D dst9, - DTYPE_IMAGE_OUT_3D dst10 - ){ - - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - - WRITE_IMAGE_3D(dst0,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(const int4)(i,j,11*k,0)).x)); - WRITE_IMAGE_3D(dst1,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,11*k+1,0)).x)); - WRITE_IMAGE_3D(dst2,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,11*k+2,0)).x)); - WRITE_IMAGE_3D(dst3,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,11*k+3,0)).x)); - WRITE_IMAGE_3D(dst4,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,11*k+4,0)).x)); - WRITE_IMAGE_3D(dst5,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,11*k+5,0)).x)); - WRITE_IMAGE_3D(dst6,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,11*k+6,0)).x)); - WRITE_IMAGE_3D(dst7,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,11*k+7,0)).x)); - WRITE_IMAGE_3D(dst8,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,11*k+8,0)).x)); - WRITE_IMAGE_3D(dst9,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,11*k+9,0)).x)); - WRITE_IMAGE_3D(dst10,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,11*k+10,0)).x)); -} - - -__kernel void split_12_stacks(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_OUT_3D dst0, - DTYPE_IMAGE_OUT_3D dst1, - DTYPE_IMAGE_OUT_3D dst2, - DTYPE_IMAGE_OUT_3D dst3, - DTYPE_IMAGE_OUT_3D dst4, - DTYPE_IMAGE_OUT_3D dst5, - DTYPE_IMAGE_OUT_3D dst6, - DTYPE_IMAGE_OUT_3D dst7, - DTYPE_IMAGE_OUT_3D dst8, - DTYPE_IMAGE_OUT_3D dst9, - DTYPE_IMAGE_OUT_3D dst10, - DTYPE_IMAGE_OUT_3D dst11 - ){ - - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - - WRITE_IMAGE_3D(dst0,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(const int4)(i,j,12*k,0)).x)); - WRITE_IMAGE_3D(dst1,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,12*k+1,0)).x)); - WRITE_IMAGE_3D(dst2,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,12*k+2,0)).x)); - WRITE_IMAGE_3D(dst3,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,12*k+3,0)).x)); - WRITE_IMAGE_3D(dst4,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,12*k+4,0)).x)); - WRITE_IMAGE_3D(dst5,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,12*k+5,0)).x)); - WRITE_IMAGE_3D(dst6,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,12*k+6,0)).x)); - WRITE_IMAGE_3D(dst7,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,12*k+7,0)).x)); - WRITE_IMAGE_3D(dst8,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,12*k+8,0)).x)); - WRITE_IMAGE_3D(dst9,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,12*k+9,0)).x)); - WRITE_IMAGE_3D(dst10,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,12*k+10,0)).x)); - WRITE_IMAGE_3D(dst11,(int4)(i,j,k,0),CONVERT_DTYPE_OUT(READ_IMAGE_3D(src,sampler,(int4)(i,j,12*k+11,0)).x)); -} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/standard_deviation_of_touching_neighbors_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/standard_deviation_of_touching_neighbors_x.cl new file mode 100644 index 0000000..eb575e4 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/standard_deviation_of_touching_neighbors_x.cl @@ -0,0 +1,72 @@ + +__kernel void standard_deviation_value_of_touching_neighbors ( + IMAGE_src_values_TYPE src_values, + IMAGE_src_touch_matrix_TYPE src_touch_matrix, + IMAGE_dst_values_TYPE dst_values, + int x_correction +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int label_id = get_global_id(0); + const int label_count = get_global_size(0); + + int count = 0; + float sum = 0; + + int y = label_id; + int x = 0; + for (x = 0; x < label_id; x++) { + float value = READ_IMAGE(src_touch_matrix, sampler, POS_src_touch_matrix_INSTANCE(x, y, 0, 0)).x; + if (value > 0) { + sum = sum + READ_IMAGE(src_values, sampler, POS_src_values_INSTANCE(x + x_correction, 0, 0, 0)).x; + count++; + } + } + + // assume the object is included in mean calculation + sum = sum + READ_IMAGE(src_values, sampler, POS_src_values_INSTANCE(label_id + x_correction, 0, 0, 0)).x; + count++; + + x = label_id; + for (y = label_id + 1; y < label_count; y++) { + float value = READ_IMAGE(src_touch_matrix, sampler, POS_src_touch_matrix_INSTANCE(x, y, 0, 0)).x; + if (value > 0) { + sum = sum + READ_IMAGE(src_values, sampler, POS_src_values_INSTANCE(y + x_correction, 0, 0, 0)).x; + count++; + } + } + + float average = sum / count; + + // ------------------------------------------------------------------------------------------------------------------- + sum = 0; + y = label_id; + x = 0; + for (x = 0; x < label_id; x++) { + float value = READ_IMAGE(src_touch_matrix, sampler, POS_src_touch_matrix_INSTANCE(x, y, 0, 0)).x; + if (value > 0) { + value = READ_IMAGE(src_values, sampler, POS_src_values_INSTANCE(x + x_correction, 0, 0, 0)).x - average; + sum = sum + value * value; + count++; + } + } + + // assume the object is included in mean calculation + float value1 = READ_IMAGE(src_values, sampler, POS_src_values_INSTANCE(label_id + x_correction, 0, 0, 0)).x - average; + sum = sum + value1 * value1; + count++; + + x = label_id; + for (y = label_id + 1; y < label_count; y++) { + float value = READ_IMAGE(src_touch_matrix, sampler, POS_src_touch_matrix_INSTANCE(x, y, 0, 0)).x; + if (value > 0) { + value = READ_IMAGE(src_values, sampler, POS_src_values_INSTANCE(y + x_correction, 0, 0, 0)).x - average; + sum = sum + value * value; + count++; + } + } + + float stdDev = sqrt((float2){sum / (count - 1), 0}).x; + WRITE_IMAGE(dst_values, POS_dst_values_INSTANCE(label_id, 0, 0, 0), CONVERT_dst_values_PIXEL_TYPE(stdDev)); +} + diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/standard_deviation_z_projection_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/standard_deviation_z_projection_x.cl new file mode 100644 index 0000000..6c11fa8 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/standard_deviation_z_projection_x.cl @@ -0,0 +1,28 @@ +__kernel void standard_deviation_z_projection( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + + float sum = 0; + int count = 0; + for(int z = 0; z < GET_IMAGE_DEPTH(src); z++) + { + sum = sum + (float)(READ_src_IMAGE(src,sampler,POS_src_INSTANCE(x,y,z,0)).x); + count++; + } + float mean = (sum / count); + + sum = 0; + for(int z = 0; z < GET_IMAGE_DEPTH(src); z++) + { + float value = (float)(READ_src_IMAGE(src,sampler,POS_src_INSTANCE(x,y,z,0)).x) - mean; + sum = sum + (value * value); + } + float stdDev = sqrt((float2){sum / (count - 1), 0}).x; + + WRITE_dst_IMAGE(dst,POS_dst_INSTANCE(x,y,0,0), CONVERT_dst_PIXEL_TYPE(stdDev)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/subtract_image_from_scalar_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/subtract_image_from_scalar_2d_x.cl new file mode 100644 index 0000000..a1e5fc2 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/subtract_image_from_scalar_2d_x.cl @@ -0,0 +1,17 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void subtract_image_from_scalar_2d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst, + float scalar +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(scalar - READ_src_IMAGE(src, sampler, pos).x); + + WRITE_dst_IMAGE (dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/subtract_image_from_scalar_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/subtract_image_from_scalar_3d_x.cl new file mode 100644 index 0000000..365f36a --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/subtract_image_from_scalar_3d_x.cl @@ -0,0 +1,18 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void subtract_image_from_scalar_3d( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst, + float scalar +) +{ + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + const IMAGE_dst_PIXEL_TYPE value = CONVERT_dst_PIXEL_TYPE(scalar - READ_src_IMAGE(src, sampler, pos).x ); + + WRITE_dst_IMAGE(dst, pos, value); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/sumProject.cl b/src/main/java/net/haesleinhuepf/clij/kernels/sumProject.cl deleted file mode 100644 index 5c9e8e4..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/sumProject.cl +++ /dev/null @@ -1,15 +0,0 @@ -__kernel void sum_project_3d_2d( - DTYPE_IMAGE_OUT_2D dst, - DTYPE_IMAGE_IN_3D src -) { - const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - - const int x = get_global_id(0); - const int y = get_global_id(1); - float sum = 0; - for(int z = 0; z < GET_IMAGE_IN_DEPTH(src); z++) - { - sum = sum + READ_IMAGE_3D(src,sampler,(int4)(x,y,z,0)).x; - } - WRITE_IMAGE_2D(dst,(int2)(x,y), CONVERT_DTYPE_OUT(sum)); -} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/sum_x_projection_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/sum_x_projection_x.cl new file mode 100644 index 0000000..5be2fec --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/sum_x_projection_x.cl @@ -0,0 +1,17 @@ + + +__kernel void sum_x_projection( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int z = get_global_id(0); + const int y = get_global_id(1); + float sum = 0; + for(int x = 0; x < GET_IMAGE_WIDTH(src); x++) + { + sum = sum + READ_src_IMAGE(src,sampler,POS_src_INSTANCE(x,y,z,0)).x; + } + WRITE_dst_IMAGE(dst,POS_dst_INSTANCE(z,y,0,0), CONVERT_dst_PIXEL_TYPE(sum)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/sum_y_projection_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/sum_y_projection_x.cl new file mode 100644 index 0000000..5b7a02c --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/sum_y_projection_x.cl @@ -0,0 +1,17 @@ + + +__kernel void sum_y_projection( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int z = get_global_id(1); + float sum = 0; + for(int y = 0; y < GET_IMAGE_HEIGHT(src); y++) + { + sum = sum + READ_src_IMAGE(src,sampler,POS_src_INSTANCE(x,y,z,0)).x; + } + WRITE_dst_IMAGE(dst,POS_dst_INSTANCE(x,z,0,0), CONVERT_dst_PIXEL_TYPE(sum)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/sum_z_projection_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/sum_z_projection_x.cl new file mode 100644 index 0000000..9dc681a --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/sum_z_projection_x.cl @@ -0,0 +1,17 @@ + + +__kernel void sum_z_projection( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + float sum = 0; + for(int z = 0; z < GET_IMAGE_DEPTH(src); z++) + { + sum = sum + READ_src_IMAGE(src,sampler,POS_src_INSTANCE(x,y,z,0)).x; + } + WRITE_dst_IMAGE(dst,POS_dst_INSTANCE(x,y,0,0), CONVERT_dst_PIXEL_TYPE(sum)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/tenengradFusion.cl b/src/main/java/net/haesleinhuepf/clij/kernels/tenengradFusion.cl deleted file mode 100644 index e7b126d..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/tenengradFusion.cl +++ /dev/null @@ -1,520 +0,0 @@ -__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - -__constant float hx[] = {-1,-2,-1,-2,-4,-2,-1,-2,-1,0,0,0,0,0,0,0,0,0,1,2,1,2,4,2,1,2,1}; -__constant float hy[] = {-1,-2,-1,0,0,0,1,2,1,-2,-4,-2,0,0,0,2,4,2,-1,-2,-1,0,0,0,1,2,1}; -__constant float hz[] = {-1,0,1,-2,0,2,-1,0,1,-2,0,2,-4,0,4,-2,0,2,-1,0,1,-2,0,2,-1,0,1}; - - -inline float sobel_magnitude_squared(DTYPE_IMAGE_IN_3D src, const int i0, const int j0, const int k0) { - float Gx = 0.0f, Gy = 0.0f, Gz = 0.0f; - for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) for (int k = 0; k < 3; ++k) { - const int dx = i-1, dy = j-1, dz = k-1; - const int ind = i + 3*j + 3*3*k; - const float pix = (float)READ_IMAGE_3D(src,sampler,(int4)(i0+dx,j0+dy,k0+dz,0)).x; - Gx += hx[ind]*pix; - Gy += hy[ind]*pix; - Gz += hz[ind]*pix; - } - return Gx*Gx + Gy*Gy + Gz*Gz; -} - - -__kernel void tenengrad_weight_unnormalized(DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src) { - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4)(i,j,k,0); - float w = sobel_magnitude_squared(src,i,j,k); - // w = w*w; - WRITE_IMAGE_3D(dst,coord, CONVERT_DTYPE_OUT(w)); -} - -inline float sobel_magnitude_squared_slice_wise(DTYPE_IMAGE_IN_3D src, const int i0, const int j0, const int k0) { - float Gx = 0.0f, Gy = 0.0f; - for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) for (int k = 0; k < 3; ++k) { - const int dx = i-1, dy = j-1, dz = k-1; - const int ind = i + 3*j + 3*3*k; - const float pix = (float)READ_IMAGE_3D(src,sampler,(int4)(i0+dx,j0+dy,k0+dz,0)).x; - Gx += hx[ind]*pix; - Gy += hy[ind]*pix; - } - return Gx*Gx + Gy*Gy; -} - - -__kernel void tenengrad_weight_unnormalized_slice_wise(DTYPE_IMAGE_OUT_3D dst, DTYPE_IMAGE_IN_3D src) { - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4)(i,j,k,0); - float w = sobel_magnitude_squared_slice_wise(src,i,j,k); - // w = w*w; - WRITE_IMAGE_3D(dst,coord, CONVERT_DTYPE_OUT(w)); -} - - -__kernel void tenengrad_fusion_with_provided_weights_2_images( - DTYPE_IMAGE_OUT_3D dst, const int factor, - DTYPE_IMAGE_IN_3D src0, DTYPE_IMAGE_IN_3D src1, - DTYPE_IMAGE_IN_3D weight0, DTYPE_IMAGE_IN_3D weight1 -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4)(i,j,k,0); - - const float4 coord_weight = (float4)((i+0.5f)/factor,(j+0.5f)/factor,k+0.5f,0); - const sampler_t sampler_weight = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_LINEAR; - - float w0 = read_imagef(weight0,sampler_weight,coord_weight).x; - float w1 = read_imagef(weight1,sampler_weight,coord_weight).x; - - const float wsum = w0 + w1 + 1e-30f; // add small epsilon to avoid wsum = 0 - w0 /= wsum; - w1 /= wsum; - - const float v0 = (float)READ_IMAGE_3D(src0,sampler,coord).x; - const float v1 = (float)READ_IMAGE_3D(src1,sampler,coord).x; - const float res = w0 * v0 + w1 * v1; - - WRITE_IMAGE_3D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - - -__kernel void tenengrad_fusion_with_provided_weights_3_images( - DTYPE_IMAGE_OUT_3D dst, const int factor, - DTYPE_IMAGE_IN_3D src0, DTYPE_IMAGE_IN_3D src1, DTYPE_IMAGE_IN_3D src2, - DTYPE_IMAGE_IN_3D weight0, DTYPE_IMAGE_IN_3D weight1, DTYPE_IMAGE_IN_3D weight2 -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4)(i,j,k,0); - - const float4 coord_weight = (float4)((i+0.5f)/factor,(j+0.5f)/factor,k+0.5f,0); - const sampler_t sampler_weight = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_LINEAR; - - float w0 = read_imagef(weight0,sampler_weight,coord_weight).x; - float w1 = read_imagef(weight1,sampler_weight,coord_weight).x; - float w2 = read_imagef(weight2,sampler_weight,coord_weight).x; - - const float wsum = w0 + w1 + w2 + 1e-30f; // add small epsilon to avoid wsum = 0 - w0 /= wsum; - w1 /= wsum; - w2 /= wsum; - - const float v0 = (float)READ_IMAGE_3D(src0,sampler,coord).x; - const float v1 = (float)READ_IMAGE_3D(src1,sampler,coord).x; - const float v2 = (float)READ_IMAGE_3D(src2,sampler,coord).x; - const float res = w0 * v0 + w1 * v1 + w2 * v2; - - WRITE_IMAGE_3D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - - - -__kernel void tenengrad_fusion_with_provided_weights_4_images( - DTYPE_IMAGE_OUT_3D dst, const int factor, - DTYPE_IMAGE_IN_3D src0, DTYPE_IMAGE_IN_3D src1, DTYPE_IMAGE_IN_3D src2, DTYPE_IMAGE_IN_3D src3, - DTYPE_IMAGE_IN_3D weight0, DTYPE_IMAGE_IN_3D weight1, DTYPE_IMAGE_IN_3D weight2, DTYPE_IMAGE_IN_3D weight3 -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4)(i,j,k,0); - - const float4 coord_weight = (float4)((i+0.5f)/factor,(j+0.5f)/factor,k+0.5f,0); - const sampler_t sampler_weight = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_LINEAR; - - float w0 = read_imagef(weight0,sampler_weight,coord_weight).x; - float w1 = read_imagef(weight1,sampler_weight,coord_weight).x; - float w2 = read_imagef(weight2,sampler_weight,coord_weight).x; - float w3 = read_imagef(weight3,sampler_weight,coord_weight).x; - - const float wsum = w0 + w1 + w2 + w3 + 1e-30f; // add small epsilon to avoid wsum = 0 - w0 /= wsum; - w1 /= wsum; - w2 /= wsum; - w3 /= wsum; - - const float v0 = (float)READ_IMAGE_3D(src0,sampler,coord).x; - const float v1 = (float)READ_IMAGE_3D(src1,sampler,coord).x; - const float v2 = (float)READ_IMAGE_3D(src2,sampler,coord).x; - const float v3 = (float)READ_IMAGE_3D(src3,sampler,coord).x; - const float res = w0 * v0 + w1 * v1 + w2 * v2 + w3 * v3; - - WRITE_IMAGE_3D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - - -__kernel void tenengrad_fusion_with_provided_weights_5_images( - DTYPE_IMAGE_OUT_3D dst, const int factor, - DTYPE_IMAGE_IN_3D src0, DTYPE_IMAGE_IN_3D src1, DTYPE_IMAGE_IN_3D src2, DTYPE_IMAGE_IN_3D src3, DTYPE_IMAGE_IN_3D src4, - DTYPE_IMAGE_IN_3D weight0, DTYPE_IMAGE_IN_3D weight1, DTYPE_IMAGE_IN_3D weight2, DTYPE_IMAGE_IN_3D weight3, DTYPE_IMAGE_IN_3D weight4 -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4)(i,j,k,0); - - const float4 coord_weight = (float4)((i+0.5f)/factor,(j+0.5f)/factor,k+0.5f,0); - const sampler_t sampler_weight = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_LINEAR; - - float w0 = read_imagef(weight0,sampler_weight,coord_weight).x; - float w1 = read_imagef(weight1,sampler_weight,coord_weight).x; - float w2 = read_imagef(weight2,sampler_weight,coord_weight).x; - float w3 = read_imagef(weight3,sampler_weight,coord_weight).x; - float w4 = read_imagef(weight4,sampler_weight,coord_weight).x; - - const float wsum = w0 + w1 + w2 + w3 + w4 + 1e-30f; // add small epsilon to avoid wsum = 0 - w0 /= wsum; - w1 /= wsum; - w2 /= wsum; - w3 /= wsum; - w4 /= wsum; - - const float v0 = (float)READ_IMAGE_3D(src0,sampler,coord).x; - const float v1 = (float)READ_IMAGE_3D(src1,sampler,coord).x; - const float v2 = (float)READ_IMAGE_3D(src2,sampler,coord).x; - const float v3 = (float)READ_IMAGE_3D(src3,sampler,coord).x; - const float v4 = (float)READ_IMAGE_3D(src4,sampler,coord).x; - const float res = w0 * v0 + w1 * v1 + w2 * v2 + w3 * v3 + w4 * v4; - - WRITE_IMAGE_3D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - - -__kernel void tenengrad_fusion_with_provided_weights_6_images( - DTYPE_IMAGE_OUT_3D dst, const int factor, - DTYPE_IMAGE_IN_3D src0, DTYPE_IMAGE_IN_3D src1, DTYPE_IMAGE_IN_3D src2, DTYPE_IMAGE_IN_3D src3, DTYPE_IMAGE_IN_3D src4, DTYPE_IMAGE_IN_3D src5, - DTYPE_IMAGE_IN_3D weight0, DTYPE_IMAGE_IN_3D weight1, DTYPE_IMAGE_IN_3D weight2, DTYPE_IMAGE_IN_3D weight3, DTYPE_IMAGE_IN_3D weight4, DTYPE_IMAGE_IN_3D weight5 -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4)(i,j,k,0); - - const float4 coord_weight = (float4)((i+0.5f)/factor,(j+0.5f)/factor,k+0.5f,0); - const sampler_t sampler_weight = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_LINEAR; - - float w0 = read_imagef(weight0,sampler_weight,coord_weight).x; - float w1 = read_imagef(weight1,sampler_weight,coord_weight).x; - float w2 = read_imagef(weight2,sampler_weight,coord_weight).x; - float w3 = read_imagef(weight3,sampler_weight,coord_weight).x; - float w4 = read_imagef(weight4,sampler_weight,coord_weight).x; - float w5 = read_imagef(weight5,sampler_weight,coord_weight).x; - - const float wsum = w0 + w1 + w2 + w3 + w4 + w5 + 1e-30f; // add small epsilon to avoid wsum = 0 - w0 /= wsum; - w1 /= wsum; - w2 /= wsum; - w3 /= wsum; - w4 /= wsum; - w5 /= wsum; - - const float v0 = (float)READ_IMAGE_3D(src0,sampler,coord).x; - const float v1 = (float)READ_IMAGE_3D(src1,sampler,coord).x; - const float v2 = (float)READ_IMAGE_3D(src2,sampler,coord).x; - const float v3 = (float)READ_IMAGE_3D(src3,sampler,coord).x; - const float v4 = (float)READ_IMAGE_3D(src4,sampler,coord).x; - const float v5 = (float)READ_IMAGE_3D(src5,sampler,coord).x; - const float res = w0 * v0 + w1 * v1 + w2 * v2 + w3 * v3 + w4 * v4 + w5 * v5; - - WRITE_IMAGE_3D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - - -__kernel void tenengrad_fusion_with_provided_weights_7_images( - DTYPE_IMAGE_OUT_3D dst, const int factor, - DTYPE_IMAGE_IN_3D src0, DTYPE_IMAGE_IN_3D src1, DTYPE_IMAGE_IN_3D src2, DTYPE_IMAGE_IN_3D src3, DTYPE_IMAGE_IN_3D src4, DTYPE_IMAGE_IN_3D src5, - DTYPE_IMAGE_IN_3D src6, - DTYPE_IMAGE_IN_3D weight0, DTYPE_IMAGE_IN_3D weight1, DTYPE_IMAGE_IN_3D weight2, DTYPE_IMAGE_IN_3D weight3, DTYPE_IMAGE_IN_3D weight4, DTYPE_IMAGE_IN_3D weight5, - DTYPE_IMAGE_IN_3D weight6 -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4)(i,j,k,0); - - const float4 coord_weight = (float4)((i+0.5f)/factor,(j+0.5f)/factor,k+0.5f,0); - const sampler_t sampler_weight = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_LINEAR; - - float w0 = read_imagef(weight0,sampler_weight,coord_weight).x; - float w1 = read_imagef(weight1,sampler_weight,coord_weight).x; - float w2 = read_imagef(weight2,sampler_weight,coord_weight).x; - float w3 = read_imagef(weight3,sampler_weight,coord_weight).x; - float w4 = read_imagef(weight4,sampler_weight,coord_weight).x; - float w5 = read_imagef(weight5,sampler_weight,coord_weight).x; - float w6 = read_imagef(weight6,sampler_weight,coord_weight).x; - - const float wsum = w0 + w1 + w2 + w3 + w4 + w5 + w6 + 1e-30f; // add small epsilon to avoid wsum = 0 - w0 /= wsum; - w1 /= wsum; - w2 /= wsum; - w3 /= wsum; - w4 /= wsum; - w5 /= wsum; - w6 /= wsum; - - const float v0 = (float)READ_IMAGE_3D(src0,sampler,coord).x; - const float v1 = (float)READ_IMAGE_3D(src1,sampler,coord).x; - const float v2 = (float)READ_IMAGE_3D(src2,sampler,coord).x; - const float v3 = (float)READ_IMAGE_3D(src3,sampler,coord).x; - const float v4 = (float)READ_IMAGE_3D(src4,sampler,coord).x; - const float v5 = (float)READ_IMAGE_3D(src5,sampler,coord).x; - const float v6 = (float)READ_IMAGE_3D(src6,sampler,coord).x; - const float res = w0 * v0 + w1 * v1 + w2 * v2 + w3 * v3 + w4 * v4 + w5 * v5 + w6 * v6; - - WRITE_IMAGE_3D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - - -__kernel void tenengrad_fusion_with_provided_weights_8_images( - DTYPE_IMAGE_OUT_3D dst, const int factor, - DTYPE_IMAGE_IN_3D src0, DTYPE_IMAGE_IN_3D src1, DTYPE_IMAGE_IN_3D src2, DTYPE_IMAGE_IN_3D src3, DTYPE_IMAGE_IN_3D src4, DTYPE_IMAGE_IN_3D src5, - DTYPE_IMAGE_IN_3D src6, DTYPE_IMAGE_IN_3D src7, - DTYPE_IMAGE_IN_3D weight0, DTYPE_IMAGE_IN_3D weight1, DTYPE_IMAGE_IN_3D weight2, DTYPE_IMAGE_IN_3D weight3, DTYPE_IMAGE_IN_3D weight4, DTYPE_IMAGE_IN_3D weight5, - DTYPE_IMAGE_IN_3D weight6, DTYPE_IMAGE_IN_3D weight7 -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4)(i,j,k,0); - - const float4 coord_weight = (float4)((i+0.5f)/factor,(j+0.5f)/factor,k+0.5f,0); - const sampler_t sampler_weight = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_LINEAR; - - float w0 = read_imagef(weight0,sampler_weight,coord_weight).x; - float w1 = read_imagef(weight1,sampler_weight,coord_weight).x; - float w2 = read_imagef(weight2,sampler_weight,coord_weight).x; - float w3 = read_imagef(weight3,sampler_weight,coord_weight).x; - float w4 = read_imagef(weight4,sampler_weight,coord_weight).x; - float w5 = read_imagef(weight5,sampler_weight,coord_weight).x; - float w6 = read_imagef(weight6,sampler_weight,coord_weight).x; - float w7 = read_imagef(weight7,sampler_weight,coord_weight).x; - - const float wsum = w0 + w1 + w2 + w3 + w4 + w5 + w6 + w7 + 1e-30f; // add small epsilon to avoid wsum = 0 - w0 /= wsum; - w1 /= wsum; - w2 /= wsum; - w3 /= wsum; - w4 /= wsum; - w5 /= wsum; - w6 /= wsum; - w7 /= wsum; - - const float v0 = (float)READ_IMAGE_3D(src0,sampler,coord).x; - const float v1 = (float)READ_IMAGE_3D(src1,sampler,coord).x; - const float v2 = (float)READ_IMAGE_3D(src2,sampler,coord).x; - const float v3 = (float)READ_IMAGE_3D(src3,sampler,coord).x; - const float v4 = (float)READ_IMAGE_3D(src4,sampler,coord).x; - const float v5 = (float)READ_IMAGE_3D(src5,sampler,coord).x; - const float v6 = (float)READ_IMAGE_3D(src6,sampler,coord).x; - const float v7 = (float)READ_IMAGE_3D(src7,sampler,coord).x; - const float res = w0 * v0 + w1 * v1 + w2 * v2 + w3 * v3 + w4 * v4 + w5 * v5 + w6 * v6 + w7 * v7; - - WRITE_IMAGE_3D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - -__kernel void tenengrad_fusion_with_provided_weights_9_images( - DTYPE_IMAGE_OUT_3D dst, const int factor, - DTYPE_IMAGE_IN_3D src0, DTYPE_IMAGE_IN_3D src1, DTYPE_IMAGE_IN_3D src2, DTYPE_IMAGE_IN_3D src3, DTYPE_IMAGE_IN_3D src4, DTYPE_IMAGE_IN_3D src5, - DTYPE_IMAGE_IN_3D src6, DTYPE_IMAGE_IN_3D src7, DTYPE_IMAGE_IN_3D src8, - DTYPE_IMAGE_IN_3D weight0, DTYPE_IMAGE_IN_3D weight1, DTYPE_IMAGE_IN_3D weight2, DTYPE_IMAGE_IN_3D weight3, DTYPE_IMAGE_IN_3D weight4, DTYPE_IMAGE_IN_3D weight5, - DTYPE_IMAGE_IN_3D weight6, DTYPE_IMAGE_IN_3D weight7, DTYPE_IMAGE_IN_3D weight8 -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4)(i,j,k,0); - - const float4 coord_weight = (float4)((i+0.5f)/factor,(j+0.5f)/factor,k+0.5f,0); - const sampler_t sampler_weight = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_LINEAR; - - float w0 = read_imagef(weight0,sampler_weight,coord_weight).x; - float w1 = read_imagef(weight1,sampler_weight,coord_weight).x; - float w2 = read_imagef(weight2,sampler_weight,coord_weight).x; - float w3 = read_imagef(weight3,sampler_weight,coord_weight).x; - float w4 = read_imagef(weight4,sampler_weight,coord_weight).x; - float w5 = read_imagef(weight5,sampler_weight,coord_weight).x; - float w6 = read_imagef(weight6,sampler_weight,coord_weight).x; - float w7 = read_imagef(weight7,sampler_weight,coord_weight).x; - float w8 = read_imagef(weight8,sampler_weight,coord_weight).x; - - const float wsum = w0 + w1 + w2 + w3 + w4 + w5 + w6 + w7 + w8 + 1e-30f; // add small epsilon to avoid wsum = 0 - w0 /= wsum; - w1 /= wsum; - w2 /= wsum; - w3 /= wsum; - w4 /= wsum; - w5 /= wsum; - w6 /= wsum; - w7 /= wsum; - w8 /= wsum; - - const float v0 = (float)READ_IMAGE_3D(src0,sampler,coord).x; - const float v1 = (float)READ_IMAGE_3D(src1,sampler,coord).x; - const float v2 = (float)READ_IMAGE_3D(src2,sampler,coord).x; - const float v3 = (float)READ_IMAGE_3D(src3,sampler,coord).x; - const float v4 = (float)READ_IMAGE_3D(src4,sampler,coord).x; - const float v5 = (float)READ_IMAGE_3D(src5,sampler,coord).x; - const float v6 = (float)READ_IMAGE_3D(src6,sampler,coord).x; - const float v7 = (float)READ_IMAGE_3D(src7,sampler,coord).x; - const float v8 = (float)READ_IMAGE_3D(src8,sampler,coord).x; - const float res = w0 * v0 + w1 * v1 + w2 * v2 + w3 * v3 + w4 * v4 + w5 * v5 + w6 * v6 + w7 * v7 + w8 * v8; - - WRITE_IMAGE_3D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - -__kernel void tenengrad_fusion_with_provided_weights_10_images( - DTYPE_IMAGE_OUT_3D dst, const int factor, - DTYPE_IMAGE_IN_3D src0, DTYPE_IMAGE_IN_3D src1, DTYPE_IMAGE_IN_3D src2, DTYPE_IMAGE_IN_3D src3, DTYPE_IMAGE_IN_3D src4, DTYPE_IMAGE_IN_3D src5, - DTYPE_IMAGE_IN_3D src6, DTYPE_IMAGE_IN_3D src7, DTYPE_IMAGE_IN_3D src8, DTYPE_IMAGE_IN_3D src9, - DTYPE_IMAGE_IN_3D weight0, DTYPE_IMAGE_IN_3D weight1, DTYPE_IMAGE_IN_3D weight2, DTYPE_IMAGE_IN_3D weight3, DTYPE_IMAGE_IN_3D weight4, DTYPE_IMAGE_IN_3D weight5, - DTYPE_IMAGE_IN_3D weight6, DTYPE_IMAGE_IN_3D weight7, DTYPE_IMAGE_IN_3D weight8, DTYPE_IMAGE_IN_3D weight9 -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4)(i,j,k,0); - - const float4 coord_weight = (float4)((i+0.5f)/factor,(j+0.5f)/factor,k+0.5f,0); - const sampler_t sampler_weight = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_LINEAR; - - float w0 = read_imagef(weight0,sampler_weight,coord_weight).x; - float w1 = read_imagef(weight1,sampler_weight,coord_weight).x; - float w2 = read_imagef(weight2,sampler_weight,coord_weight).x; - float w3 = read_imagef(weight3,sampler_weight,coord_weight).x; - float w4 = read_imagef(weight4,sampler_weight,coord_weight).x; - float w5 = read_imagef(weight5,sampler_weight,coord_weight).x; - float w6 = read_imagef(weight6,sampler_weight,coord_weight).x; - float w7 = read_imagef(weight7,sampler_weight,coord_weight).x; - float w8 = read_imagef(weight8,sampler_weight,coord_weight).x; - float w9 = read_imagef(weight9,sampler_weight,coord_weight).x; - - const float wsum = w0 + w1 + w2 + w3 + w4 + w5 + w6 + w7 + w8 + w9 + 1e-30f; // add small epsilon to avoid wsum = 0 - w0 /= wsum; - w1 /= wsum; - w2 /= wsum; - w3 /= wsum; - w4 /= wsum; - w5 /= wsum; - w6 /= wsum; - w7 /= wsum; - w8 /= wsum; - w9 /= wsum; - - const float v0 = (float)READ_IMAGE_3D(src0,sampler,coord).x; - const float v1 = (float)READ_IMAGE_3D(src1,sampler,coord).x; - const float v2 = (float)READ_IMAGE_3D(src2,sampler,coord).x; - const float v3 = (float)READ_IMAGE_3D(src3,sampler,coord).x; - const float v4 = (float)READ_IMAGE_3D(src4,sampler,coord).x; - const float v5 = (float)READ_IMAGE_3D(src5,sampler,coord).x; - const float v6 = (float)READ_IMAGE_3D(src6,sampler,coord).x; - const float v7 = (float)READ_IMAGE_3D(src7,sampler,coord).x; - const float v8 = (float)READ_IMAGE_3D(src8,sampler,coord).x; - const float v9 = (float)READ_IMAGE_3D(src9,sampler,coord).x; - const float res = w0 * v0 + w1 * v1 + w2 * v2 + w3 * v3 + w4 * v4 + w5 * v5 + w6 * v6 + w7 * v7 + w8 * v8 + w9 * v9; - - WRITE_IMAGE_3D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - -__kernel void tenengrad_fusion_with_provided_weights_11_images( - DTYPE_IMAGE_OUT_3D dst, const int factor, - DTYPE_IMAGE_IN_3D src0, DTYPE_IMAGE_IN_3D src1, DTYPE_IMAGE_IN_3D src2, DTYPE_IMAGE_IN_3D src3, DTYPE_IMAGE_IN_3D src4, DTYPE_IMAGE_IN_3D src5, - DTYPE_IMAGE_IN_3D src6, DTYPE_IMAGE_IN_3D src7, DTYPE_IMAGE_IN_3D src8, DTYPE_IMAGE_IN_3D src9, DTYPE_IMAGE_IN_3D src10, - DTYPE_IMAGE_IN_3D weight0, DTYPE_IMAGE_IN_3D weight1, DTYPE_IMAGE_IN_3D weight2, DTYPE_IMAGE_IN_3D weight3, DTYPE_IMAGE_IN_3D weight4, DTYPE_IMAGE_IN_3D weight5, - DTYPE_IMAGE_IN_3D weight6, DTYPE_IMAGE_IN_3D weight7, DTYPE_IMAGE_IN_3D weight8, DTYPE_IMAGE_IN_3D weight9, DTYPE_IMAGE_IN_3D weight10 -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4)(i,j,k,0); - - const float4 coord_weight = (float4)((i+0.5f)/factor,(j+0.5f)/factor,k+0.5f,0); - const sampler_t sampler_weight = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_LINEAR; - - float w0 = read_imagef(weight0,sampler_weight,coord_weight).x; - float w1 = read_imagef(weight1,sampler_weight,coord_weight).x; - float w2 = read_imagef(weight2,sampler_weight,coord_weight).x; - float w3 = read_imagef(weight3,sampler_weight,coord_weight).x; - float w4 = read_imagef(weight4,sampler_weight,coord_weight).x; - float w5 = read_imagef(weight5,sampler_weight,coord_weight).x; - float w6 = read_imagef(weight6,sampler_weight,coord_weight).x; - float w7 = read_imagef(weight7,sampler_weight,coord_weight).x; - float w8 = read_imagef(weight8,sampler_weight,coord_weight).x; - float w9 = read_imagef(weight9,sampler_weight,coord_weight).x; - float w10 = read_imagef(weight9,sampler_weight,coord_weight).x; - - const float wsum = w0 + w1 + w2 + w3 + w4 + w5 + w6 + w7 + w8 + w9 + w10 + 1e-30f; // add small epsilon to avoid wsum = 0 - w0 /= wsum; - w1 /= wsum; - w2 /= wsum; - w3 /= wsum; - w4 /= wsum; - w5 /= wsum; - w6 /= wsum; - w7 /= wsum; - w8 /= wsum; - w9 /= wsum; - w10 /= wsum; - - const float v0 = (float)READ_IMAGE_3D(src0,sampler,coord).x; - const float v1 = (float)READ_IMAGE_3D(src1,sampler,coord).x; - const float v2 = (float)READ_IMAGE_3D(src2,sampler,coord).x; - const float v3 = (float)READ_IMAGE_3D(src3,sampler,coord).x; - const float v4 = (float)READ_IMAGE_3D(src4,sampler,coord).x; - const float v5 = (float)READ_IMAGE_3D(src5,sampler,coord).x; - const float v6 = (float)READ_IMAGE_3D(src6,sampler,coord).x; - const float v7 = (float)READ_IMAGE_3D(src7,sampler,coord).x; - const float v8 = (float)READ_IMAGE_3D(src8,sampler,coord).x; - const float v9 = (float)READ_IMAGE_3D(src9,sampler,coord).x; - const float v10 = (float)READ_IMAGE_3D(src10,sampler,coord).x; - const float res = w0 * v0 + w1 * v1 + w2 * v2 + w3 * v3 + w4 * v4 + w5 * v5 + w6 * v6 + w7 * v7 + w8 * v8 + w9 * v9 + w10 * v10; - - WRITE_IMAGE_3D(dst,coord, CONVERT_DTYPE_OUT(res)); -} - -__kernel void tenengrad_fusion_with_provided_weights_12_images( - DTYPE_IMAGE_OUT_3D dst, const int factor, - DTYPE_IMAGE_IN_3D src0, DTYPE_IMAGE_IN_3D src1, DTYPE_IMAGE_IN_3D src2, DTYPE_IMAGE_IN_3D src3, DTYPE_IMAGE_IN_3D src4, DTYPE_IMAGE_IN_3D src5, - DTYPE_IMAGE_IN_3D src6, DTYPE_IMAGE_IN_3D src7, DTYPE_IMAGE_IN_3D src8, DTYPE_IMAGE_IN_3D src9, DTYPE_IMAGE_IN_3D src10, DTYPE_IMAGE_IN_3D src11, - DTYPE_IMAGE_IN_3D weight0, DTYPE_IMAGE_IN_3D weight1, DTYPE_IMAGE_IN_3D weight2, DTYPE_IMAGE_IN_3D weight3, DTYPE_IMAGE_IN_3D weight4, DTYPE_IMAGE_IN_3D weight5, - DTYPE_IMAGE_IN_3D weight6, DTYPE_IMAGE_IN_3D weight7, DTYPE_IMAGE_IN_3D weight8, DTYPE_IMAGE_IN_3D weight9, DTYPE_IMAGE_IN_3D weight10, DTYPE_IMAGE_IN_3D weight11 -) -{ - const int i = get_global_id(0), j = get_global_id(1), k = get_global_id(2); - const int4 coord = (int4)(i,j,k,0); - - const float4 coord_weight = (float4)((i+0.5f)/factor,(j+0.5f)/factor,k+0.5f,0); - const sampler_t sampler_weight = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_LINEAR; - - float w0 = read_imagef(weight0,sampler_weight,coord_weight).x; - float w1 = read_imagef(weight1,sampler_weight,coord_weight).x; - float w2 = read_imagef(weight2,sampler_weight,coord_weight).x; - float w3 = read_imagef(weight3,sampler_weight,coord_weight).x; - float w4 = read_imagef(weight4,sampler_weight,coord_weight).x; - float w5 = read_imagef(weight5,sampler_weight,coord_weight).x; - float w6 = read_imagef(weight6,sampler_weight,coord_weight).x; - float w7 = read_imagef(weight7,sampler_weight,coord_weight).x; - float w8 = read_imagef(weight8,sampler_weight,coord_weight).x; - float w9 = read_imagef(weight9,sampler_weight,coord_weight).x; - float w10 = read_imagef(weight9,sampler_weight,coord_weight).x; - float w11 = read_imagef(weight9,sampler_weight,coord_weight).x; - - const float wsum = w0 + w1 + w2 + w3 + w4 + w5 + w6 + w7 + w8 + w9 + w10 + w11 + 1e-30f; // add small epsilon to avoid wsum = 0 - w0 /= wsum; - w1 /= wsum; - w2 /= wsum; - w3 /= wsum; - w4 /= wsum; - w5 /= wsum; - w6 /= wsum; - w7 /= wsum; - w8 /= wsum; - w9 /= wsum; - w10 /= wsum; - w11 /= wsum; - - const float v0 = (float)READ_IMAGE_3D(src0,sampler,coord).x; - const float v1 = (float)READ_IMAGE_3D(src1,sampler,coord).x; - const float v2 = (float)READ_IMAGE_3D(src2,sampler,coord).x; - const float v3 = (float)READ_IMAGE_3D(src3,sampler,coord).x; - const float v4 = (float)READ_IMAGE_3D(src4,sampler,coord).x; - const float v5 = (float)READ_IMAGE_3D(src5,sampler,coord).x; - const float v6 = (float)READ_IMAGE_3D(src6,sampler,coord).x; - const float v7 = (float)READ_IMAGE_3D(src7,sampler,coord).x; - const float v8 = (float)READ_IMAGE_3D(src8,sampler,coord).x; - const float v9 = (float)READ_IMAGE_3D(src9,sampler,coord).x; - const float v10 = (float)READ_IMAGE_3D(src10,sampler,coord).x; - const float v11 = (float)READ_IMAGE_3D(src11,sampler,coord).x; - const float res = w0 * v0 + w1 * v1 + w2 * v2 + w3 * v3 + w4 * v4 + w5 * v5 + w6 * v6 + w7 * v7 + w8 * v8 + w9 * v9 + w10 * v10 + w11 * v11; - - WRITE_IMAGE_3D(dst,coord, CONVERT_DTYPE_OUT(res)); -} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/test.cl b/src/main/java/net/haesleinhuepf/clij/kernels/test.cl deleted file mode 100644 index c2f64fa..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/test.cl +++ /dev/null @@ -1,29 +0,0 @@ - -__kernel void set_pixels_to_width_src1_3d( -DTYPE_IMAGE_IN_3D src1, -DTYPE_IMAGE_IN_3D src2, -DTYPE_IMAGE_OUT_3D dst) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - float value = GET_IMAGE_IN_WIDTH(src1); - - WRITE_IMAGE_3D (dst, (int4)(x,y,z,0), CONVERT_DTYPE_OUT(value)); -} - -__kernel void set_pixels_to_width_src2_3d( -DTYPE_IMAGE_IN_3D src1, -DTYPE_IMAGE_IN_3D src2, -DTYPE_IMAGE_OUT_3D dst) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - float value = GET_IMAGE_IN_WIDTH(src2); - - WRITE_IMAGE_3D (dst, (int4)(x,y,z,0), CONVERT_DTYPE_OUT(value)); -} - diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/thresholding.cl b/src/main/java/net/haesleinhuepf/clij/kernels/thresholding.cl deleted file mode 100644 index f05f569..0000000 --- a/src/main/java/net/haesleinhuepf/clij/kernels/thresholding.cl +++ /dev/null @@ -1,43 +0,0 @@ -__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; - -__kernel void apply_local_threshold_3d(DTYPE_IMAGE_IN_3D src, - DTYPE_IMAGE_IN_3D local_threshold, - DTYPE_IMAGE_OUT_3D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - const int z = get_global_id(2); - - const int4 pos = (int4){x,y,z,0}; - - DTYPE_IN inputValue = READ_IMAGE_3D(src, sampler, pos).x; - DTYPE_IN threshold = READ_IMAGE_3D(local_threshold, sampler, pos).x; - - DTYPE_OUT value = 1.0; - if (inputValue < threshold) { - value = 0.0; - } - - WRITE_IMAGE_3D (dst, pos, value); -} - -__kernel void apply_local_threshold_2d(DTYPE_IMAGE_IN_2D src, - DTYPE_IMAGE_IN_2D local_threshold, - DTYPE_IMAGE_OUT_2D dst - ) -{ - const int x = get_global_id(0); - const int y = get_global_id(1); - - const int2 pos = (int2){x,y}; - - DTYPE_IN inputValue = READ_IMAGE_2D(src, sampler, pos).x; - DTYPE_IN threshold = READ_IMAGE_2D(local_threshold, sampler, pos).x; - DTYPE_OUT value = 1.0; - if (inputValue < threshold) { - value = 0.0; - } - - WRITE_IMAGE_2D (dst, pos, value); -} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/touch_matrix_to_mesh_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/touch_matrix_to_mesh_3d_x.cl new file mode 100644 index 0000000..3c825ab --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/touch_matrix_to_mesh_3d_x.cl @@ -0,0 +1,43 @@ +__kernel void touch_matrix_to_mesh_3d( +IMAGE_src_pointlist_TYPE src_pointlist, +IMAGE_src_touch_matrix_TYPE src_touch_matrix, +IMAGE_dst_mesh_TYPE dst_mesh) { + + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int pointIndex = get_global_id(0); + + int2 pos = (int2){pointIndex, 0}; + const float pointAx = READ_src_pointlist_IMAGE(src_pointlist, sampler, pos).x; + pos = (int2){pointIndex, 1}; + const float pointAy = READ_src_pointlist_IMAGE(src_pointlist, sampler, pos).x; + pos = (int2){pointIndex, 2}; + const float pointAz = READ_src_pointlist_IMAGE(src_pointlist, sampler, pos).x; + + int4 pointA = (int4){pointAx, pointAy, pointAz, 0}; + + // so many point candidates are available: + const int num_pointBs = GET_IMAGE_HEIGHT(src_touch_matrix); + for (int pointBIndex = pointIndex + 1; pointBIndex < num_pointBs; pointBIndex++) { + const float touching = READ_src_touch_matrix_IMAGE(src_touch_matrix, sampler, POS_src_touch_matrix_INSTANCE(pointIndex + 1, pointBIndex + 1, 0, 0)).x; + if (touching > 0) { + const float pointBx = READ_src_pointlist_IMAGE(src_pointlist, sampler, POS_src_pointlist_INSTANCE(pointBIndex, 0, 0, 0)).x; + const float pointBy = READ_src_pointlist_IMAGE(src_pointlist, sampler, POS_src_pointlist_INSTANCE(pointBIndex, 1, 0, 0)).x; + const float pointBz = READ_src_pointlist_IMAGE(src_pointlist, sampler, POS_src_pointlist_INSTANCE(pointBIndex, 2, 0, 0)).x; + + // draw line from A to B + float distanceX = pow(pointAx - pointBx, (float)2.0); + float distanceY = pow(pointAy - pointBy, (float)2.0); + float distanceZ = pow(pointAz - pointBz, (float)2.0); + + float distance = sqrt(distanceX + distanceY + distanceZ); + for (float d = 0; d < distance; d = d + 0.5) { + POS_dst_mesh_TYPE tPos = POS_dst_mesh_INSTANCE(pointAx + (pointBx - pointAx) * d / distance, + pointAy + (pointBy - pointAy) * d / distance, + pointAz + (pointBz - pointAz) * d / distance, + 0); + WRITE_dst_mesh_IMAGE(dst_mesh, tPos, CONVERT_dst_mesh_PIXEL_TYPE(touching)); + } + } + } +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/transpose_xy_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/transpose_xy_3d_x.cl new file mode 100644 index 0000000..2fd690a --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/transpose_xy_3d_x.cl @@ -0,0 +1,18 @@ +__kernel void transpose_xy_3d ( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const sampler_t intsampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const POS_src_TYPE spos = POS_src_INSTANCE(y, x, z,0); + const POS_dst_TYPE tpos = POS_dst_INSTANCE(x, y, z,0); + + float value = READ_src_IMAGE(src, intsampler, spos).x; + + WRITE_dst_IMAGE (dst, tpos, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/transpose_xz_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/transpose_xz_3d_x.cl new file mode 100644 index 0000000..1b19c15 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/transpose_xz_3d_x.cl @@ -0,0 +1,19 @@ + +__kernel void transpose_xz_3d ( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const sampler_t intsampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const POS_src_TYPE spos = POS_src_INSTANCE(z, y, x,0); + const POS_dst_TYPE tpos = POS_dst_INSTANCE(x, y, z,0); + + float value = READ_src_IMAGE(src, intsampler, spos).x; + + WRITE_dst_IMAGE (dst, tpos, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/transpose_yz_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/transpose_yz_3d_x.cl new file mode 100644 index 0000000..dc4b0d2 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/transpose_yz_3d_x.cl @@ -0,0 +1,18 @@ +__kernel void transpose_yz_3d ( + IMAGE_src_TYPE src, + IMAGE_dst_TYPE dst +) +{ + const sampler_t intsampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const POS_src_TYPE spos = POS_src_INSTANCE(x, z, y,0); + const POS_dst_TYPE tpos = POS_dst_INSTANCE(x, y, z,0); + + float value = READ_src_IMAGE(src, intsampler, spos).x; + + WRITE_dst_IMAGE (dst, tpos, CONVERT_dst_PIXEL_TYPE(value)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/undefined_to_zero_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/undefined_to_zero_x.cl new file mode 100644 index 0000000..73b3b16 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/undefined_to_zero_x.cl @@ -0,0 +1,18 @@ + +__kernel void undefined_to_zero( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + float value = READ_src_IMAGE(src,sampler, POS_src_INSTANCE(x, y, z,0)).x; + if (isnan(value) || isinf(value)) { + value = 0; + } + + WRITE_dst_IMAGE(dst, POS_dst_INSTANCE(x, y, z,0), CONVERT_dst_PIXEL_TYPE(value)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/variance_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/variance_2d_x.cl new file mode 100644 index 0000000..ec57f37 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/variance_2d_x.cl @@ -0,0 +1,18 @@ + +__kernel void masked_squared_sum_2d_2d( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + IMAGE_src_mask_TYPE src_mask, + float mean_intensity +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + float sum = 0; + if (READ_src_mask_IMAGE(src_mask,sampler,(int2)(x,y)).x > 0) { + float value = READ_src_IMAGE(src,sampler,(int2)(x,y)).x; + sum = pow(value - mean_intensity, 2); + } + WRITE_dst_IMAGE(dst,(int2)(x,y), CONVERT_dst_PIXEL_TYPE(sum)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/variance_masked_projection_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/variance_masked_projection_x.cl new file mode 100644 index 0000000..894e897 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/variance_masked_projection_x.cl @@ -0,0 +1,21 @@ + +__kernel void masked_squared_sum_project( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + IMAGE_src_mask_TYPE src_mask, + float mean_intensity +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + float sum = 0; + for(int z = 0; z < GET_IMAGE_DEPTH(src); z++) + { + if (READ_src_mask_IMAGE(src_mask,sampler,POS_src_mask_INSTANCE(x,y,z,0)).x > 0) { + float value = READ_src_IMAGE(src,sampler,POS_src_INSTANCE(x,y,z,0)).x; + sum = sum + pow(value - mean_intensity, 2); + } + } + WRITE_dst_IMAGE(dst,POS_dst_INSTANCE(x,y,0,0), CONVERT_dst_PIXEL_TYPE(sum)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/variance_projection_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/variance_projection_x.cl new file mode 100644 index 0000000..c553267 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/variance_projection_x.cl @@ -0,0 +1,17 @@ +__kernel void squared_sum_project( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src, + float mean_intensity +) { + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + float sum = 0; + for(int z = 0; z < GET_IMAGE_DEPTH(src); z++) + { + float value = READ_src_IMAGE(src,sampler,POS_src_INSTANCE(x,y,z,0)).x; + sum = sum + pow(value - mean_intensity, 2); + } + WRITE_dst_IMAGE(dst,POS_dst_INSTANCE(x,y,0,0), CONVERT_sum_PIXEL_TYPE(sum)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/watershed_binarize_labelmap_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/watershed_binarize_labelmap_2d_x.cl new file mode 100644 index 0000000..652a2e1 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/watershed_binarize_labelmap_2d_x.cl @@ -0,0 +1,37 @@ +__kernel void watershed_binarize_labelmap_2d +( + IMAGE_src_labelmap_TYPE src_labelmap, + IMAGE_dst_binary_TYPE dst_binary +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float currentlabel = READ_src_labelmap_IMAGE(src_labelmap, sampler, pos).x; + + if (currentlabel > 0) { + for (int ax = -1; ax <= 1; ax++) { + for (int ay = -1; ay <= 1; ay++) { + if (ax != 0 || ay != 0) { + float otherlabel = READ_src_labelmap_IMAGE(src_labelmap, sampler, (pos + (int2){ax, ay})).x; + if (otherlabel < currentlabel) { + currentlabel = 0; + break; + } + } + } + if (currentlabel < 1) { + break; + } + } + } + if (currentlabel > 0) { + currentlabel = 1; + } + + WRITE_dst_binary_IMAGE (dst_binary, pos, CONVERT_dst_binary_PIXEL_TYPE(currentlabel)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/watershed_binarize_labelmap_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/watershed_binarize_labelmap_3d_x.cl new file mode 100644 index 0000000..a77ccd0 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/watershed_binarize_labelmap_3d_x.cl @@ -0,0 +1,40 @@ +__kernel void watershed_binarize_labelmap_3d +( + IMAGE_src_labelmap_TYPE src_labelmap, + IMAGE_dst_binary_TYPE dst_binary +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){ x, y, z, 0 }; + + float currentlabel = READ_src_labelmap_IMAGE(src_labelmap, sampler, pos).x; + + if (currentlabel > 0) { + for (int ax = -1; ax <= 1; ax++) { + for (int ay = -1; ay <= 1; ay++) { + for (int az = -1; az <= 1; az++) { + if (ax != 0 || ay != 0 || az != 0) { + float otherlabel = READ_src_labelmap_IMAGE(src_labelmap, sampler, (pos + (int4){ax, ay, az, 0})).x; + if (otherlabel < currentlabel) { + currentlabel = 0; + break; + } + } + } + } + if (currentlabel < 1) { + break; + } + } + } + if (currentlabel > 0) { + currentlabel = 1; + } + + WRITE_dst_binary_IMAGE (dst_binary, pos, CONVERT_dst_binary_PIXEL_TYPE(currentlabel)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/watershed_detect_maxima_region_box_2d.cl b/src/main/java/net/haesleinhuepf/clij/kernels/watershed_detect_maxima_region_box_2d.cl new file mode 100644 index 0000000..2863e59 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/watershed_detect_maxima_region_box_2d.cl @@ -0,0 +1,36 @@ +__kernel void watershed_detect_maxima_region_box_2d( + DTYPE_IMAGE_IN_2D src, + DTYPE_IMAGE_OUT_2D dst +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + int2 pos = {get_global_id(0), get_global_id(1)}; + float centerValue = READ_IMAGE_2D(src, sampler, pos).x; + float result = 0; + + if (centerValue > 0) { + result = 1; + + int radius = 1; + for(int x = -radius; x < radius + 1; x++) + { + for(int y = -radius; y < radius + 1; y++) + { + if (x != y || y != 0) { + const int2 localPos = pos + (int2){ x, y}; + + float value = READ_IMAGE_2D(src, sampler, localPos).x; + if (value - centerValue > 0) { + result = 0; + break; + } + } + } + if (result < 1) { + break; + } + } + } + WRITE_IMAGE_2D(dst, pos, CONVERT_DTYPE_OUT(result)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/watershed_detect_maxima_region_box_3d.cl b/src/main/java/net/haesleinhuepf/clij/kernels/watershed_detect_maxima_region_box_3d.cl new file mode 100644 index 0000000..fdfb40e --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/watershed_detect_maxima_region_box_3d.cl @@ -0,0 +1,39 @@ +__kernel void watershed_detect_maxima_region_box_3d( + DTYPE_IMAGE_IN_3D src, + DTYPE_IMAGE_OUT_3D dst +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + int4 pos = {get_global_id(0), get_global_id(1), get_global_id(2), 0}; + float centerValue = READ_IMAGE_3D(src, sampler, pos).x; + float result = 0; + + if (centerValue > 0) { + result = 1; + + int radius = 1; + for(int x = -radius; x < radius + 1; x++) + { + for(int y = -radius; y < radius + 1; y++) + { + for(int z = -radius; z < radius + 1; z++) + { + if (x != y || y != 0) { + const int4 localPos = pos + (int4){ x, y, z, 0}; + + float value = READ_IMAGE_3D(src, sampler, localPos).x; + if (value - centerValue > 0) { + result = 0; + break; + } + } + } + } + if (result < 1) { + break; + } + } + } + WRITE_IMAGE_3D(dst, pos, CONVERT_DTYPE_OUT(result)); +} \ No newline at end of file diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/watershed_eliminate_wrong_maxima_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/watershed_eliminate_wrong_maxima_2d_x.cl new file mode 100644 index 0000000..c1daaab --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/watershed_eliminate_wrong_maxima_2d_x.cl @@ -0,0 +1,40 @@ +__kernel void watershed_eliminate_wrong_maxima_2d +( + IMAGE_src_maxima_TYPE src_maxima, + IMAGE_src_distancemap_TYPE src_distancemap, + IMAGE_dst_maxima_TYPE dst_maxima, + IMAGE_flag_dst_TYPE flag_dst +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float was_maximum = READ_src_maxima_IMAGE(src_maxima, sampler, pos).x; + float value = READ_src_distancemap_IMAGE(src_distancemap, sampler, pos).x; + float is_maximum = was_maximum; + + if (is_maximum > 0) { + for (int ax = -1; ax <= 1; ax++) { + for (int ay = -1; ay <= 1; ay++) { + if (ax != 0 || ay != 0) { + float other_is_maximum = READ_src_maxima_IMAGE(src_maxima, sampler, (pos + (int2){ax, ay})).x; + float other_value = READ_src_distancemap_IMAGE(src_distancemap, sampler, (pos + (int2){ax, ay})).x; + if (other_value > 0 && (! (fabs(other_value - value) > 0))) { + if (other_is_maximum < 1) { + is_maximum = 0; + } + } + } + } + } + + if (fabs(((float)is_maximum - was_maximum)) > 0) { + WRITE_flag_dst_IMAGE(flag_dst,(int4)(0,0,0,0),1); + } + } + WRITE_dst_maxima_IMAGE (dst_maxima, pos, CONVERT_dst_maxima_PIXEL_TYPE(is_maximum)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/watershed_eliminate_wrong_maxima_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/watershed_eliminate_wrong_maxima_3d_x.cl new file mode 100644 index 0000000..7fcccc9 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/watershed_eliminate_wrong_maxima_3d_x.cl @@ -0,0 +1,43 @@ +__kernel void watershed_eliminate_wrong_maxima_3d +( + IMAGE_src_maxima_TYPE src_maxima, + IMAGE_src_distancemap_TYPE src_distancemap, + IMAGE_dst_maxima_TYPE dst_maxima, + IMAGE_flag_dst_TYPE flag_dst +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y,z,0}; + + float was_maximum = READ_src_maxima_IMAGE(src_maxima, sampler, pos).x; + float value = READ_src_distancemap_IMAGE(src_distancemap, sampler, pos).x; + float is_maximum = was_maximum; + + if (is_maximum > 0) { + for (int ax = -1; ax <= 1; ax++) { + for (int ay = -1; ay <= 1; ay++) { + for (int az = -1; az <= 1; az++) { + if (ax != 0 || ay != 0) { + float other_is_maximum = READ_src_maxima_IMAGE(src_maxima, sampler, (pos + (int4){ax, ay, az, 0})).x; + float other_value = READ_src_distancemap_IMAGE(src_distancemap, sampler, (pos + (int4){ax, ay, az, 0})).x; + if (other_value > 0 && (! (fabs(other_value - value) > 0))) { + if (other_is_maximum < 1) { + is_maximum = 0; + } + } + } + } + } + } + + if (fabs(((float)is_maximum - was_maximum)) > 0) { + WRITE_flag_dst_IMAGE(flag_dst,(int4)(0,0,0,0),1); + } + } + WRITE_dst_maxima_IMAGE (dst_maxima, pos, CONVERT_dst_maxima_PIXEL_TYPE(is_maximum)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/watershed_local_maximum_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/watershed_local_maximum_2d_x.cl new file mode 100644 index 0000000..79bb4a4 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/watershed_local_maximum_2d_x.cl @@ -0,0 +1,43 @@ +__kernel void watershed_local_maximum_2d +( + IMAGE_src_labelmap_TYPE src_labelmap, + IMAGE_src_distancemap_TYPE src_distancemap, + IMAGE_dst_labelmap_TYPE dst_labelmap, + IMAGE_dst_distancemap_TYPE dst_distancemap, + IMAGE_flag_dst_TYPE flag_dst +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + + const int2 pos = (int2){x,y}; + + float currentlabel = READ_src_labelmap_IMAGE(src_labelmap, sampler, pos).x; + float currentdistance = READ_src_distancemap_IMAGE(src_distancemap, sampler, pos).x; + + float bestlabel = currentlabel; + float bestdistance = currentdistance; + + if (currentdistance > 0 && currentlabel < 1) { + for (int ax = -1; ax <= 1; ax++) { + for (int ay = -1; ay <= 1; ay++) { + float distance = READ_src_distancemap_IMAGE(src_distancemap, sampler, (pos + (int2){ax, ay})).x; + if (distance > 0) { + if (distance > bestdistance) { + float label = READ_src_labelmap_IMAGE(src_labelmap, sampler, (pos + (int2){ax, ay})).x; + bestdistance = distance; + bestlabel = label; + } + } + } + } + + if (fabs(((float)bestlabel - currentlabel)) > 0) { + WRITE_flag_dst_IMAGE(flag_dst,(int4)(0,0,0,0),1); + } + } + WRITE_dst_labelmap_IMAGE (dst_labelmap, pos, CONVERT_dst_labelmap_PIXEL_TYPE(bestlabel)); + WRITE_dst_distancemap_IMAGE (dst_distancemap, pos, CONVERT_dst_distancemap_PIXEL_TYPE(bestdistance)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/watershed_local_maximum_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/watershed_local_maximum_3d_x.cl new file mode 100644 index 0000000..7336e67 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/watershed_local_maximum_3d_x.cl @@ -0,0 +1,46 @@ +__kernel void watershed_local_maximum_3d +( + IMAGE_src_labelmap_TYPE src_labelmap, + IMAGE_src_distancemap_TYPE src_distancemap, + IMAGE_dst_labelmap_TYPE dst_labelmap, + IMAGE_dst_distancemap_TYPE dst_distancemap, + IMAGE_flag_dst_TYPE flag_dst +) +{ + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + + const int x = get_global_id(0); + const int y = get_global_id(1); + const int z = get_global_id(2); + + const int4 pos = (int4){x,y, z, 0}; + + float currentlabel = READ_src_labelmap_IMAGE(src_labelmap, sampler, pos).x; + float currentdistance = READ_src_distancemap_IMAGE(src_distancemap, sampler, pos).x; + + float bestlabel = currentlabel; + float bestdistance = currentdistance; + + if (currentdistance > 0) { + for (int ax = -1; ax <= 1; ax++) { + for (int ay = -1; ay <= 1; ay++) { + for (int az = -1; az <= 1; az++) { + float distance = READ_src_distancemap_IMAGE(src_distancemap, sampler, (pos + (int4){ax, ay, az, 0})).x; + if (distance > 0) { + if (distance > bestdistance) { + float label = READ_src_labelmap_IMAGE(src_labelmap, sampler, (pos + (int4){ax, ay, az, 0})).x; + bestdistance = distance; + bestlabel = label; + } + } + } + } + } + + if (fabs(((float)bestlabel - currentlabel)) > 0) { + WRITE_flag_dst_IMAGE(flag_dst,(int4)(0,0,0,0),1); + } + } + WRITE_dst_labelmap_IMAGE (dst_labelmap, pos, CONVERT_dst_labelmap_PIXEL_TYPE(bestlabel)); + WRITE_dst_distancemap_IMAGE (dst_distancemap, pos, CONVERT_dst_distancemap_PIXEL_TYPE(bestdistance)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/write_values_to_positions_2d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/write_values_to_positions_2d_x.cl new file mode 100644 index 0000000..efa63b7 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/write_values_to_positions_2d_x.cl @@ -0,0 +1,18 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void write_values_to_positions_2d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) +{ + const int i = get_global_id(0); + const int2 sourcePos = (int2)(i,0); + + const int x = READ_src_IMAGE(src,sampler, (sourcePos + (int2){0, 0})).x; + const int y = READ_src_IMAGE(src,sampler, (sourcePos + (int2){0, 1})).x; + const float v = READ_src_IMAGE(src,sampler, (sourcePos + (int2){0, 2})).x; + + const int2 coord = (int2){x, y}; + WRITE_dst_IMAGE(dst,coord, CONVERT_dst_PIXEL_TYPE(v)); +} diff --git a/src/main/java/net/haesleinhuepf/clij/kernels/write_values_to_positions_3d_x.cl b/src/main/java/net/haesleinhuepf/clij/kernels/write_values_to_positions_3d_x.cl new file mode 100644 index 0000000..6748a93 --- /dev/null +++ b/src/main/java/net/haesleinhuepf/clij/kernels/write_values_to_positions_3d_x.cl @@ -0,0 +1,19 @@ +__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__kernel void write_values_to_positions_3d +( + IMAGE_dst_TYPE dst, + IMAGE_src_TYPE src +) +{ + const int i = get_global_id(0); + const int2 sourcePos = (int2)(i,0); + + const int x = READ_src_IMAGE(src,sampler, (sourcePos + (int2){0, 0})).x; + const int y = READ_src_IMAGE(src,sampler, (sourcePos + (int2){0, 1})).x; + const int z = READ_src_IMAGE(src,sampler, (sourcePos + (int2){0, 2})).x; + const float v = READ_src_IMAGE(src,sampler, (sourcePos + (int2){0, 3})).x; + + const int4 coord = (int4){x, y, z, 0}; + WRITE_dst_IMAGE(dst,coord, CONVERT_dst_PIXEL_TYPE(v)); +}