Ejemplo n.º 1
0
 @Test
 public void testSingleDilateFull() {
   final Shape shape = new DiamondShape(1);
   @SuppressWarnings("unchecked")
   final Img<ByteType> out1 =
       (Img<ByteType>) ops.run(DefaultDilate.class, Img.class, in, shape, true);
   final Img<ByteType> out2 = Dilation.dilateFull(in, shape, 1);
   final Cursor<ByteType> c1 = out1.cursor();
   final Cursor<ByteType> c2 = out2.cursor();
   while (c1.hasNext()) assertEquals(c1.next().get(), c2.next().get());
 }
Ejemplo n.º 2
0
  @Test
  public void testInplace() {
    ops.run(DefaultLoopInplace.class, in, inplaceOp, numIterations);

    // test
    final Cursor<ByteType> c = in.cursor();

    while (c.hasNext()) {
      org.junit.Assert.assertEquals(numIterations, c.next().get());
    }
  }
Ejemplo n.º 3
0
 @Test
 public void testListDilateFull() {
   final List<Shape> shapes = new ArrayList<Shape>();
   shapes.add(new DiamondShape(1));
   shapes.add(new DiamondShape(1));
   shapes.add(new RectangleShape(1, false));
   shapes.add(new HorizontalLineShape(2, 1, false));
   @SuppressWarnings("unchecked")
   final IterableInterval<ByteType> out1 =
       (IterableInterval<ByteType>)
           ops.run(ListDilate.class, IterableInterval.class, in, shapes, true);
   final Img<ByteType> out2 = Dilation.dilateFull(in, shapes, 1);
   final Cursor<ByteType> c1 = out1.cursor();
   final Cursor<ByteType> c2 = out2.cursor();
   while (c1.hasNext()) assertEquals(c1.next().get(), c2.next().get());
 }
Ejemplo n.º 4
0
  @Test
  public void testFunctionalEven() {
    ops.run(
        DefaultLoopComputer.class,
        out,
        in,
        computerOp,
        new ImgImgSameTypeFactory<ByteType>(),
        numIterations);

    // test
    final Cursor<ByteType> c = out.cursor();

    while (c.hasNext()) {
      org.junit.Assert.assertEquals(numIterations, c.next().get());
    }
  }
Ejemplo n.º 5
0
  /**
   * Create a new imgage with using the current settings.
   *
   * @return the new image
   */
  @SuppressWarnings("unchecked")
  public final <T extends NativeType<T> & RealType<T>> ImgPlus<T> nextImage() {

    // Set up new utils
    m_dimList = new ArrayList<Long>();
    m_axisList = new ArrayList<AxisType>();

    ImgFactoryTypes facType;

    // select a factory
    if (m_factory == null) {
      m_factory = ImgFactoryTypes.values()[randomBoundedInt(ImgFactoryTypes.values().length - 2)];
    }

    if (m_randomFactory) {
      facType = ImgFactoryTypes.values()[randomBoundedInt(ImgFactoryTypes.values().length - 2)];
    } else {
      facType = m_factory;
    }

    final ImgFactory<T> imgFac = ImgFactoryTypes.getImgFactory(facType);

    // process all dimensions
    processDimension(m_minSizeX, m_sizeX, "X");
    processDimension(m_minSizeY, m_sizeY, "Y");
    processDimension(m_minSizeZ, m_sizeZ, "Z");
    processDimension(m_minSizeChannel, m_sizeChannel, "Channel");
    processDimension(m_minSizeT, m_sizeT, "Time");

    final long[] dims = new long[m_dimList.size()];

    for (int d = 0; d < m_dimList.size(); d++) {
      dims[d] = m_dimList.get(d);
    }

    // Type of img is selected
    NativeTypes type;

    if (m_type == null) {
      m_type = NativeTypes.values()[randomBoundedInt(NativeTypes.values().length - 1)];
    }

    if (m_randomType) {
      type = NativeTypes.values()[randomBoundedInt(NativeTypes.values().length - 1)];
    } else {
      type = m_type;
    }

    // create the actual image
    final T val = (T) NativeTypes.getTypeInstance(type);
    final Img<T> img = imgFac.create(dims, val);

    // fill the image
    final Cursor<T> cursor = img.cursor();
    while (cursor.hasNext()) {
      cursor.fwd();

      double result;

      if (m_randomFill) {
        double sign = 1;

        if (val.getMinValue() < 0) {
          if (Math.random() > 0.5) { // ~50% negative
            sign = -1;
          }
        }

        if (type.equals(NativeTypes.DOUBLETYPE) || type.equals(NativeTypes.FLOATTYPE)) {
          // random value between -1 and 1
          result = Math.random() * sign;
        } else {
          // random value in type range
          result = Math.random() * val.getMaxValue() * sign;
        }
      } else {
        result = m_value;
      }

      cursor.get().setReal(result);
    }

    final ImgPlus<T> imgPlus = new ImgPlus<T>(ImgView.wrap(img, imgFac));

    int d = 0;
    for (final AxisType a : m_axisList) {
      imgPlus.setAxis(new DefaultLinearAxis(a), d++);
    }

    return imgPlus;
  }