Example #1
0
  @SuppressWarnings("unchecked")
  @Override
  public Region<E> close(Region<E> reg) {
    // return erode(dilate(reg));

    try {
      CubeHistogram<E> ch = new CubeHistogram<E>((PixelCube<E, BaseIndex>) reg);

      Erosion<E> er = new Erosion<E>((StructureElement<E>) se);

      er.initFunction(ch);

      Dilation<E> dil = new Dilation<E>((StructureElement<E>) se);

      dil.initFunction(ch);

      reg.setIterationPattern(IP_DEFAULT);
      reg.setIndexing(BASE_INDEXING);

      Region<E> out = new Region<E>((PixelCube<E, ?>) reg.clone(), (StructureElement<E>) se);
      // out.setIterationPattern(IP_DEFAULT);
      // out.setIndexing(BASE_INDEXING);

      final ZonalProcessor zp = reg.getProcessor();
      final VectorCube<E> ve = reg.getVectorCube();
      // System.out.println(ve);

      // final double limbodil=0;s
      // Pair<Number,Number> p= (Pair<Number, Number>) ch.getMinMax();
      // final double limboer=p.second.doubleValue();

      Access<E> accessOut = out.getAccess();

      BoundaryCondition<int[]> bc = reg.getBoundaryCondition();

      final int n = (int) accessOut.length();
      int offset = Util.cumprod(se.getDimensions()) + 1; // (int)ve.size();
      System.out.println("offset: " + offset);
      for (int i = 0; i < n + offset; i++) {
        if (i < n) {
          final E elem = zp.elementTransformCond(ve, dil, bc, i);
          accessOut.putE(i, elem);
        }
        if (i >= offset) {
          final int z = i - offset;
          // System.out.println("z: "+ z);
          final E elem = zp.elementTransformCond(ve, er, bc, z);
          accessOut.putE(z, elem);
        }
      }

      // } // end if

      return out;
    } catch (UnsupportedTypeException e) {
      e.printStackTrace();
    }
    return null;
  }
Example #2
0
  @SuppressWarnings("unchecked")
  @Override
  public Region<E> dilate(Region<E> reg) {
    CubeHistogram<E> ch;
    try {
      ch = new CubeHistogram<E>((PixelCube<E, BaseIndex>) reg);

      Dilation<E> dil = new Dilation<E>((StructureElement<E>) se);

      dil.initFunction(ch);

      reg.setIterationPattern(IP_DEFAULT);
      reg.setIndexing(BASE_INDEXING);
      reg.setElementFnct(dil);
      setLimboDilation(reg, ch);

      Region<E> out = new Region<E>((PixelCube<E, ?>) reg.clone(), (StructureElement<E>) se);
      out.setIterationPattern(IP_DEFAULT);
      out.setIndexing(BASE_INDEXING);
      final ZonalProcessor zp = reg.getProcessor();
      VectorCube<E> ve = reg.getVectorCube();
      // System.out.println(ve);
      BoundaryCondition<int[]> bc = reg.getBoundaryCondition();

      if (useIter) {
        ArrayIterator<E> iter = (ArrayIterator<E>) reg.iterator();
        ArrayIterator<E> iterout = (ArrayIterator<E>) out.iterator();

        while (iter.hasNext() && iterout.hasNext()) {
          int idx = iter.index();
          // System.out.print(idx+" ");
          // final E elem=zp.elementTransform(ve, dil, idx);
          final E elem = zp.elementTransformCond(ve, dil, bc, idx);
          iter.inc();
          iterout.put(elem);
        }

      } else {
        Access<E> accessOut = out.getAccess();
        final int n = accessOut.size()[0];
        for (int i = 0; i < n; i++) {
          // final E elem=reg.elementTransform(dil,i);
          // final E elem=zp.elementTransform(ve, dil, i);
          final E elem = zp.elementTransformCond(ve, dil, bc, i);
          accessOut.putE(i, elem);
        }
      }

      return out;
    } catch (UnsupportedTypeException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return null;
  }