-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathAddImageAndScalar.java
88 lines (74 loc) · 3.16 KB
/
AddImageAndScalar.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package net.haesleinhuepf.clij2.plugins;
import net.haesleinhuepf.clij.clearcl.ClearCLBuffer;
import net.haesleinhuepf.clij.clearcl.interfaces.ClearCLImageInterface;
import net.haesleinhuepf.clij.macro.CLIJMacroPlugin;
import net.haesleinhuepf.clij.macro.CLIJOpenCLProcessor;
import net.haesleinhuepf.clij.macro.documentation.OffersDocumentation;
import net.haesleinhuepf.clij2.AbstractCLIJ2Plugin;
import net.haesleinhuepf.clij2.CLIJ2;
import net.haesleinhuepf.clij2.utilities.HasClassifiedInputOutput;
import net.haesleinhuepf.clij2.utilities.IsCategorized;
import org.scijava.plugin.Plugin;
import java.util.HashMap;
import static net.haesleinhuepf.clij.utilities.CLIJUtilities.assertDifferent;
import static net.haesleinhuepf.clij2.utilities.CLIJUtilities.checkDimensions;
/**
* Author: @haesleinhuepf
* December 2018
*/
@Plugin(type = CLIJMacroPlugin.class, name = "CLIJ2_addImageAndScalar")
public class AddImageAndScalar extends AbstractCLIJ2Plugin implements CLIJMacroPlugin, CLIJOpenCLProcessor, OffersDocumentation, IsCategorized, HasClassifiedInputOutput {
@Override
public String getInputType() {
return "Image";
}
@Override
public String getOutputType() {
return "Image";
}
@Override
public String getCategories() {
return "Math";
}
@Override
public Object[] getDefaultValues() {
return new Object[]{null, null, Double.valueOf(1)};
}
@Override
public boolean executeCL() {
return getCLIJ2().addImageAndScalar((ClearCLBuffer)( args[0]), (ClearCLBuffer)(args[1]), asFloat(args[2]));
}
public static boolean addImageAndScalar(CLIJ2 clij2, ClearCLImageInterface src, ClearCLImageInterface dst, Float scalar) {
assertDifferent(src, dst);
HashMap<String, Object> parameters = new HashMap<>();
parameters.put("src", src);
parameters.put("scalar", scalar);
parameters.put("dst", dst);
if (!checkDimensions(src.getDimension(), src.getDimension(), dst.getDimension())) {
throw new IllegalArgumentException("Error: number of dimensions don't match! (minimumImageAndScalar)");
}
clij2.execute(AddImageAndScalar .class, "add_image_and_scalar_" + src.getDimension() + "d_x.cl", "add_image_and_scalar_" + src.getDimension() + "d", dst.getDimensions(), dst.getDimensions(), parameters);
return true;
}
@Override
public String getParameterHelpText() {
return "Image source, ByRef Image destination, Number scalar";
}
@Override
public String getDescription() {
return "Adds a scalar value s to all pixels x of a given image X.\n\n" +
"<pre>f(x, s) = x + s</pre>\n\n" +
"Parameters\n" +
"----------\n" +
"source : Image\n" +
" The input image where scalare should be added.\n" +
"destination : Image\n" +
" The output image where results are written into.\n" +
"scalar : float\n" +
" The constant number which will be added to all pixels.\n";
}
@Override
public String getAvailableForDimensions() {
return "2D, 3D";
}
}