/**
  * Splits the specified RGB stack into three 8-bit grayscale stacks. Deletes the source stack if
  * keepSource is false.
  */
 public static ImageStack[] splitRGB(ImageStack rgb, boolean keepSource) {
   int w = rgb.getWidth();
   int h = rgb.getHeight();
   ImageStack[] channels = new ImageStack[3];
   for (int i = 0; i < 3; i++) channels[i] = new ImageStack(w, h);
   byte[] r, g, b;
   ColorProcessor cp;
   int slice = 1;
   int inc = keepSource ? 1 : 0;
   int n = rgb.getSize();
   for (int i = 1; i <= n; i++) {
     IJ.showStatus(i + "/" + n);
     r = new byte[w * h];
     g = new byte[w * h];
     b = new byte[w * h];
     cp = (ColorProcessor) rgb.getProcessor(slice);
     slice += inc;
     cp.getRGB(r, g, b);
     if (!keepSource) rgb.deleteSlice(1);
     channels[0].addSlice(null, r);
     channels[1].addSlice(null, g);
     channels[2].addSlice(null, b);
     IJ.showProgress((double) i / n);
   }
   return channels;
 }
  public ImageProcessor projectColor(int[] maxima) {
    ColorProcessor ip = new ColorProcessor(w, h);
    for (int y = 0; y < h; y++) {
      for (int x = 0; x < w; x++) {
        int index = y * w + x;

        float w0 = vertexWeights[index][0];
        float w1 = vertexWeights[index][1];
        float w2 = vertexWeights[index][2];

        int m0 = maxima[vIndices[index][0]];
        int m1 = maxima[vIndices[index][1]];
        int m2 = maxima[vIndices[index][2]];

        int r =
            (int)
                (w0 * ((m0 & 0xff0000) >> 16)
                    + w1 * ((m1 & 0xff0000) >> 16)
                    + w2 * ((m2 & 0xff0000) >> 16));
        int g =
            (int)
                (w0 * ((m0 & 0xff00) >> 8) + w1 * ((m1 & 0xff00) >> 8) + w2 * ((m2 & 0xff00) >> 8));
        int b = (int) (w0 * ((m0 & 0xff)) + w1 * ((m1 & 0xff)) + w2 * ((m2 & 0xff)));

        ip.set(x, y, (r << 16) + (g << 8) + b);
      }
    }
    return ip;
  }
示例#3
0
  /**
   * Method to change bands order only on the BufferedImage.
   *
   * @param bufferedImage
   * @return new bufferedImage
   */
  public Image invertRGB(BufferedImage bufferedImage, String bands) {

    ColorModel colorModel = bufferedImage.getColorModel();

    if (colorModel instanceof DirectColorModel) {
      DirectColorModel directColorModel = (DirectColorModel) colorModel;
      int red = directColorModel.getRedMask();
      int blue = directColorModel.getBlueMask();
      int green = directColorModel.getGreenMask();
      int alpha = directColorModel.getAlphaMask();

      int[] components = new int[3];
      String bds = bands.toLowerCase();
      components[0] = getComponent(bds.charAt(0), red, green, blue);
      components[1] = getComponent(bds.charAt(1), red, green, blue);
      components[2] = getComponent(bds.charAt(2), red, green, blue);

      directColorModel =
          new DirectColorModel(32, components[0], components[1], components[2], alpha);
      ColorProcessor colorProcessor = new ColorProcessor(bufferedImage);
      colorProcessor.setColorModel(directColorModel);

      return colorProcessor.createImage();
    }
    return bufferedImage;
  }
示例#4
0
  public static double[] getPixels(ImagePlus imp, int[] slices, int[] frames, int[] channels) {

    ImagePlus subImp = AccessImage.getSubHyperStack(imp, slices, frames, channels);
    ImageStack imageStack = subImp.getImageStack();

    double[] pixels = new double[subImp.getWidth() * subImp.getHeight() * imageStack.getSize()];

    for (int i = 0; i < imageStack.getSize(); i++) {
      switch (subImp.getType()) {
        case ImagePlus.GRAY8:
          ByteProcessor byteProcessor = (ByteProcessor) imageStack.getProcessor(i + 1);
          for (int iX = 0; iX < subImp.getWidth(); iX++) {
            for (int iY = 0; iY < subImp.getHeight(); iY++) {
              pixels[i * subImp.getWidth() * subImp.getHeight() + iY * subImp.getWidth() + iX] =
                  (double) byteProcessor.getPixelValue(iX, iY);
            }
          }
          break;
        case ImagePlus.GRAY16:
          ShortProcessor shortProcessor = (ShortProcessor) imageStack.getProcessor(i + 1);
          for (int iX = 0; iX < subImp.getWidth(); iX++) {
            for (int iY = 0; iY < subImp.getHeight(); iY++) {
              pixels[i * subImp.getWidth() * subImp.getHeight() + iY * subImp.getWidth() + iX] =
                  (double) shortProcessor.getPixelValue(iX, iY);
            }
          }
          break;
        case ImagePlus.GRAY32:
          FloatProcessor floatProcessor = (FloatProcessor) imageStack.getProcessor(i + 1);
          for (int iX = 0; iX < subImp.getWidth(); iX++) {
            for (int iY = 0; iY < subImp.getHeight(); iY++) {
              pixels[i * subImp.getWidth() * subImp.getHeight() + iY * subImp.getWidth() + iX] =
                  (double) floatProcessor.getPixelValue(iX, iY);
            }
          }
          break;
        case ImagePlus.COLOR_RGB:
          ColorProcessor colorProcessor = (ColorProcessor) imageStack.getProcessor(i + 1);
          int nX = subImp.getWidth();
          int nY = subImp.getHeight();
          byte[] red = new byte[nX * nY];
          byte[] green = new byte[nX * nY];
          byte[] blue = new byte[nX * nY];
          colorProcessor.getRGB(red, green, blue);
          int r, g, b;

          for (int j = 0; j < nX * nY; j++) {
            r = red[j] << 16;
            g = green[j] << 8;
            b = blue[j] << 0;
            pixels[i * nX * nY + j] = (double) (r + g + b);
          }
          break;
      }
    }

    return (pixels);
  }
  public ImagePlusInteractiveDisplay2D(
      final int width,
      final int height,
      final ScreenImageRenderer renderer,
      final TransformListener2D renderTransformListener) {
    sourceToScreen = new AffineTransform2D();

    final ColorProcessor cp = new ColorProcessor(width, height);
    screenImage = new ARGBScreenImage(cp.getWidth(), cp.getHeight(), (int[]) cp.getPixels());

    this.renderer = renderer;
    renderer.screenImageChanged(screenImage);
    this.renderTransformListener = renderTransformListener;

    imp = new ImagePlus("argbScreenProjection", cp);
    imp.show();
    imp.getCanvas().setMagnification(1.0);
    imp.draw();

    gui = new GUI(imp);

    handler = new TransformEventHandler2Dij(imp, this);
    handler.setWindowCenter(width / 2, height / 2);
    addHandler(handler);

    // additional keyboard mappings
    addHandler(
        new KeyListener() {
          @Override
          public void keyPressed(final KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_E) {
              IJ.log(sourceToScreen.toString());
            } else if (e.getKeyCode() == KeyEvent.VK_F1) {
              IJ.showMessage(handler.getHelpString());
            } else if (e.getKeyCode() == KeyEvent.VK_PLUS || e.getKeyCode() == KeyEvent.VK_EQUALS) {
              IJ.run("In [+]");
            } else if (e.getKeyCode() == KeyEvent.VK_MINUS) {
              IJ.run("Out [-]");
            }
          }

          @Override
          public void keyTyped(final KeyEvent e) {}

          @Override
          public void keyReleased(final KeyEvent e) {}
        });
  }
  @Override
  public BooleanImage getBinaryImage(ImageProcessor ip) {
    if (th1 == null || !isSupported(ip)) return new BooleanImage(ip.getWidth(), ip.getHeight());
    int width = ip.getWidth();
    int height = ip.getHeight();
    byte[] ch1, ch2, ch3;

    ch1 = new byte[ip.getWidth() * ip.getHeight()];
    ch2 = new byte[ip.getWidth() * ip.getHeight()];
    ch3 = new byte[ip.getWidth() * ip.getHeight()];

    ColorProcessor cp = (ColorProcessor) ip;

    switch (colorspace) {
      case RGB:
        cp.getRGB(ch1, ch2, ch3);
        break;
      case HSB:
        cp.getHSB(ch1, ch2, ch3);
        break;
      case Lab:
        getLab(cp, ch1, ch2, ch3);
        break;
      case YUV:
        getYUV(cp, ch1, ch2, ch3);
        break;
      default:
        break;
    }
    boolean[] pix = new boolean[width * height];

    for (int i = 0; i < ch1.length; i++) {
      boolean c1 = th1[0] <= (ch1[i] & 0xff) && (ch1[i] & 0xff) <= th1[1];
      if (pass1 ? !c1 : c1) continue;
      boolean c2 = th2[0] <= (ch2[i] & 0xff) && (ch2[i] & 0xff) <= th2[1];
      if (pass2 ? !c2 : c2) continue;
      boolean c3 = th3[0] <= (ch3[i] & 0xff) && (ch3[i] & 0xff) <= th3[1];
      if (pass3 ? !c3 : c3) continue;
      pix[i] = true;
    }

    pix = applyMask(pix);
    return new BooleanImage(width, height, pix);
  }
示例#7
0
 // Conversion Options
 void conversions() {
   double[] weights = ColorProcessor.getWeightingFactors();
   boolean weighted = !(weights[0] == 1d / 3d && weights[1] == 1d / 3d && weights[2] == 1d / 3d);
   // boolean weighted = !(Math.abs(weights[0]-1d/3d)<0.0001 && Math.abs(weights[1]-1d/3d)<0.0001
   // && Math.abs(weights[2]-1d/3d)<0.0001);
   GenericDialog gd = new GenericDialog("Conversion Options");
   gd.addCheckbox("Scale when converting", ImageConverter.getDoScaling());
   String prompt = "Weighted RGB conversions";
   if (weighted)
     prompt +=
         " (" + IJ.d2s(weights[0]) + "," + IJ.d2s(weights[1]) + "," + IJ.d2s(weights[2]) + ")";
   gd.addCheckbox(prompt, weighted);
   gd.showDialog();
   if (gd.wasCanceled()) return;
   ImageConverter.setDoScaling(gd.getNextBoolean());
   Prefs.weightedColor = gd.getNextBoolean();
   if (!Prefs.weightedColor) ColorProcessor.setWeightingFactors(1d / 3d, 1d / 3d, 1d / 3d);
   else if (Prefs.weightedColor && !weighted)
     ColorProcessor.setWeightingFactors(0.299, 0.587, 0.114);
   return;
 }
示例#8
0
  private void process(ColorProcessor ip) {
    double[] feature = new double[binX * binY * binZ];
    int processedPixels = 0;

    ImageProcessor mask = ip.getMask();

    int numpixels = ip.getPixelCount();
    float[] hsbvals = new float[3]; // Conversion buffer
    for (int i = 0; i < numpixels; i++) {
      if (mask == null || mask.get(i) != 0) {
        if (type == TYPE.HSB) {
          feature[getBinForHSB(ip.get(i), hsbvals)]++;
        } else if (type == TYPE.RGB) {
          feature[getBinForRGB(ip.get(i))]++;
        }
        processedPixels++;
      }
    }

    Arrays2.div(feature, processedPixels);
    addData(feature);
  }
示例#9
0
    public void makeTransition(ImagePlus imp, int from, int num) {
      if (from > imp.getStackSize()) {
        IJ.error("Need a following slice to which to transit.");
        return;
      }
      num++; // so that really num slices are added
      ImageStack stack = imp.getStack();
      int[] before = (int[]) (stack.getProcessor(from).convertToRGB().getPixels());
      int[] after = (int[]) (stack.getProcessor(from + 1).convertToRGB().getPixels());

      for (int z = 1; z < num; z++) {
        ColorProcessor bp = new ColorProcessor(stack.getWidth(), stack.getHeight());
        int[] pixels = (int[]) bp.getPixels();
        double dp = z;
        double dn = num - z;

        for (int i = 0; i < pixels.length; i++) {
          pixels[i] = interpolate(before[i], dp, after[i], dn);
        }
        new ImagePlus("slice + " + z, bp).show();
        stack.addSlice("", bp, from + z - 1);
      }
    }
示例#10
0
 public void fillRect(int x, int y, int width, int height) {
   // have the implement the clip rect ourselves here
   int x1 = x;
   int y1 = y;
   int x2 = x + width;
   int y2 = y + height;
   if (x1 < clip.x) x1 = clip.x;
   if (x2 > (clip.x + clip.width)) x2 = clip.x + clip.width;
   if (x2 < x1) return;
   if (y1 < clip.y) y1 = clip.y;
   if (y2 > (clip.y + clip.width)) y2 = clip.y + clip.width;
   if (y2 < y1) return;
   Roi fillroi = new Roi(x1, y1, x2 - x1, y2 - y1);
   cp.fill(fillroi);
 }
  public int[] setSphereColors(SphericalMaxProjection smp, ColorProcessor ip) {
    Point2f polar = new Point2f();
    Point2D.Double out = new Point2D.Double();
    int[] colors = new int[smp.getSphere().nVertices];
    int idx = 0;
    for (Point3f v : smp.getSphere().getVertices()) {
      smp.getPolar(v, polar);
      projection.transformRadians(polar.x, polar.y, out);
      int x = (int) out.x - minx;
      int y = maxy - (int) out.y;

      colors[idx++] = ip.get(x, y);
    }
    return colors;
  }
示例#12
0
 ImageStack getRGBStack(ImagePlus imp) {
   ImageProcessor ip = imp.getProcessor();
   int w = ip.getWidth();
   int h = ip.getHeight();
   int size = w * h;
   byte[] r = new byte[size];
   byte[] g = new byte[size];
   byte[] b = new byte[size];
   ((ColorProcessor) ip).getRGB(r, g, b);
   ImageStack stack = new ImageStack(w, h);
   stack.addSlice("Red", r);
   stack.addSlice("Green", g);
   stack.addSlice("Blue", b);
   stack.setColorModel(ip.getDefaultColorModel());
   return stack;
 }
示例#13
0
 public void unsetClip() {
   cp.setClipRect(null);
   clip = new Rectangle(width, height);
 }
示例#14
0
 public FontMetrics getFontMetrics() {
   return cp.getFontMetrics();
 }
示例#15
0
 public Font getFont() {
   return cp.getFont();
 }
示例#16
0
 public int getStringWidth(String string) {
   return cp.getStringWidth(string);
 }
  // -----------------------------------------------------------------------------------
  public void Lipschitz2D(ImageProcessor ip) {
    int slope, slope1, p, p1, p2, p3, p4, maxz;

    m_roi = ip.getRoi();
    ImageHeight = ip.getHeight();
    ImageWidth = ip.getWidth();
    m_channels = ip instanceof ColorProcessor ? 3 : 1;
    m_short = ip instanceof ShortProcessor;
    pixel = new int[m_channels];

    int[][] destPixels = new int[m_channels][ImageHeight * ImageWidth];
    int[][] srcPixels = new int[m_channels][ImageHeight * ImageWidth];
    byte[][] tmpBytePixels = new byte[m_channels][ImageHeight * ImageWidth];
    short[][] tmpShortPixels = new short[m_channels][ImageHeight * ImageWidth];

    if (m_channels == 1) {
      if (m_short) {
        tmpShortPixels[0] = (short[]) ip.getPixels();
      } else {
        tmpBytePixels[0] = (byte[]) ip.getPixels();
      }

    } else {
      ColorProcessor cip = (ColorProcessor) ip;
      cip.getRGB(tmpBytePixels[0], tmpBytePixels[1], tmpBytePixels[2]);
    }

    int sign = (m_Down ? 1 : -1);
    int topdown = (m_Down ? 0 : 255);
    for (int ii = 0; ii < m_channels; ii++) {
      for (int ij = 0; ij < ImageHeight * ImageWidth; ij++) {
        srcPixels[ii][ij] =
            (m_short
                ? sign * (tmpShortPixels[ii][ij] & 0xffff)
                : sign * (tmpBytePixels[ii][ij] & 0xff));
        destPixels[ii][ij] = srcPixels[ii][ij];
      }
    }

    slope = (int) (m_Slope);
    slope1 = (int) (slope * Math.sqrt(2.0));
    maxz = m_channels;

    for (int y = m_roi.y; y < m_roi.y + m_roi.height; y++) // rows
    {
      IJ.showProgress(y, 2 * ImageHeight);
      for (int z = 0; z < m_channels; z++) {
        p2 = sign * (topdown + (sign) * slope);
        p3 = sign * (topdown + (sign) * slope1);
        for (int x = m_roi.x; x < m_roi.x + m_roi.width; x++) // columns
        {
          p = (p2 - slope);
          p1 = (p3 - slope1);
          if (p1 > p) p = p1;
          p3 = destPixels[z][x + ImageWidth * (Math.max(y - 1, 0))];
          p1 = p3 - slope;
          if (p1 > p) p = p1;

          p4 = destPixels[z][Math.min(x + 1, ImageWidth - 1) + ImageWidth * (Math.max(y - 1, 0))];
          p1 = p4 - slope1;
          if (p1 > p) p = p1;

          p2 = srcPixels[z][x + ImageWidth * y];
          if (p > p2) {
            destPixels[z][x + ImageWidth * y] = p;
            p2 = p;
          }
        }
      }
    }

    for (int y = m_roi.y + m_roi.height - 1; y >= m_roi.y; y--) // rows
    {
      IJ.showProgress(2 * ImageHeight - y - 1, 2 * ImageHeight);
      for (int z = 0; z < maxz; z++) {
        p2 = sign * (topdown + (sign) * slope);
        p3 = sign * (topdown + (sign) * slope1);
        for (int x = m_roi.x + m_roi.width - 1; x >= m_roi.x; x--) // columns
        {
          p = (p2 - slope);
          p1 = (p3 - slope1);
          if (p1 > p) p = p1;

          p3 = destPixels[z][x + ImageWidth * (Math.min(y + 1, ImageHeight - 1))];
          p1 = p3 - slope;
          if (p1 > p) p = p1;

          p4 = destPixels[z][Math.max(x - 1, 0) + ImageWidth * (Math.min(y + 1, ImageHeight - 1))];
          p1 = p4 - slope1;
          if (p1 > p) p = p1;

          p2 = destPixels[z][x + ImageWidth * y];
          if (p > p2) {
            destPixels[z][x + ImageWidth * y] = p;
            p2 = p;
          }
        }
      }
    }

    for (int ii = 0; ii < m_channels; ii++) {
      for (int ij = 0; ij < ImageHeight * ImageWidth; ij++) {
        if (m_TopHat) {
          tmpBytePixels[ii][ij] =
              (m_Down
                  ? (byte) (srcPixels[ii][ij] - destPixels[ii][ij] + 255)
                  : (byte) (destPixels[ii][ij] - srcPixels[ii][ij]));
        } else {
          if (m_short) {
            tmpShortPixels[ii][ij] = (short) ((sign * destPixels[ii][ij] & 0xffff));
          } else {
            tmpBytePixels[ii][ij] = (byte) (sign * destPixels[ii][ij]);
          }
        }
      }
    }

    if (m_channels == 1) {
      if (m_short) {
        ShortProcessor sip = (ShortProcessor) ip;
        sip.setPixels(tmpShortPixels[0]);
      } else {
        ByteProcessor bip = (ByteProcessor) ip;
        bip.setPixels(tmpBytePixels[0]);
      }

    } else {
      ColorProcessor cip = (ColorProcessor) ip;
      cip.setRGB(tmpBytePixels[0], tmpBytePixels[1], tmpBytePixels[2]);
    }
  }
示例#18
0
 public void drawVerticalString(String string, int x, int y) {
   // x and y here are the center of the string
   FontMetrics fm = cp.getFontMetrics();
   int ascent = fm.getAscent();
   int descent = fm.getDescent();
   int height = ascent + descent;
   int width = cp.getStringWidth(string);
   int[] mask = new int[width * height];
   for (int i = 0; i < width * height; i++) {
     mask[i] = 0xffffffff;
   }
   ColorProcessor cp2 = new ColorProcessor(width, height, mask);
   cp2.setAntialiasedText(antialias);
   cp2.setFont(cp.getFont());
   cp2.drawString(string, 0, ascent);
   ColorProcessor cp3 = (ColorProcessor) cp2.rotateLeft();
   mask = (int[]) cp3.getPixels();
   int newx = x - height / 2;
   int newy = y - width / 2;
   int[] pixels = (int[]) cp.getPixels();
   int owidth = cp.getWidth();
   int oheight = cp.getHeight();
   for (int i = 0; i < width; i++) {
     int b = newy + i;
     if (b >= 0 && b < oheight) {
       for (int j = 0; j < height; j++) {
         int a = newx + j;
         if (a >= 0 && a < owidth) {
           if (mask[j + i * height] != 0xffffffff) {
             pixels[a + owidth * b] = mask[j + i * height];
           }
         }
       }
     }
   }
 }
示例#19
0
 public void drawLine(int x1, int y1, int x2, int y2) {
   cp.drawLine(x1, y1, x2, y2);
 }
示例#20
0
    void sample() {
      byte[] hsSource, ssSource, bsSource;
      // ImageProcessor ip2;
      // ip2 = imp.getProcessor();
      Rectangle myroi = ip.getRoi();
      int swidth = myroi.width;
      int sheight = myroi.height;
      int sy = myroi.y;
      int sx = myroi.x;
      if (swidth == width && sheight == height) {
        IJ.showMessage("Select a rectangular ROI");
        IJ.beep();
        return;
      }

      IJ.run("Select None");

      int snumPixels = swidth * sheight;

      hsSource = new byte[snumPixels];
      ssSource = new byte[snumPixels];
      bsSource = new byte[snumPixels];

      int[] pixs = new int[snumPixels];
      int[] bin = new int[256];

      int counter = 0, pi = 0, rangePassH = 0, rangeStopH = 0, rangePassL = 0, rangeStopL = 0, i, j;

      for (i = sy; i < sy + sheight; i++) {
        for (j = sx; j < sx + swidth; j++) {
          pixs[counter++] = ip.getPixel(j, i);
        }
      }

      // Get hsb or rgb from roi.
      ColorProcessor cp2 = new ColorProcessor(swidth, sheight, pixs);

      int iminhue = 256, imaxhue = -1, iminsat = 256, imaxsat = -1, iminbri = 256, imaxbri = -1;
      int iminred = 256, imaxred = -1, imingre = 256, imaxgre = -1, iminblu = 256, imaxblu = -1;

      if (isRGB) cp2.getRGB(hsSource, ssSource, bsSource);
      else cp2.getHSB(hsSource, ssSource, bsSource);

      for (i = 0; i < snumPixels; i++) {
        bin[hsSource[i] & 255] = 1;
        if ((hsSource[i] & 255) > imaxhue) imaxhue = (hsSource[i] & 255);
        if ((hsSource[i] & 255) < iminhue) iminhue = (hsSource[i] & 255);
        if ((ssSource[i] & 255) > imaxsat) imaxsat = (ssSource[i] & 255);
        if ((ssSource[i] & 255) < iminsat) iminsat = (ssSource[i] & 255);
        if ((bsSource[i] & 255) > imaxbri) imaxbri = (bsSource[i] & 255);
        if ((bsSource[i] & 255) < iminbri) iminbri = (bsSource[i] & 255);
        // IJ.showMessage("h:"+minhue+"H:"+maxhue+"s:"+minsat+"S:"+maxsat+"b:"+minbri+"B:"+maxbri);
      }

      if (!isRGB) { // get pass or stop filter whichever has a narrower range
        for (i = 0; i < 256; i++) {
          if (bin[i] > 0) {
            rangePassL = i;
            break;
          }
        }
        for (i = 255; i >= 0; i--) {
          if (bin[i] > 0) {
            rangePassH = i;
            break;
          }
        }
        for (i = 0; i < 256; i++) {
          if (bin[i] == 0) {
            rangeStopL = i;
            break;
          }
        }
        for (i = 255; i >= 0; i--) {
          if (bin[i] == 0) {
            rangeStopH = i;
            break;
          }
        }
        if ((rangePassH - rangePassL) < (rangeStopH - rangeStopL)) {
          bandPassH.setState(true);
          bandStopH.setState(false);
          iminhue = rangePassL;
          imaxhue = rangePassH;
        } else {
          bandPassH.setState(false);
          bandStopH.setState(true);
          iminhue = rangeStopL;
          imaxhue = rangeStopH;
        }
      } else {
        bandPassH.setState(true);
        bandStopH.setState(false);
      }

      adjustMinHue(iminhue);
      minSlider.setValue(iminhue);
      adjustMaxHue(imaxhue);
      maxSlider.setValue(imaxhue);
      adjustMinSat(iminsat);
      minSlider2.setValue(iminsat);
      adjustMaxSat(imaxsat);
      maxSlider2.setValue(imaxsat);
      adjustMinBri(iminbri);
      minSlider3.setValue(iminbri);
      adjustMaxBri(imaxbri);
      maxSlider3.setValue(imaxbri);
      originalB.setEnabled(true);
      // IJ.showStatus("done");
    }
示例#21
0
    ImageProcessor setup(ImagePlus imp) {

      ImageProcessor ip;
      int type = imp.getType();
      if (type != ImagePlus.COLOR_RGB) return null;
      ip = imp.getProcessor();
      int id = imp.getID();
      int slice = imp.getCurrentSlice();

      if ((id != previousImageID) | (slice != previousSlice) | (flag)) {
        flag = false; // if true, flags a change from HSB to RGB or viceversa
        numSlices = imp.getStackSize();
        stack = imp.getStack();
        width = stack.getWidth();
        height = stack.getHeight();
        numPixels = width * height;

        hSource = new byte[numPixels];
        sSource = new byte[numPixels];
        bSource = new byte[numPixels];

        // restore = (int[])ip.getPixelsCopy(); //This runs into trouble sometimes, so do it the
        // long way:
        int[] temp = (int[]) ip.getPixels();
        restore = new int[numPixels];
        for (int i = 0; i < numPixels; i++) restore[i] = temp[i];

        fillMask = new int[numPixels];

        // Get hsb or rgb from image.
        ColorProcessor cp = (ColorProcessor) ip;
        IJ.showStatus("Gathering data");

        if (isRGB) cp.getRGB(hSource, sSource, bSource);
        else cp.getHSB(hSource, sSource, bSource);

        IJ.showStatus("done");

        // Create a spectrum ColorModel for the Hue histogram plot.
        Color c;
        byte[] reds = new byte[256];
        byte[] greens = new byte[256];
        byte[] blues = new byte[256];
        for (int i = 0; i < 256; i++) {
          c = Color.getHSBColor(i / 255f, 1f, 1f);

          reds[i] = (byte) c.getRed();
          greens[i] = (byte) c.getGreen();
          blues[i] = (byte) c.getBlue();
        }
        ColorModel cm = new IndexColorModel(8, 256, reds, greens, blues);

        // Make an image with just the hue from the RGB image and the spectrum LUT.
        // This is just for a hue histogram for the plot.  Do not show it.
        // ByteProcessor bpHue = new ByteProcessor(width,height,h,cm);
        ByteProcessor bpHue = new ByteProcessor(width, height, hSource, cm);
        ImagePlus impHue = new ImagePlus("Hue", bpHue);
        // impHue.show();

        ByteProcessor bpSat = new ByteProcessor(width, height, sSource, cm);
        ImagePlus impSat = new ImagePlus("Sat", bpSat);
        // impSat.show();

        ByteProcessor bpBri = new ByteProcessor(width, height, bSource, cm);
        ImagePlus impBri = new ImagePlus("Bri", bpBri);
        // impBri.show();

        plot.setHistogram(impHue, 0);
        splot.setHistogram(impSat, 1);
        bplot.setHistogram(impBri, 2);

        updateLabels();
        updatePlot();
        updateScrollBars();
        imp.updateAndDraw();
      }
      previousImageID = id;
      previousSlice = slice;
      return ip;
    }
  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();
  }
示例#23
0
 public void drawImage(Image img, int x, int y) {
   ColorProcessor cp2 = new ColorProcessor(img);
   cp.copyBits(cp2, x, y, Blitter.COPY);
 }
示例#24
0
 public void setFont(Font font) {
   cp.setFont(font);
 }
示例#25
0
 public void setColor(Color color) {
   cp.setColor(color);
   this.color = color;
 }
示例#26
0
 public void setAntiAliasedText(boolean antialias) {
   cp.setAntialiasedText(antialias);
   this.antialias = true;
 }
示例#27
0
 public void drawString(String string, int x, int y) {
   cp.drawString(string, x, y);
 }
示例#28
0
 public void setClipRect(int x, int y, int width, int height) {
   clip = new Rectangle(x, y, width, height);
   cp.setClipRect(clip);
 }
  public void run(ImageProcessor ip) {
    ImageUtils.initMMorph4J();

    if (ip instanceof ByteProcessor) {
      GrayScaleImage img = ImageJAdapter.toGrayScaleImage((ByteProcessor) ip);

      Object obj[] = BuilderTreeOfShapeByUnionFindParallel.getImageInterpolate(img);
      short interpolation0[] = (short[]) obj[0];
      short interpolation1[] = (short[]) obj[1];

      int interpWidth = (img.getWidth() * 4 - 3);
      int interpHeight = (img.getHeight() * 4 - 3);

      ByteProcessor imgOut0 = new ByteProcessor(interpWidth, interpHeight);
      ByteProcessor imgOut1 = new ByteProcessor(interpWidth, interpHeight);

      for (int i = 0; i < interpolation0.length; i++) {
        // imgOut.setPixel(i, (interpolation0[i] + interpolation1[i]) / 2);
        imgOut0.set(i, (interpolation0[i] & 0xFF));
        imgOut1.set(i, (interpolation1[i] & 0xFF));
      }

      ImagePlus imgPlus0 = new ImagePlus("interpolation - max", imgOut0);
      imgPlus0.show("image interpolation - max");
      ImagePlus imgPlus1 = new ImagePlus("interpolation - min", imgOut1);
      imgPlus1.show("image interpolation - min");
    } else if (ip instanceof ColorProcessor) {
      ColorImage img = ImageJAdapter.toColorImage((ColorProcessor) ip);

      int interpWidth = (img.getWidth() * 4 - 3);
      int interpHeight = (img.getHeight() * 4 - 3);

      GrayScaleImage imgR = img.getRed();
      GrayScaleImage imgG = img.getGreen();
      GrayScaleImage imgB = img.getBlue();

      ColorProcessor imgOut0 = new ColorProcessor(interpWidth, interpHeight);
      ColorProcessor imgOut1 = new ColorProcessor(interpWidth, interpHeight);

      Object objR[] = BuilderTreeOfShapeByUnionFindParallel.getImageInterpolate(imgR);
      short interpolation0R[] = (short[]) objR[0];
      short interpolation1R[] = (short[]) objR[1];

      Object objG[] = BuilderTreeOfShapeByUnionFindParallel.getImageInterpolate(imgG);
      short interpolation0G[] = (short[]) objG[0];
      short interpolation1G[] = (short[]) objG[1];

      Object objB[] = BuilderTreeOfShapeByUnionFindParallel.getImageInterpolate(imgB);
      short interpolation0B[] = (short[]) objB[0];
      short interpolation1B[] = (short[]) objB[1];

      for (int i = 0; i < interpolation0R.length; i++) {

        int valor0 =
            ((0 & 0xFF) << 24)
                | ((interpolation0R[i] & 0xFF) << 16)
                | ((interpolation0G[i] & 0xFF) << 8)
                | ((interpolation0B[i] & 0xFF) << 0);

        imgOut0.set(i, valor0);

        int valor1 =
            ((0 & 0xFF) << 24)
                | ((interpolation1R[i] & 0xFF) << 16)
                | ((interpolation1G[i] & 0xFF) << 8)
                | ((interpolation1B[i] & 0xFF) << 0);
        imgOut1.set(i, valor1);
      }

      ImagePlus imgPlus0 = new ImagePlus("interpolation - max", imgOut0);
      imgPlus0.show("image interpolation - max");
      ImagePlus imgPlus1 = new ImagePlus("interpolation - min", imgOut1);
      imgPlus1.show("image interpolation - min");
    }
  }
示例#30
0
 public ColorHistogram(ColorProcessor ip) {
   this((int[]) ip.getPixels());
 }