Esempio n. 1
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;
  }
Esempio n. 2
0
 public CompositeImage(ImagePlus imp, int mode) {
   if (mode < COMPOSITE || mode > GRAYSCALE) mode = COLOR;
   this.mode = mode;
   int channels = imp.getNChannels();
   bitDepth = getBitDepth();
   if (IJ.debugMode) IJ.log("CompositeImage: " + imp + " " + mode + " " + channels);
   ImageStack stack2;
   boolean isRGB = imp.getBitDepth() == 24;
   if (isRGB) {
     if (imp.getImageStackSize() > 1)
       throw new IllegalArgumentException("RGB stacks not supported");
     stack2 = getRGBStack(imp);
   } else stack2 = imp.getImageStack();
   int stackSize = stack2.getSize();
   if (channels == 1 && isRGB) channels = 3;
   if (channels == 1 && stackSize <= MAX_CHANNELS && !imp.dimensionsSet) channels = stackSize;
   if (channels < 1 || (stackSize % channels) != 0)
     throw new IllegalArgumentException("stacksize not multiple of channels");
   if (mode == COMPOSITE && channels > MAX_CHANNELS) this.mode = COLOR;
   compositeImage = true;
   int z = imp.getNSlices();
   int t = imp.getNFrames();
   if (channels == stackSize || channels * z * t != stackSize)
     setDimensions(channels, stackSize / channels, 1);
   else setDimensions(channels, z, t);
   setStack(imp.getTitle(), stack2);
   setCalibration(imp.getCalibration());
   FileInfo fi = imp.getOriginalFileInfo();
   if (fi != null) {
     displayRanges = fi.displayRanges;
     channelLuts = fi.channelLuts;
   }
   setFileInfo(fi);
   Object info = imp.getProperty("Info");
   if (info != null) setProperty("Info", imp.getProperty("Info"));
   if (mode == COMPOSITE) {
     for (int i = 0; i < MAX_CHANNELS; i++) active[i] = true;
   } else active[0] = true;
   // if (!(channels==3&&stackSize==3))
   setRoi(imp.getRoi());
   setOverlay(imp.getOverlay());
   if (channels != stackSize) setOpenAsHyperStack(true);
 }