Exemplo n.º 1
0
  @SuppressWarnings("unchecked")
  public MorphoProcessorXD(Region<?> reg) throws UnsupportedTypeException {
    se = new StructureElement<E>((VectorCube<E>) reg.getVectorCube());

    region = reg;
    type = reg.getType();
    CubeHistogram<E> ch = new CubeHistogram<E>((PixelCube<E, ?>) region);
    // System.out.println(ch);
    // System.out.println("min max :"+se.getMinMax());
    se.setMinMax(ch);
    scaled = true;
    // System.out.println("scaling ... \n " +se);
  }
Exemplo n.º 2
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;
  }
Exemplo n.º 3
0
  @SuppressWarnings("unchecked")
  private void setLimboDilation(Region<E> reg, CubeHistogram<E> ch) {

    if (reg.getType() == byte.class) {
      final Byte gmin = Byte.valueOf((byte) 0);
      System.out.println("limbo gmin " + (gmin.intValue() & byteMask));
      reg.setLimbo((E) gmin);
      return;
    }
    if (reg.getType() == short.class) {
      final Short gmin = Short.valueOf((short) 0);
      System.out.println("limbo gmin " + (gmin.intValue() & shortMask));
      reg.setLimbo((E) gmin);
      return;
    }
    if (reg.getType() == float.class) {
      Pair<Float, Float> p = (Pair<Float, Float>) ch.getMinMax();
      final Float gmin = p.first;
      System.out.println("limbo gmin " + gmin);
      reg.setLimbo((E) gmin);
      return;
    }
  }
Exemplo n.º 4
0
  @SuppressWarnings("unchecked")
  @Override
  public Region<E> erode(Region<E> reg) {
    try {
      CubeHistogram<E> ch = new CubeHistogram<E>((PixelCube<E, BaseIndex>) reg);

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

      er.initFunction(ch);

      reg.setIterationPattern(IP_DEFAULT);
      reg.setIndexing(BASE_INDEXING);
      reg.setElementFnct(er);
      setLimboErosion(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();
      // System.out.println(bc);
      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, er, idx);
          final E elem = zp.elementTransformCond(ve, er, bc, idx);
          iter.inc();
          iterout.put(elem);
        }

      } else {
        Access<E> accessOut = out.getAccess();
        final int n = accessOut.size()[0];
        for (int idx = 0; idx < n; idx++) {

          // System.out.print(" i="+i+",");
          // final E elem=zp.elementTransform(ve, er, idx);
          final E elem = zp.elementTransformCond(ve, er, bc, idx);

          accessOut.putE(idx, elem);
        }
      }

      return out;
    } catch (UnsupportedTypeException e) {
      e.printStackTrace();
    }
    return null;
  }
Exemplo n.º 5
0
  public Region<E> rankMin(Region<E> reg) {
    CubeHistogram<E> ch;
    try {
      ch = new CubeHistogram<E>((PixelCube<E, BaseIndex>) reg);

      int ndim = reg.getNDimensions();

      final int[] center = new int[ndim];

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

      dil.initFunction(ch);

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

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

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

        while (iter.hasNext() && iterout.hasNext()) {
          final int idx = iter.index();
          // System.out.print(idx+" ");
          final E elem = reg.elementTransform(idx, center);
          iter.inc();
          if (elem.intValue() == 0) iterout.putInt(0);
          else iterout.inc();
        }

      } else {
        Access<E> accessOut = out.getAccess();
        final int n = accessOut.size()[0];
        for (int i = 0; i < n; i++) {
          final E elem = reg.elementTransform(i, center); // we return a masking element
          if (elem.intValue() == 0) {
            // System.out.print(elem.intValue()+"+");
            accessOut.putInt(i, 0);
          }
        }
      }

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