Пример #1
0
  public static void main(String[] args) {
    // n_cpus=1;
    new MtreadingTest();
    System.out.println("CPUs " + n_cpus + "");
    int[] dims = {2000, 2000};

    final int size = Util.cumprod(dims);
    byte[] byte_pixels = Util.rampByte(size, 100);

    final Thread[] threads = new Thread[n_cpus];

    int csize = size / n_cpus;

    System.out.println("size " + size + " csize " + csize + "");
    final int overlap = 10;

    try {
      final Access<Byte> accesin = Access.rawAccess(byte_pixels, null);

      for (int ithread = 0; ithread < threads.length; ithread++) {
        final int offset = ithread * csize;
        int climit = offset + csize + overlap;
        if (ithread == threads.length - 1) climit = size;
        final int limit = climit;

        // System.out.println("offset "+offset+" limit "+limit);

        final int u = ithread;

        threads[ithread] =
            new Thread() {

              int _id = u;
              boolean _debug = debug;

              {
                setPriority(Thread.NORM_PRIORITY);
              }

              // task specific code goes here
              public void run() {
                for (int i = offset; i < limit; i++) {
                  int p = accesin.elementInt(i) + 1;
                  accesin.putInt(i, p);
                }

                if (_debug) System.out.println("finishing " + limit + " " + _id);
              } // end run
            }; // end thread
        // Concurrently run in as many threads as CPUs
      } // end for
      long time = -System.currentTimeMillis();
      startAndJoin(threads);
      time += System.currentTimeMillis();
      System.out.println("run time " + time + " ");

      PixelCube<Byte, BaseIndex> pci = new PixelCube<Byte, BaseIndex>(dims, byte_pixels);
      new ImageJ();
      PixLib plib = new PixLib();

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

    } catch (UnsupportedTypeException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Пример #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();
  }