5353import net .imglib2 .util .Intervals ;
5454import net .imglib2 .view .ExtendedRandomAccessibleInterval ;
5555import net .imglib2 .view .Views ;
56-
5756import org .scijava .function .Computers ;
5857import org .scijava .function .Functions ;
58+ import org .scijava .ops .spi .Nullable ;
5959import org .scijava .ops .spi .OpDependency ;
6060
6161/**
9292public class Watershed <T extends RealType <T >, B extends BooleanType <B >> implements
9393 Computers .Arity4 <RandomAccessibleInterval <T >, Boolean , Boolean , RandomAccessibleInterval <B >, ImgLabeling <Integer , IntType >> {
9494
95- // @SuppressWarnings("rawtypes")
96- // private UnaryFunctionOp<Interval, ImgLabeling> createOp;
97-
9895 @ OpDependency (name = "create.img" )
9996 BiFunction <Dimensions , IntType , RandomAccessibleInterval <IntType >> imgCreator ;
10097
@@ -110,16 +107,20 @@ public class Watershed<T extends RealType<T>, B extends BooleanType<B>> implemen
110107 /**
111108 * TODO
112109 *
113- * @param input
110+ * @param in
114111 * @param useEightConnectivity
115112 * @param drawWatersheds
116113 * @param mask
117114 * @param outputLabeling
118115 */
119116 @ Override
120- public void compute (final RandomAccessibleInterval <T > in , final Boolean useEightConnectivity ,
121- final Boolean drawWatersheds , final RandomAccessibleInterval <B > mask ,
122- final ImgLabeling <Integer , IntType > out ) {
117+ public void compute (
118+ final RandomAccessibleInterval <T > in , //
119+ final Boolean useEightConnectivity , //
120+ final Boolean drawWatersheds , //
121+ @ Nullable final RandomAccessibleInterval <B > mask , //
122+ final ImgLabeling <Integer , IntType > outputLabeling //
123+ ) {
123124 final RandomAccess <T > raIn = in .randomAccess ();
124125
125126 RandomAccess <B > raMask = null ;
@@ -327,7 +328,7 @@ public void compute(final RandomAccessibleInterval<T> in, final Boolean useEight
327328 /*
328329 * Draw output and remove as the case may be the watersheds
329330 */
330- final Cursor <LabelingType <Integer >> cursorOut = out .cursor ();
331+ final Cursor <LabelingType <Integer >> cursorOut = outputLabeling .cursor ();
331332 while (cursorOut .hasNext ()) {
332333 cursorOut .fwd ();
333334 boolean maskValue = true ;
@@ -369,9 +370,9 @@ public void compute(final RandomAccessibleInterval<T> in, final Boolean useEight
369370 /*
370371 * Merge already present labels before calculation of watershed
371372 */
372- if (out != null ) {
373- final Cursor <LabelingType <Integer >> cursor = out .cursor ();
374- final RandomAccess <LabelingType <Integer >> raOut = out .randomAccess ();
373+ if (outputLabeling != null ) {
374+ final Cursor <LabelingType <Integer >> cursor = outputLabeling .cursor ();
375+ final RandomAccess <LabelingType <Integer >> raOut = outputLabeling .randomAccess ();
375376 while (cursor .hasNext ()) {
376377 cursor .fwd ();
377378 raOut .setPosition (cursor );
@@ -384,84 +385,3 @@ public void compute(final RandomAccessibleInterval<T> in, final Boolean useEight
384385
385386}
386387
387- /**
388- *@implNote op names='image.watershed'
389- */
390- class WatershedMaskless <T extends RealType <T >, B extends BooleanType <B >> implements
391- Computers .Arity3 <RandomAccessibleInterval <T >, Boolean , Boolean , ImgLabeling <Integer , IntType >> {
392-
393- @ OpDependency (name = "image.watershed" )
394- private Computers .Arity4 <RandomAccessibleInterval <T >, Boolean , Boolean , RandomAccessibleInterval <B >, ImgLabeling <Integer , IntType >> watershedOp ;
395-
396- /**
397- * TODO
398- *
399- * @param input
400- * @param useEightConnectivity
401- * @param drawWatersheds
402- * @param outputLabeling
403- */
404- @ Override
405- public void compute (RandomAccessibleInterval <T > in , Boolean useEightConnectivity , Boolean drawWatersheds ,
406- ImgLabeling <Integer , IntType > outputLabeling ) {
407- watershedOp .compute (in , useEightConnectivity , drawWatersheds , null , outputLabeling );
408-
409- }
410- }
411-
412- /**
413- *@implNote op names='image.watershed'
414- */
415- class WatershedFunction <T extends RealType <T >, B extends BooleanType <B >>
416- implements Functions .Arity4 <RandomAccessibleInterval <T >, Boolean , Boolean , RandomAccessibleInterval <B >, ImgLabeling <Integer , IntType >> {
417-
418- @ OpDependency (name = "image.watershed" )
419- private Computers .Arity4 <RandomAccessibleInterval <T >, Boolean , Boolean , RandomAccessibleInterval <B >, ImgLabeling <Integer , IntType >> watershedOp ;
420- @ OpDependency (name = "create.imgLabeling" )
421- private BiFunction <Dimensions , IntType , ImgLabeling <Integer , IntType >> labelingCreator ;
422-
423- /**
424- * TODO
425- *
426- * @param input
427- * @param useEightConnectivity
428- * @param drawWatersheds
429- * @param mask
430- * @return the outputLabeling
431- */
432- @ Override
433- public ImgLabeling <Integer , IntType > apply (RandomAccessibleInterval <T > in , Boolean useEightConnectivity ,
434- Boolean drawWatersheds , RandomAccessibleInterval <B > mask ) {
435- ImgLabeling <Integer , IntType > outputLabeling = labelingCreator .apply (in , new IntType ());
436- watershedOp .compute (in , useEightConnectivity , drawWatersheds , mask , outputLabeling );
437- return outputLabeling ;
438- }
439- }
440-
441- /**
442- *@implNote op names='image.watershed'
443- */
444- class WatershedFunctionMaskless <T extends RealType <T >, B extends BooleanType <B >>
445- implements Functions .Arity3 <RandomAccessibleInterval <T >, Boolean , Boolean , ImgLabeling <Integer , IntType >> {
446-
447- @ OpDependency (name = "image.watershed" )
448- private Computers .Arity3 <RandomAccessibleInterval <T >, Boolean , Boolean , ImgLabeling <Integer , IntType >> watershedOp ;
449- @ OpDependency (name = "create.imgLabeling" )
450- private BiFunction <Dimensions , IntType , ImgLabeling <Integer , IntType >> labelingCreator ;
451-
452- /**
453- * TODO
454- *
455- * @param input
456- * @param useEightConnectivity
457- * @param drawWatersheds
458- * @return the outputLabeling
459- */
460- @ Override
461- public ImgLabeling <Integer , IntType > apply (RandomAccessibleInterval <T > in , Boolean useEightConnectivity ,
462- Boolean drawWatersheds ) {
463- ImgLabeling <Integer , IntType > outputLabeling = labelingCreator .apply (in , new IntType ());
464- watershedOp .compute (in , useEightConnectivity , drawWatersheds , outputLabeling );
465- return outputLabeling ;
466- }
467- }
0 commit comments