示例#1
0
  // TODO
  @SuppressWarnings("unchecked")
  @Override
  public N join() {

    PixelCube<E, BaseIndex> pc = new PixelCube<E, BaseIndex>(dim, dummy);

    pc.setIndexing(BASE_INDEXING);
    pc.one();

    pc.setIterationPattern(IP_SINGLE + IP_DIR + IP_FWD);
    pc.setDir(new int[] {0, 1});
    PixelDirForwardIterator<E> iter = (PixelDirForwardIterator<E>) pc.iterator();
    PixelDirForwardIterator<E> iter2 = (PixelDirForwardIterator<E>) pc.iterator();

    for (int i = 0; i < nKernels; i++) {

      System.out.println("iter: " + i);
      for (int u = 0; u < ndim; u++) {
        int[] dir = {0, u + 1}; // direction
        if (u == ndim - 1) dir = new int[] {1, 0};
        iter.setDirection(dir);
        iter2.setDirection(dir);
        int p = 0;
        Access<?> kaccess;
        try {
          kaccess = Access.rawAccess(kernels[i], null);
          final int len = kaccess.size()[0];
          System.out.println(dim[u] + ",");
          while (iter.hasNext()) {
            float elem = iter.next().floatValue();
            elem *= kaccess.elementFloat(p);
            System.out.print(elem + ",");
            iter2.putFloat(elem);
            iter2.inc();
            p++;
            p = p % len;
          }
          iter.reset();

          iter2.reset();
          System.out.println();
        } catch (UnsupportedTypeException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          return null;
        } // end catch
      } // end for
    } // end for
    // System.out.println(pc);
    return (N) pc.getAccess().getArray();
  } //
示例#2
0
  /** @param args */
  public static void main(String[] args) {
    final int[] dims = {50, 30};
    final int n = 1500;
    final short[] short_pixels = Util.rampShort(n, 0);

    // final int[] int_pixels=Util.rampInt(n,0);
    final float[] float_pixels = Util.rampFloat(n, 0);

    final short[] labels = {0, 1, 2};
    final int[] borders = {0, 10, 200, 1000};

    final float[] flabels = {0, 1, 2};
    final float[] fborders = {0.0f, 10, 200, 1000};

    PixelCube<Short, BaseIndex> pci = new PixelCube<Short, BaseIndex>(dims, short_pixels);
    pci.setIterationPattern(IP_FWD + IP_SINGLE);
    pci.setIndexing(BASE_INDEXING);

    PixelCube<Short, BaseIndex> outc = (PixelCube<Short, BaseIndex>) pci.clone();

    RasterForwardIterator<Short> in = (RasterForwardIterator<Short>) pci.iterator();
    RasterForwardIterator<Short> out = (RasterForwardIterator<Short>) outc.iterator();

    Labeling<Short> labeling = new Labeling<Short>(labels, borders);
    labeling.setIO(in, out);

    labeling.run();
    new ImageJ();
    PixLib plib = new PixLib();

    ImagePlus imp1 = null;
    try {
      imp1 = plib.imageFrom("test", pci);
    } catch (UnsupportedTypeException e2) {
      // TODO Auto-generated catch block
      e2.printStackTrace();
    }
    imp1.show();

    ImagePlus imp2 = null;
    try {
      imp2 = plib.imageFrom("thresholded", outc);
    } catch (UnsupportedTypeException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
    imp2.show();

    PixelCube<Float, BaseIndex> pcif = new PixelCube<Float, BaseIndex>(dims, float_pixels);
    pcif.setIterationPattern(IP_FWD + IP_SINGLE);
    pcif.setIndexing(BASE_INDEXING);

    PixelCube<Float, BaseIndex> outcf = (PixelCube<Float, BaseIndex>) pcif.clone();

    RasterForwardIterator<Float> inf = (RasterForwardIterator<Float>) pcif.iterator();
    RasterForwardIterator<Float> outf = (RasterForwardIterator<Float>) outcf.iterator();

    Labeling<Float> labelingf = new Labeling<Float>(flabels, fborders);
    labelingf.setIO(inf, outf);

    Float elem = Float.valueOf(3.0f);
    System.out.println(labelingf.mapFloat(elem).getClass());

    labelingf.run();

    // PixLib plibf=new PixLib();
    ImagePlus imp3 = null;
    try {
      imp3 = plib.imageFrom("test", pcif);
    } catch (UnsupportedTypeException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    imp3.show();

    ImagePlus imp4 = null;
    try {
      imp4 = plib.imageFrom("thresholded", outcf);
    } catch (UnsupportedTypeException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    imp4.show();
  }