Skip to content

Commit 5989f28

Browse files
committed
Try to shore up ParameterConversion variable names
1 parent 76c91a8 commit 5989f28

1 file changed

Lines changed: 27 additions & 27 deletions

File tree

docs/ops/doc/ParameterConversion.rst

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ Suppose we have a ``Function`` Op that inherently operates on ``RandomAccessible
2525
/**
2626
* Convolves an image with a kernel, returning the output in a new object
2727
*
28-
* @param input the input data
28+
* @param image the input image
2929
* @param kernel the kernel
30-
* @return the convolution of {@code input} and {@code kernel}
30+
* @return the convolution of {@code image} and {@code kernel}
3131
* @implNote op names="filter.convolve"
3232
*/
3333
public static RandomAccessibleInterval<DoubleType> convolveNaive(
34-
final RandomAccessibleInterval<DoubleType> input,
34+
final RandomAccessibleInterval<DoubleType> image,
3535
final RandomAccessibleInterval<DoubleType> kernel
3636
) {
3737
// convolve convolve convolve //
@@ -42,21 +42,21 @@ Suppose a user wants to use this Op with a small, fixed kernel, which for ease i
4242

4343
.. code-block:: java
4444
45-
Img<DoubleType> in = ...
45+
Img<DoubleType> image = ...
4646
// 3x3 averaging kernel
4747
double[][] kernel = { //
4848
{ 1/9d, 1/9d, 1/9d}, //
4949
{ 1/9d, 1/9d, 1/9d}, //
5050
{ 1/9d, 1/9d, 1/9d} //
5151
};
5252
// transform double[][] into a RandomAccessibleInterval
53-
Img<DoubleType> kernel = ArrayImgs.doubles(data, 3, 3);
54-
var cursor = kernel.cursor();
55-
while(cursor.hasNext())
53+
Img<DoubleType> kernelImg = ArrayImgs.doubles(kernel, 3, 3);
54+
var cursor = kernelImg.cursor();
55+
while (cursor.hasNext())
5656
cursor.next().set(kernel[cursor.getIntPosition(0)][cursor.getIntPosition(1)]);
5757
5858
var result = ops.op("filter.convolve") //
59-
.input(in, kernel) //
59+
.input(image, kernelImg) //
6060
.outType(new Nil<RandomAccessibleInterval<DoubleType>>() {}) //
6161
.apply();
6262
@@ -70,20 +70,20 @@ All ``engine.convert`` Ops are ``Function``\ s that are given user arguments and
7070
.. code-block:: java
7171
7272
/**
73-
* @param input the input data
74-
* @return an image ({@link RandomAccessibleInterval}) whose values are equivalent to {@code input}s
73+
* @param image the input image, as a matrix in 2D array form
74+
* @return an image ({@link RandomAccessibleInterval}) whose values are equivalent to {@code image}'s
7575
* values but converted to {@link DoubleType}s.
7676
* @implNote op names='engine.convert', type=Function
7777
*/
78-
public static RandomAccessibleInterval<DoubleType> arrayToRAI(final double[][] input)
78+
public static RandomAccessibleInterval<DoubleType> arrayToRAI(final double[][] image)
7979
{
8080
// Creates an empty image of doubles
81-
var img = ArrayImgs.doubles(input.length, input[0].length);
81+
var img = ArrayImgs.doubles(image.length, image[0].length);
8282
var ra = img.randomAccess();
8383
// Deep copies the double[][] into the RAI
84-
for(int i = 0; i < input.length; i++) {
85-
for(int j = 0; j < input[0].length; j++) {
86-
ra.setPositionAndGet(i, j).set(input[i][j]);
84+
for(int i = 0; i < image.length; i++) {
85+
for(int j = 0; j < image[0].length; j++) {
86+
ra.setPositionAndGet(i, j).set(image[i][j]);
8787
}
8888
}
8989
return img;
@@ -93,7 +93,7 @@ Using this ``engine.convert`` Op, SciJava Ops can match our ``filter.convolve``
9393

9494
.. code-block:: java
9595
96-
Img<DoubleType> in = ...
96+
Img<DoubleType> image = ...
9797
// 3x3 averaging kernel
9898
double[][] kernel = { //
9999
{ 1/9d, 1/9d, 1/9d}, //
@@ -103,15 +103,15 @@ Using this ``engine.convert`` Op, SciJava Ops can match our ``filter.convolve``
103103
104104
// Ideal case - no need to wrap to Img
105105
var result = ops.op("filter.convolve") //
106-
.input(in, kernel) //
106+
.input(image, kernel) //
107107
.outType(new Nil<RandomAccessibleInterval<DoubleType>>() {}) //
108108
.apply();
109109
110110
At runtime, the Op matcher will invoke the following steps:
111111

112-
* The ``Img<DoubleType> in`` is left alone, as it is already of the type expected by the Op.
112+
* The ``Img<DoubleType> image`` is left alone, as it is already of the type expected by the Op.
113113
* The ``double[][] kernel`` is converted to a ``RandomAccessibleInterval<DoubleType> kernel1`` using our ``engine.convert`` Op.
114-
* The Op convolves ``input`` with ``kernel1``, returning an ``Img<DoubleType> result``.
114+
* The Op convolves ``image`` with ``kernel1``, returning an ``Img<DoubleType> result``.
115115

116116

117117
Adding efficiency
@@ -161,7 +161,7 @@ Now, imagine that the user wished to execute the Op using **only** ``double[][]`
161161

162162
.. code-block:: java
163163
164-
double[][] in = ...
164+
double[][] image = ...
165165
// 3x3 averaging kernel
166166
double[][] kernel = { //
167167
{ 1/9d, 1/9d, 1/9d}, //
@@ -170,7 +170,7 @@ Now, imagine that the user wished to execute the Op using **only** ``double[][]`
170170
};
171171
172172
double[][] result = ops.op("filter.convolve") //
173-
.input(in, kernel) //
173+
.input(image, kernel) //
174174
.outType(double[][].class) //
175175
.apply();
176176
@@ -219,13 +219,13 @@ Finally, consider our ``filter.convolve`` Op example, instead written as a ``Com
219219
/**
220220
* Convolves an image with a kernel, placing the result in the output buffer
221221
*
222-
* @param input the input data
222+
* @param image the input image
223223
* @param kernel the kernel
224224
* @param output the result buffer
225225
* @implNote op names="filter.convolve" type=Computer
226226
*/
227227
public static void convolveNaive(
228-
final RandomAccessibleInterval<DoubleType> input,
228+
final RandomAccessibleInterval<DoubleType> image,
229229
final RandomAccessibleInterval<DoubleType> kernel,
230230
final RandomAccessibleInterval<DoubleType> output
231231
) {
@@ -236,18 +236,18 @@ Suppose that again the user wants to call this Op using *only* ``double[][]``\ s
236236

237237
.. code-block:: java
238238
239-
double[][] in = ...
239+
double[][] image = ...
240240
// 3x3 averaging kernel
241241
double[][] kernel = { //
242242
{ 1/9d, 1/9d, 1/9d}, //
243243
{ 1/9d, 1/9d, 1/9d}, //
244244
{ 1/9d, 1/9d, 1/9d} //
245245
};
246-
double[][] result = new double[in.length][in[0].length];
246+
double[][] result = new double[image.length][image[0].length];
247247
248-
ops.op("filter.convolve").input(in, kernel).output(result).apply();
248+
ops.op("filter.convolve").input(image, kernel).output(result).apply();
249249
250-
We will certainly need the ``engine.convert(in: double[][]) -> RandomAccessibleInterval<DoubleType>`` Op and the ``engine.convert(in: RandomAccessibleInterval<DoubleType>) -> double[][]`` Op we wrote above, however if we follow the same procedure with :ref:`Functions <function-output>`, the ``result`` array they provided will be empty/unmodified. This is because our ``raiToArray` ``engine.convert`` Op we wrote above *creates a new ``double[][]``*. Writing ``engine.convert`` Ops as wrappers is ideal, but in cases like this may not be possible (i.e. we can't create a custom ``double[][]`` implementation).
250+
We will certainly need the ``engine.convert(input: double[][]) -> RandomAccessibleInterval<DoubleType>`` Op and the ``engine.convert(input: RandomAccessibleInterval<DoubleType>) -> double[][]`` Op we wrote above, however if we follow the same procedure with :ref:`Functions <function-output>`, the ``result`` array they provided will be empty/unmodified. This is because our ``raiToArray` ``engine.convert`` Op we wrote above *creates a new ``double[][]``*. Writing ``engine.convert`` Ops as wrappers is ideal, but in cases like this may not be possible (i.e. we can't create a custom ``double[][]`` implementation).
251251

252252
Because SciJava Ops cannot guarantee that ``engine.convert`` Ops wrap user arguments, an additional step is required for parameter conversion with ``Computer`` Ops. This is done by calling an ``engine.copy`` Op to copy the converted output *back into the user's object*. **If you want to enable parameter conversion** on ``Computer``\ s or ``Inplace``\ s, **you must implement** an ``engine.copy`` identity Op for your data type in addition to any ``engine.convert`` Ops. Because there is no way to know how Ops will be implemented (and ``Computer``\s do make a large portion of current Ops) **this is highly recommended**.
253253

0 commit comments

Comments
 (0)