Skip to content

Commit 3e10881

Browse files
committed
Opify gradient package
1 parent 3d6f6b7 commit 3e10881

File tree

1 file changed

+139
-4
lines changed

1 file changed

+139
-4
lines changed

src/main/java/net/imglib2/algorithm/gradient/PartialDerivative.java

Lines changed: 139 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
import java.util.concurrent.ExecutionException;
4141
import java.util.concurrent.ExecutorService;
4242
import java.util.concurrent.Future;
43+
import java.util.function.BiPredicate;
44+
import java.util.function.Consumer;
4345

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;
4848
import net.imglib2.loops.LoopBuilder;
4949
import net.imglib2.type.numeric.NumericType;
5050
import net.imglib2.util.Intervals;
@@ -88,6 +88,32 @@ public static < T extends NumericType< T > > void gradientCentralDifference2( fi
8888
}
8989
}
9090

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+
91117
// parallel version...
92118
/**
93119
* Compute the partial derivative (central difference approximation) of source
@@ -163,6 +189,42 @@ public static < T extends NumericType< T > > void gradientCentralDifferenceParal
163189
f.get();
164190
}
165191

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+
166228
// fast version
167229
/**
168230
* Compute the partial derivative (central difference approximation) of source
@@ -191,6 +253,33 @@ public static < T extends NumericType< T > > void gradientCentralDifference( fin
191253
} );
192254
}
193255

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+
194283
/**
195284
* Compute the backward difference of source in a particular dimension:
196285
* {@code d_f( x ) = ( f( x ) - f( x - e ) )}
@@ -213,6 +302,29 @@ public static < T extends NumericType< T > > void gradientBackwardDifference( fi
213302
} );
214303
}
215304

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+
216328
/**
217329
* Compute the forward difference of source in a particular dimension:
218330
* {@code d_f( x ) = ( f( x + e ) - f( x ) )}
@@ -234,4 +346,27 @@ public static < T extends NumericType< T > > void gradientForwardDifference( fin
234346
r.sub( b );
235347
} );
236348
}
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+
}
237372
}

0 commit comments

Comments
 (0)