@Override public RealRandomAccessibleRealInterval<BoolType> convert( final RealMaskRealInterval src) { return Masks.toRealRandomAccessibleRealInterval(src); }
@Override public MaskInterval convert(final RandomAccessibleInterval<BoolType> src) { return Masks.toMaskInterval(src); }
@Override public RandomAccessibleInterval<BoolType> convert(final MaskInterval src) { return Masks.toRandomAccessibleInterval(src); }
@Override public RealMaskRealInterval convert( final RealRandomAccessibleRealInterval<BoolType> src) { return Masks.toRealMaskRealInterval(src); }
/** * Determines whether two points describe the same region. * <p> * Two points are equal iff they have the same dimensionality and position. * </p> * * @param pointMask1 * The first point to compare. * @param pointMask2 * The second point to compare. * @return True iff the points describe the same region. */ public static boolean equals( final PointMask pointMask1, final PointMask pointMask2 ) { if ( pointMask1 == null && pointMask2 == null ) return true; if ( pointMask1 == null || pointMask2 == null || !Masks.sameTypesAndDimensions( pointMask1, pointMask2 ) ) return false; return Util.locationsEqual( pointMask1, pointMask2 ); } }
@Override public RandomAccessible<BoolType> convert(final Mask src) { return Masks.toRandomAccessible(src); }
@Override public Mask convert(final RandomAccessible<BoolType> src) { return Masks.toMask(src); }
/** * Creates a {@link MaskInterval} which returns {@code false} for every * location and has empty interval bounds (i.e. min > max). * * @param numDims * number of dimensions the resulting MaskInterval should have * @return {@link MaskInterval} which returns false for all locations */ public static MaskInterval emptyMaskInterval( final int numDims ) { return new DefaultMaskInterval( emptyInterval( numDims ), BoundaryType.UNSPECIFIED, t -> false, KnownConstant.ALL_FALSE ); }
/** * Creates a {@link RealMaskRealInterval} which returns {@code false} for * every location and has empty interval bounds (i.e. min > max). * * @param numDims * number of dimensions the resulting RealMaskRealInterval should * have * @return {@link RealMaskRealInterval} which returns false for all * locations */ public static RealMaskRealInterval emptyRealMaskRealInterval( final int numDims ) { return new DefaultRealMaskRealInterval( emptyRealInterval( numDims ), BoundaryType.UNSPECIFIED, t -> false, KnownConstant.ALL_FALSE ); }
/** * Wraps the given {@link RealRandomAccessible} as a {@link RealMask}. If * the given RealRandomAccessible is a * {@link RealRandomAccessibleRealInterval} a {@link RealMaskRealInterval} * is returned. * * @param rra * {@link RealRandomAccessible} to be wrapped * @return {@link RealMask} equivalent to the given * {@link RealRandomAccessible} */ public static < B extends BooleanType< B > > RealMask toRealMask( final RealRandomAccessible< B > rra ) { if ( rra instanceof RealRandomAccessibleRealInterval ) return toRealMaskRealInterval( ( RealRandomAccessibleRealInterval< B > ) rra ); return new RealRandomAccessibleAsRealMask<>( rra ); }
/** * Determines whether two point collections describe the same region. * <p> * Two point collections are equal iff they have the same dimensionality and * vertices. * </p> * * @param points1 * The first point collection to compare. * @param points2 * The second point collection to compare. * @return True iff the point collections describe the same region. */ static boolean equals( final RealPointCollection< ? > points1, final RealPointCollection< ? > points2 ) { if ( points1 == null && points2 == null ) return true; if ( points1 == null || points2 == null || !Masks.sameTypesAndDimensions( points1, points2 ) || points1.size() != points2.size() ) return false; for ( final RealLocalizable p : points1.points() ) { if ( !points2.test( p ) ) return false; } return true; } }
/** * Wraps the given {@link RealMask} as a {@link RealRandomAccessible} of * {@link BoolType}. If the given RealMask is a {@link RealMaskRealInterval}, * a {@link RealRandomAccessibleRealInterval} is returned. * * @param mask {@link RealMask} to be wrapped * @return RealRandomAccessible equivalent to the given RealMask */ public static RealRandomAccessible< BoolType > toRealRandomAccessible( final RealMask mask ) { if ( mask instanceof RealMaskRealInterval ) return toRealRandomAccessibleRealInterval( ( RealMaskRealInterval ) mask ); return new RealMaskAsRealRandomAccessible<>( mask, new BoolType() ); }
/** * Wraps the given {@link Mask} as a {@link RandomAccessible} of * {@link BoolType}. If the given Mask is a {@link MaskInterval}, a * {@link RandomAccessibleInterval} is returned. * * @param mask {@link Mask} to be wrapped * @return a RandomAccessible equivalent to the given Mask */ public static RandomAccessible< BoolType > toRandomAccessible( final Mask mask ) { if ( mask instanceof MaskInterval ) return toRandomAccessibleInterval( ( MaskInterval ) mask ); return new MaskAsRandomAccessible<>( mask, new BoolType() ); }
/** * Wraps the given {@link RandomAccessible} as a {@link Mask}. If the given * RandomAccessible is a {@link RandomAccessibleInterval} a * {@link MaskInterval} is returned. * * @param ra * {@link RandomAccessible} to be wrapped * @return {@link Mask} equivalent to the given {@link RandomAccessible} */ public static < B extends BooleanType< B > > Mask toMask( final RandomAccessible< B > ra ) { if ( ra instanceof RandomAccessibleInterval ) return toMaskInterval( ( RandomAccessibleInterval< B > ) ra ); return new RandomAccessibleAsMask<>( ra ); }
/** * Determines whether two lines describe the same region. * <p> * Two lines are equal iff they have the same dimensionality and endpoints. * </p> * * @param line1 * The first line to compare. * @param line2 * The second line to compare. * @return True iff the lines describe the same region. */ public static boolean equals( final Line line1, final Line line2 ) { if ( line1 == null && line2 == null ) return true; return line1 != null && line2 != null && Masks.sameTypesAndDimensions( line1, line2 ) && // Util.locationsEqual( line1.endpointOne(), line2.endpointOne() ) && // Util.locationsEqual( line1.endpointTwo(), line2.endpointTwo() ); } }
@Override public ImageRoi convert(final RealMaskRealInterval mask) { // Wrap mask as RRARI final RealRandomAccessibleRealInterval<BoolType> rrari = Masks .toRealRandomAccessibleRealInterval(mask); // Convert the RRARI to a RAI whose min is (0, 0), this will ensure it // displays properly final RandomAccessible<BoolType> raster = Views.raster(rrari); final RandomAccessible<BoolType> translate = Views.translate(raster, new long[] { (long) -mask.realMin(0), (long) -mask.realMin(1) }); final RandomAccessibleInterval<BoolType> rai = Views.interval(translate, new long[] { 0, 0 }, new long[] { (long) (mask.realMax(0) - mask.realMin( 0)), (long) (mask.realMax(1) - mask.realMin(1)) }); // Convert RAI to ImagePlus final Dataset d = datasetService.create(rai); final ImagePlus ip = convertService.convert(d, ImagePlus.class); return new ImageRoi((int) mask.realMin(0), (int) mask.realMin(1), ip .getBufferedImage()); }
/** * Determines whether two boxes describe the same region. * <p> * Two boxes are equal iff they have the same dimensionality, boundary type, * lengths and position. * </p> * * @param box1 * The first box to compare. * @param box2 * The second box to compare. * @return True iff the boxes describe the same region. */ static boolean equals( final Box box1, final Box box2 ) { if ( box1 == null && box2 == null ) return true; if ( box1 == null || box2 == null || !Masks.sameTypesAndDimensions( box1, box2 ) ) return false; for ( int d = 0; d < box1.numDimensions(); d++ ) if ( box1.sideLength( d ) != box2.sideLength( d ) ) return false; return Util.locationsEqual( box1.center(), box2.center() ); } }
/** * Determines whether two polyshapes describe the same region. * <p> * Two polyshapes are equal iff they have the same mask type, boundary type, * dimensions and vertices. * </p> * * @param polyshape1 * The first polyshape to compare. * @param polyshape2 * The second polyshape to compare. * @return True iff the polyshapes describe the same region. */ static boolean equals( final Polyshape polyshape1, final Polyshape polyshape2 ) { if ( polyshape1 == null && polyshape2 == null ) return true; if ( polyshape1 == null || polyshape2 == null || !Masks.sameTypesAndDimensions( polyshape1, polyshape2 ) ) return false; // Ensure same vertices in same order. final List< RealLocalizable > vertices1 = polyshape1.vertices(); final List< RealLocalizable > vertices2 = polyshape2.vertices(); for ( final Pair< RealLocalizable, RealLocalizable > pair : new IterablePair<>( vertices1, vertices2 ) ) if ( !Util.locationsEqual( pair.getA(), pair.getB() ) ) return false; return true; } }
/** * Determines whether two superellipsoid describe the same region. * <p> * Two superellipsoids are equal iff they have the same dimensionality, * boundary type, exponent, semi-axis lengths and positions. * </p> * * @param ellipsoid1 * The first superellipsoid to compare. * @param ellipsoid2 * The second superellipsoid to compare. * @return True iff the superellipsoids describe the same region. */ static boolean equals( final SuperEllipsoid ellipsoid1, final SuperEllipsoid ellipsoid2 ) { if ( ellipsoid1 == null && ellipsoid2 == null ) return true; if ( ellipsoid1 == null || ellipsoid2 == null || !Masks.sameTypesAndDimensions( ellipsoid1, ellipsoid2 ) || // ellipsoid1.exponent() != ellipsoid2.exponent() ) return false; for ( int d = 0; d < ellipsoid1.numDimensions(); d++ ) if ( ellipsoid1.semiAxisLength( d ) != ellipsoid2.semiAxisLength( d ) ) return false; return Util.locationsEqual( ellipsoid1.center(), ellipsoid2.center() ); } }