2929
3030package net .imagej .ops .filter .hessian ;
3131
32+ import java .util .ArrayList ;
33+ import java .util .List ;
34+
3235import net .imagej .ops .Ops ;
33- import net .imagej .ops .Ops .Filter .Hessian ;
3436import net .imagej .ops .special .chain .RAIs ;
3537import net .imagej .ops .special .computer .UnaryComputerOp ;
36- import net .imagej .ops .special .function .Functions ;
38+ import net .imagej .ops .special .function .AbstractUnaryFunctionOp ;
3739import net .imagej .ops .special .function .UnaryFunctionOp ;
38- import net .imagej .ops .special .hybrid .AbstractUnaryHybridCF ;
39- import net .imglib2 .Dimensions ;
40- import net .imglib2 .FinalDimensions ;
4140import net .imglib2 .RandomAccessibleInterval ;
4241import net .imglib2 .type .numeric .RealType ;
43- import net .imglib2 .util .Util ;
44- import net .imglib2 .view .IntervalView ;
4542import net .imglib2 .view .Views ;
43+ import net .imglib2 .view .composite .CompositeIntervalView ;
44+ import net .imglib2 .view .composite .RealComposite ;
4645
4746import org .scijava .plugin .Plugin ;
4847
5756
5857@ Plugin (type = Ops .Filter .Hessian .class )
5958public class HessianRAI <T extends RealType <T >>
60- extends AbstractUnaryHybridCF <RandomAccessibleInterval <T >, RandomAccessibleInterval <T >> implements Hessian {
59+ extends AbstractUnaryFunctionOp <RandomAccessibleInterval <T >, CompositeIntervalView <T , RealComposite <T >>>
60+ implements Ops .Filter .Hessian {
6161
6262 private UnaryComputerOp <RandomAccessibleInterval <T >, RandomAccessibleInterval <T >>[] derivativeComputers ;
6363
64- @ SuppressWarnings ("rawtypes" )
65- private UnaryFunctionOp <Dimensions , RandomAccessibleInterval > createRAIFromDim ;
66-
6764 private UnaryFunctionOp <RandomAccessibleInterval <T >, RandomAccessibleInterval <T >> createRAIFromRAI ;
6865
6966 @ SuppressWarnings ("unchecked" )
7067 @ Override
7168 public void initialize () {
72- createRAIFromDim = Functions .unary (ops (), Ops .Create .Img .class , RandomAccessibleInterval .class ,
73- Dimensions .class , Util .getTypeFromInterval (in ()).createVariable ());
7469 createRAIFromRAI = RAIs .function (ops (), Ops .Create .Img .class , in ());
7570
7671 derivativeComputers = new UnaryComputerOp [in ().numDimensions ()];
@@ -80,29 +75,19 @@ public void initialize() {
8075 }
8176
8277 @ Override
83- public void compute1 (RandomAccessibleInterval <T > input , RandomAccessibleInterval <T > output ) {
84- int iteration = 0 ;
85-
86- for (int i = 0 ; i < input .numDimensions (); i ++) {
78+ public CompositeIntervalView <T , RealComposite <T >> compute1 (RandomAccessibleInterval <T > input ) {
79+ List <RandomAccessibleInterval <T >> derivatives = new ArrayList <>();
80+ for (int i = 0 ; i < derivativeComputers .length ; i ++) {
8781 RandomAccessibleInterval <T > derivative = createRAIFromRAI .compute1 (input );
8882 derivativeComputers [i ].compute1 (input , derivative );
89- for (int j = 0 ; j < input . numDimensions () ; j ++) {
90- IntervalView <T > out = Views . hyperSlice ( Views . hyperSlice ( output , 3 , 0 ), 2 , iteration );
83+ for (int j = 0 ; j < derivativeComputers . length ; j ++) {
84+ RandomAccessibleInterval <T > out = createRAIFromRAI . compute1 ( input );
9185 derivativeComputers [j ].compute1 (derivative , out );
92- iteration ++ ;
86+ derivatives . add ( out ) ;
9387 }
9488 }
89+ RandomAccessibleInterval <T > stackedDerivatives = Views .stack (derivatives );
90+ return Views .collapseReal (stackedDerivatives );
9591 }
9692
97- @ SuppressWarnings ("unchecked" )
98- @ Override
99- public RandomAccessibleInterval <T > createOutput (RandomAccessibleInterval <T > input ) {
100- long [] dims = new long [input .numDimensions () + 2 ];
101- for (int i = 0 ; i < dims .length - 1 ; i ++) {
102- dims [i ] = input .dimension (i );
103- }
104- dims [dims .length - 1 ] = input .numDimensions () * input .numDimensions ();
105- Dimensions dim = FinalDimensions .wrap (dims );
106- return createRAIFromDim .compute1 (dim );
107- }
10893}
0 commit comments