40
40
import java .util .concurrent .ExecutionException ;
41
41
import java .util .concurrent .ExecutorService ;
42
42
import java .util .concurrent .Future ;
43
+ import java .util .function .BiPredicate ;
44
+ import java .util .function .Consumer ;
43
45
44
- import net .imglib2 .Cursor ;
45
- import net .imglib2 .FinalInterval ;
46
- import net .imglib2 .RandomAccessible ;
47
- import net .imglib2 .RandomAccessibleInterval ;
46
+ import net .imglib2 .*;
47
+ import net .imglib2 .algorithm .neighborhood .Shape ;
48
48
import net .imglib2 .loops .LoopBuilder ;
49
49
import net .imglib2 .type .numeric .NumericType ;
50
50
import net .imglib2 .util .Intervals ;
@@ -88,6 +88,32 @@ public static < T extends NumericType< T > > void gradientCentralDifference2( fi
88
88
}
89
89
}
90
90
91
+ /**
92
+ * Compute the partial derivative (central difference approximation) of source
93
+ * in a particular dimension:
94
+ * {@code d_f( x ) = ( f( x + e ) - f( x - e ) ) / 2},
95
+ * where {@code e} is the unit vector along that dimension.
96
+ * <p>
97
+ * This method differs from
98
+ * {@link #gradientCentralDifference2(RandomAccessible, RandomAccessibleInterval, int)}
99
+ * only in that its parameter order is tailored to an Op. The output comes
100
+ * last, and the primary input (the input image) comes first.
101
+ * </p>
102
+ *
103
+ * @implNote op name='gradientCentralDifference2', type='org.scijava.function.Computers.Arity2'
104
+ * @param source
105
+ * source image, has to provide valid data in the interval of the
106
+ * gradient image plus a one pixel border in dimension.
107
+ * @param dimension
108
+ * along which dimension the partial derivatives are computed
109
+ * @param gradient
110
+ * output image
111
+ */
112
+ public static < T extends NumericType < T > > void gradientCentralDifference2 ( final RandomAccessible < T > source , final int dimension , final RandomAccessibleInterval < T > gradient )
113
+ {
114
+ gradientCentralDifference2 ( source , gradient , dimension );
115
+ }
116
+
91
117
// parallel version...
92
118
/**
93
119
* Compute the partial derivative (central difference approximation) of source
@@ -163,6 +189,42 @@ public static < T extends NumericType< T > > void gradientCentralDifferenceParal
163
189
f .get ();
164
190
}
165
191
192
+ /**
193
+ * Compute the partial derivative (central difference approximation) of source
194
+ * in a particular dimension:
195
+ * {@code d_f( x ) = ( f( x + e ) - f( x - e ) ) / 2},
196
+ * where {@code e} is the unit vector along that dimension.
197
+ * <p>
198
+ * This method differs from
199
+ * {@link #gradientCentralDifferenceParallel(RandomAccessible, RandomAccessibleInterval, int, int, ExecutorService)}
200
+ * only in that its parameter order is tailored to an Op. The output comes
201
+ * last, and the primary input (the input image) comes first.
202
+ * </p>
203
+ *
204
+ * @implNote op name='gradientCentralDifferenceParallel', type='org.scijava.function.Computers.Arity4'
205
+ * @param source
206
+ * source image, has to provide valid data in the interval of the
207
+ * gradient image plus a one pixel border in dimension.
208
+ * @param dimension
209
+ * along which dimension the partial derivatives are computed
210
+ * @param nTasks
211
+ * Number of tasks for gradient computation.
212
+ * @param es
213
+ * {@link ExecutorService} providing workers for gradient
214
+ * computation. Service is managed (created, shutdown) by caller.
215
+ * @param gradient
216
+ * output image
217
+ */
218
+ public static < T extends NumericType < T > > void gradientCentralDifferenceParallel (
219
+ final RandomAccessible < T > source ,
220
+ final int dimension ,
221
+ final int nTasks ,
222
+ final ExecutorService es ,
223
+ final RandomAccessibleInterval < T > gradient ) throws InterruptedException , ExecutionException
224
+ {
225
+ gradientCentralDifferenceParallel ( source , gradient , dimension , nTasks , es );
226
+ }
227
+
166
228
// fast version
167
229
/**
168
230
* Compute the partial derivative (central difference approximation) of source
@@ -191,6 +253,33 @@ public static < T extends NumericType< T > > void gradientCentralDifference( fin
191
253
} );
192
254
}
193
255
256
+ /**
257
+ * Compute the partial derivative (central difference approximation) of source
258
+ * in a particular dimension:
259
+ * {@code d_f( x ) = ( f( x + e ) - f( x - e ) ) / 2},
260
+ * where {@code e} is the unit vector along that dimension.
261
+ * <p>
262
+ * This method differs from
263
+ * {@link #gradientCentralDifference(RandomAccessible, RandomAccessibleInterval, int)}
264
+ * only in that its parameter order is tailored to an Op. The output comes
265
+ * last, and the primary input (the input image) comes first.
266
+ * </p>
267
+ *
268
+ * @implNote op name='gradientCentralDifference', type='org.scijava.function.Computers.Arity2'
269
+ * @param source
270
+ * source image, has to provide valid data in the interval of the
271
+ * gradient image plus a one pixel border in dimension.
272
+ * @param dimension
273
+ * along which dimension the partial derivatives are computed
274
+ * @param result
275
+ * output image
276
+ */
277
+ public static < T extends NumericType < T > > void gradientCentralDifference ( final RandomAccessible < T > source ,
278
+ final int dimension , final RandomAccessibleInterval < T > result )
279
+ {
280
+ gradientCentralDifference ( source , result , dimension );
281
+ }
282
+
194
283
/**
195
284
* Compute the backward difference of source in a particular dimension:
196
285
* {@code d_f( x ) = ( f( x ) - f( x - e ) )}
@@ -213,6 +302,29 @@ public static < T extends NumericType< T > > void gradientBackwardDifference( fi
213
302
} );
214
303
}
215
304
305
+ /**
306
+ * Compute the backward difference of source in a particular dimension:
307
+ * {@code d_f( x ) = ( f( x ) - f( x - e ) )}
308
+ * where {@code e} is the unit vector along that dimension
309
+ * <p>
310
+ * This method differs from
311
+ * {@link #gradientBackwardDifference(RandomAccessible, RandomAccessibleInterval, int)}
312
+ * only in that its parameter order is tailored to an Op. The output comes
313
+ * last, and the primary input (the input image) comes first.
314
+ * </p>
315
+ *
316
+ * @implNote op name='gradientBackwardDifference', type='org.scijava.function.Computers.Arity2'
317
+ * @param source source image, has to provide valid data in the interval of
318
+ * the gradient image plus a one pixel border in dimension.
319
+ * @param dimension along which dimension the partial derivatives are computed
320
+ * @param result output image
321
+ */
322
+ public static < T extends NumericType < T > > void gradientBackwardDifference ( final RandomAccessible < T > source ,
323
+ final int dimension , final RandomAccessibleInterval < T > result )
324
+ {
325
+ gradientBackwardDifference ( source , result , dimension );
326
+ }
327
+
216
328
/**
217
329
* Compute the forward difference of source in a particular dimension:
218
330
* {@code d_f( x ) = ( f( x + e ) - f( x ) )}
@@ -234,4 +346,27 @@ public static < T extends NumericType< T > > void gradientForwardDifference( fin
234
346
r .sub ( b );
235
347
} );
236
348
}
349
+
350
+ /**
351
+ * Compute the forward difference of source in a particular dimension:
352
+ * {@code d_f( x ) = ( f( x + e ) - f( x ) )}
353
+ * where {@code e} is the unit vector along that dimension
354
+ * <p>
355
+ * This method differs from
356
+ * {@link #gradientForwardDifference(RandomAccessible, RandomAccessibleInterval, int)}
357
+ * only in that its parameter order is tailored to an Op. The output comes
358
+ * last, and the primary input (the input image) comes first.
359
+ * </p>
360
+ *
361
+ * @implNote op name='gradientForwardDifference', type='org.scijava.function.Computers.Arity2'
362
+ * @param source source image, has to provide valid data in the interval of
363
+ * the gradient image plus a one pixel border in dimension.
364
+ * @param dimension along which dimension the partial derivatives are computed
365
+ * @param result output image
366
+ */
367
+ public static < T extends NumericType < T > > void gradientForwardDifference ( final RandomAccessible < T > source ,
368
+ final int dimension , final RandomAccessibleInterval < T > result )
369
+ {
370
+ gradientForwardDifference ( source , result , dimension );
371
+ }
237
372
}
0 commit comments