示例#1
0
  private ImagePlus findSurfaceVoxels(final ImagePlus imp) {
    final int w = imp.getWidth();
    final int h = imp.getHeight();
    final int d = imp.getImageStackSize();
    final ImageStack stack = imp.getImageStack();
    final ImageStack surfaceStack = new ImageStack(w, h, d);

    for (int z = 0; z < d; z++) {
      IJ.showStatus("Finding surface voxels");
      final byte[] pixels = (byte[]) stack.getPixels(z + 1);
      surfaceStack.setPixels(pixels.clone(), z + 1);
      final ImageProcessor surfaceIP = surfaceStack.getProcessor(z + 1);
      for (int y = 0; y < h; y++) {
        checkNeighbours:
        for (int x = 0; x < w; x++) {
          if (getPixel(stack, x, y, z, w, h, d) == (byte) 0) continue;
          for (int nz = -1; nz < 2; nz++) {
            final int znz = z + nz;
            for (int ny = -1; ny < 2; ny++) {
              final int yny = y + ny;
              for (int nx = -1; nx < 2; nx++) {
                final int xnx = x + nx;
                final byte pixel = getPixel(stack, xnx, yny, znz, w, h, d);
                if (pixel == (byte) 0) continue checkNeighbours;
              }
            }
          }
          // we checked all the neighbours for a 0
          // but didn't find one, so this is not a surface voxel
          surfaceIP.set(x, y, (byte) 1);
        }
      }
    }
    // turn all the 1's into 0's
    final int wh = w * h;
    for (int z = 0; z < d; z++) {
      IJ.showStatus("Finding surface voxels");
      final ImageProcessor ip = surfaceStack.getProcessor(z + 1);
      for (int i = 0; i < wh; i++) {
        if (ip.get(i) == (byte) 1) ip.set(i, (byte) 0);
      }
    }

    final ImagePlus surfaceImp = new ImagePlus("Surface");
    surfaceImp.setStack(surfaceStack);
    surfaceImp.setCalibration(imp.getCalibration());
    return surfaceImp;
  }
示例#2
0
  @Override
  public void putLineShort(short[] line, int k, int xdir) {
    final int width = ip.getWidth();
    final int height = ip.getHeight();

    switch (xdir) {
      case Ox:
        {
          if (debug) System.out.println("puting line in Ox");
          final int lineno = height;
          int offset = k * width;
          int z = offset / (width * height);
          if (z >= 0 && z < lineno) {
            Object aux = ip.getPixels();
            try {
              System.arraycopy(line, 0, aux, offset, width);
              // System.out.println(":"+(offset ));
            } catch (Exception e) {
              System.out.println("offset" + (offset));
              e.printStackTrace();
            }
          }
          break;
        }
      case Oy:
        {
          if (debug) System.out.println("puting line in Oy");
          final int lineno = width;
          k = k % width;
          if (k >= 0 && k < lineno) {
            try {
              for (int y = 0; y < height; y++) {
                ip.set(k, y, line[y]);
                // System.out.print( "("+ k +" " +y +"),");
              }
            } catch (Exception e) {
              // System.out.println("k "+ k );
              e.printStackTrace();
            }
          }
          break;
        }
    }
  }
示例#3
0
  /**
   * Reduce error in thickness quantitation by trimming the one pixel overhang in the thickness map
   *
   * @param imp Binary input image
   * @param impLTC Thickness map
   * @param inv true if calculating thickness of background, false for foreground
   * @return Thickness map with pixels masked by input image
   */
  private ImagePlus trimOverhang(ImagePlus imp, ImagePlus impLTC, boolean inv) {
    final int w = imp.getWidth();
    final int h = imp.getHeight();
    final int d = imp.getImageStackSize();

    final ImageStack stack = imp.getImageStack();
    final ImageStack mapStack = impLTC.getImageStack();

    final int keepValue = inv ? 0 : 255;
    ImageProcessor ip = new ByteProcessor(w, h);
    ImageProcessor map = new FloatProcessor(w, h);
    for (int z = 1; z <= d; z++) {
      IJ.showStatus("Masking thickness map...");
      IJ.showProgress(z, d);
      ip = stack.getProcessor(z);
      map = mapStack.getProcessor(z);
      for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
          if (ip.get(x, y) != keepValue) map.set(x, y, 0);
        }
      }
    }
    return impLTC;
  }
  public void run(ImageProcessor ip) {
    // Ask the user for the sCol value (color saturation factor)
    GenericDialog gd = new GenericDialog("sCol Value");
    gd.addNumericField("sCol: ", 0.3, 3);
    gd.showDialog();
    if (gd.wasCanceled()) return;
    sCol = gd.getNextNumber();

    // Get the mask for the ROI (selected region)
    ImageProcessor mask = ip.getMask();

    Rectangle roi = ip.getRoi();
    int x = (int) roi.getX();
    int y = (int) roi.getY();
    int w = (int) roi.getWidth();
    int h = (int) roi.getHeight();
    // IJ.write("mask w: "+mask.getWidth()+", mask h: "+mask.getHeight()+", roi w: "+w+", roi h:
    // "+h);
    // Create a new mask based on the selected region, but the size is equivalent to the original
    // image
    ColorProcessor temp = new ColorProcessor(ip.getWidth(), ip.getHeight());
    for (int j = 0; j < ip.getHeight(); j++) {
      for (int i = 0; i < ip.getWidth(); i++) {
        if (j >= y && j < y + h && i >= x && i < x + w) {
          // In the mask region
          if (mask == null) // When ROI is Rectangle
          temp.set(i, j, 1);
          else {
            if (mask.get(i - x, j - y) != 0) temp.set(i, j, 1);
            else temp.set(i, j, 0);
          }
        } else {
          temp.set(i, j, 0);
        }
      }
    }
    ip.setMask(temp); // not necessary
    mask = temp;

    // iterate over all pixels, and desaturate only pixels in ROI
    for (int v = 0; v < ip.getHeight(); v++) {
      for (int u = 0; u < ip.getWidth(); u++) {
        if (mask.get(u, v) != 0) {
          // get int-packed color pixel
          int c = ip.get(u, v);

          // extract RGB components from color pixel
          int r = (c & 0xff0000) >> 16;
          int g = (c & 0x00ff00) >> 8;
          int b = (c & 0x0000ff);

          // compute equivalent gray value
          double yy = 0.299 * r + 0.587 * g + 0.114 * b;

          // linearly interpolate $(yyy) --> (rgb)
          r = (int) (yy + sCol * (r - yy));
          g = (int) (yy + sCol * (g - yy));
          b = (int) (yy + sCol * (b - yy));

          // reassemble color pixel
          c = ((r & 0xff) << 16) | ((g & 0xff) << 8) | b & 0xff;
          ip.set(u, v, c);
        }
      }
    }
    imp.updateAndDraw();
  }