Exemple #1
0
 private void doRGBProjection(ImageStack stack) {
   ImageStack[] channels = ChannelSplitter.splitRGB(stack, true);
   ImagePlus red = new ImagePlus("Red", channels[0]);
   ImagePlus green = new ImagePlus("Green", channels[1]);
   ImagePlus blue = new ImagePlus("Blue", channels[2]);
   imp.unlock();
   ImagePlus saveImp = imp;
   imp = red;
   color = "(red)";
   doProjection();
   ImagePlus red2 = projImage;
   imp = green;
   color = "(green)";
   doProjection();
   ImagePlus green2 = projImage;
   imp = blue;
   color = "(blue)";
   doProjection();
   ImagePlus blue2 = projImage;
   int w = red2.getWidth(), h = red2.getHeight(), d = red2.getStackSize();
   if (method == SD_METHOD) {
     ImageProcessor r = red2.getProcessor();
     ImageProcessor g = green2.getProcessor();
     ImageProcessor b = blue2.getProcessor();
     double max = 0;
     double rmax = r.getStatistics().max;
     if (rmax > max) max = rmax;
     double gmax = g.getStatistics().max;
     if (gmax > max) max = gmax;
     double bmax = b.getStatistics().max;
     if (bmax > max) max = bmax;
     double scale = 255 / max;
     r.multiply(scale);
     g.multiply(scale);
     b.multiply(scale);
     red2.setProcessor(r.convertToByte(false));
     green2.setProcessor(g.convertToByte(false));
     blue2.setProcessor(b.convertToByte(false));
   }
   RGBStackMerge merge = new RGBStackMerge();
   ImageStack stack2 =
       merge.mergeStacks(w, h, d, red2.getStack(), green2.getStack(), blue2.getStack(), true);
   imp = saveImp;
   projImage = new ImagePlus(makeTitle(), stack2);
 }
Exemple #2
0
  /** Update the result overlay with the current matrix of confidence */
  private void updateResult() {
    imp.killRoi();
    roiOverlay.setRoi(null);

    ImageProcessor cp = confMatrix.convertToRGB();
    cp.multiply(1.0 / 255.0);
    cp.copyBits(ip, 0, 0, Blitter.MULTIPLY);

    resultOverlay.setImage(cp);

    imp.changes = true;
    imp.updateAndDraw();
  }
Exemple #3
0
  /**
   * Divide pixel values of a selected image in a hyperstack by a corresponding single number
   *
   * @param a
   * @param b
   * @return
   */
  public static ImagePlus divide(
      ImagePlus a, double b, int slices[], int frames[], int channels[]) {
    int sizes[] = a.getDimensions();

    // Zero index --> keep all indices
    if (slices.length == 1 && slices[0] == 0) {
      slices = Commons.getSequence(1, sizes[3]);
    }
    if (frames.length == 1 && frames[0] == 0) {
      frames = Commons.getSequence(1, sizes[4]);
    }
    if (channels.length == 1 && channels[0] == 0) {
      channels = Commons.getSequence(1, sizes[2]);
    }

    // Check input arguments
    if ((Commons.getMin(slices) < 1) || (Commons.getMax(slices) > sizes[3])) {
      System.out.println("Subscripts for slices out of bounds.");
      return a;
    }
    if ((Commons.getMin(frames) < 1) || (Commons.getMax(frames) > sizes[4])) {
      System.out.println("Subscripts for frames out of bounds.");
      return a;
    }
    if ((Commons.getMin(channels) < 1) || (Commons.getMax(channels) > sizes[2])) {
      System.out.println("Subscripts for channels out of bounds.");
      return a;
    }

    Duplicator dp = new Duplicator();
    ImagePlus c = dp.run(a);

    for (int i = 0; i < slices.length; i++) {
      for (int j = 0; j < frames.length; j++) {
        for (int k = 0; k < channels.length; k++) {
          c.setPosition(channels[k], slices[i], frames[j]);
          ImageProcessor ip = c.getProcessor();
          if (b != 0.0) {
            ip.multiply(1 / b);
          } else {
            ip = new FloatProcessor(c.getWidth(), c.getHeight());
            c.setProcessor(ip);
          }
        }
      }
    }
    return (c);
  }
  void Phansalkar(ImagePlus imp, int radius, double par1, double par2, boolean doIwhite) {
    // This is a modification of Sauvola's thresholding method to deal with low contrast images.
    // Phansalskar N. et al. Adaptive local thresholding for detection of nuclei in diversity
    // stained
    // cytology images.International Conference on Communications and Signal Processing (ICCSP),
    // 2011,
    // 218 - 220.
    // In this method, the threshold t = mean*(1+p*exp(-q*mean)+k*((stdev/r)-1))
    // Phansalkar recommends k = 0.25, r = 0.5, p = 2 and q = 10. In this plugin, k and r are the
    // parameters 1 and 2 respectively, but the values of p and q are fixed.
    //
    // Implemented from Phansalkar's paper description by G. Landini
    // This version uses a circular local window, instead of a rectagular one

    ImagePlus Meanimp, Varimp, Orimp;
    ImageProcessor ip = imp.getProcessor(), ipMean, ipVar, ipOri;
    double k_value = 0.25;
    double r_value = 0.5;
    double p_value = 2.0;
    double q_value = 10.0;
    byte object;
    byte backg;

    if (par1 != 0) {
      IJ.log("Phansalkar: changed k_value from :" + k_value + "  to:" + par1);
      k_value = par1;
    }

    if (par2 != 0) {
      IJ.log("Phansalkar: changed r_value from :" + r_value + "  to:" + par2);
      r_value = par2;
    }

    if (doIwhite) {
      object = (byte) 0xff;
      backg = (byte) 0;
    } else {
      object = (byte) 0;
      backg = (byte) 0xff;
    }

    Meanimp = duplicateImage(ip);
    ContrastEnhancer ce = new ContrastEnhancer();
    ce.stretchHistogram(Meanimp, 0.0);
    ImageConverter ic = new ImageConverter(Meanimp);
    ic.convertToGray32();
    ipMean = Meanimp.getProcessor();
    ipMean.multiply(1.0 / 255);

    Orimp = duplicateImage(ip);
    ce.stretchHistogram(Orimp, 0.0);
    ic = new ImageConverter(Orimp);
    ic.convertToGray32();
    ipOri = Orimp.getProcessor();
    ipOri.multiply(1.0 / 255); // original to compare
    // Orimp.show();

    RankFilters rf = new RankFilters();
    rf.rank(ipMean, radius, rf.MEAN); // Mean

    // Meanimp.show();
    Varimp = duplicateImage(ip);
    ce.stretchHistogram(Varimp, 0.0);
    ic = new ImageConverter(Varimp);
    ic.convertToGray32();
    ipVar = Varimp.getProcessor();
    ipVar.multiply(1.0 / 255);

    rf.rank(ipVar, radius, rf.VARIANCE); // Variance
    ipVar.sqr(); // SD

    // Varimp.show();
    byte[] pixels = (byte[]) ip.getPixels();
    float[] ori = (float[]) ipOri.getPixels();
    float[] mean = (float[]) ipMean.getPixels();
    float[] sd = (float[]) ipVar.getPixels();

    for (int i = 0; i < pixels.length; i++)
      pixels[i] =
          ((ori[i])
                  > (mean[i]
                      * (1.0
                          + p_value * Math.exp(-q_value * mean[i])
                          + k_value * ((sd[i] / r_value) - 1.0))))
              ? object
              : backg;
    // imp.updateAndDraw();
    return;
  }