예제 #1
0
    void apply(ImagePlus imp, ImageProcessor ip) {
      // this.setCursor(wait);
      // IJ.showStatus("Bandpassing slice "+previousSlice);
      java.awt.Color col;

      if (invert.getState()) col = Toolbar.getForegroundColor();
      else col = Toolbar.getBackgroundColor();

      ip.setColor(col);

      int fill = ip.BLACK;
      int keep = 0;

      if (bandPassH.getState() && bandPassS.getState() && bandPassB.getState()) { // PPP All pass
        for (int j = 0; j < numPixels; j++) {
          int hue = hSource[j] & 0xff;
          int sat = sSource[j] & 0xff;
          int bri = bSource[j] & 0xff;
          if (((hue < minHue) || (hue > maxHue))
              || ((sat < minSat) || (sat > maxSat))
              || ((bri < minBri) || (bri > maxBri))) fillMask[j] = fill;
          else fillMask[j] = keep;
        }
      } else if (!bandPassH.getState()
          && !bandPassS.getState()
          && !bandPassB.getState()) { // SSS All stop
        for (int j = 0; j < numPixels; j++) {
          int hue = hSource[j] & 0xff;
          int sat = sSource[j] & 0xff;
          int bri = bSource[j] & 0xff;
          if (((hue >= minHue) && (hue <= maxHue))
              || ((sat >= minSat) && (sat <= maxSat))
              || ((bri >= minBri) && (bri <= maxBri))) fillMask[j] = fill;
          else fillMask[j] = keep;
        }
      } else if (bandPassH.getState() && bandPassS.getState() && !bandPassB.getState()) { // PPS
        for (int j = 0; j < numPixels; j++) {
          int hue = hSource[j] & 0xff;
          int sat = sSource[j] & 0xff;
          int bri = bSource[j] & 0xff;
          if (((hue < minHue) || (hue > maxHue))
              || ((sat < minSat) || (sat > maxSat))
              || ((bri >= minBri) && (bri <= maxBri))) fillMask[j] = fill;
          else fillMask[j] = keep;
        }
      } else if (!bandPassH.getState() && !bandPassS.getState() && bandPassB.getState()) { // SSP
        for (int j = 0; j < numPixels; j++) {
          int hue = hSource[j] & 0xff;
          int sat = sSource[j] & 0xff;
          int bri = bSource[j] & 0xff;
          if (((hue >= minHue) && (hue <= maxHue))
              || ((sat >= minSat) && (sat <= maxSat))
              || ((bri < minBri) || (bri > maxBri))) fillMask[j] = fill;
          else fillMask[j] = keep;
        }
      } else if (bandPassH.getState() && !bandPassS.getState() && !bandPassB.getState()) { // PSS
        for (int j = 0; j < numPixels; j++) {
          int hue = hSource[j] & 0xff;
          int sat = sSource[j] & 0xff;
          int bri = bSource[j] & 0xff;
          if (((hue < minHue) || (hue > maxHue))
              || ((sat >= minSat) && (sat <= maxSat))
              || ((bri >= minBri) && (bri <= maxBri))) fillMask[j] = fill;
          else fillMask[j] = keep;
        }
      } else if (!bandPassH.getState() && bandPassS.getState() && bandPassB.getState()) { // SPP
        for (int j = 0; j < numPixels; j++) {
          int hue = hSource[j] & 0xff;
          int sat = sSource[j] & 0xff;
          int bri = bSource[j] & 0xff;
          if (((hue >= minHue) && (hue <= maxHue))
              || ((sat < minSat) || (sat > maxSat))
              || ((bri < minBri) || (bri > maxBri))) fillMask[j] = fill;
          else fillMask[j] = keep;
        }
      } else if (!bandPassH.getState() && bandPassS.getState() && !bandPassB.getState()) { // SPS
        for (int j = 0; j < numPixels; j++) {
          int hue = hSource[j] & 0xff;
          int sat = sSource[j] & 0xff;
          int bri = bSource[j] & 0xff;
          if (((hue >= minHue) && (hue <= maxHue))
              || ((sat < minSat) || (sat > maxSat))
              || ((bri >= minBri) && (bri <= maxBri))) fillMask[j] = fill;
          else fillMask[j] = keep;
        }
      } else if (bandPassH.getState() && !bandPassS.getState() && bandPassB.getState()) { // PSP
        for (int j = 0; j < numPixels; j++) {
          int hue = hSource[j] & 0xff;
          int sat = sSource[j] & 0xff;
          int bri = bSource[j] & 0xff;
          if (((hue < minHue) || (hue > maxHue))
              || ((sat >= minSat) && (sat <= maxSat))
              || ((bri < minBri) || (bri > maxBri))) fillMask[j] = fill;
          else fillMask[j] = keep;
        }
      }

      ip.fill(fillMask);

      if (threshold.getState()) {
        ip.invert();
        for (int j = 0; j < numPixels; j++) {
          if (fillMask[j] == fill) fillMask[j] = keep;
          else fillMask[j] = fill;
        }
        ip.fill(fillMask);
        ip.invert();
      }
    }
예제 #2
0
 public void itemStateChanged(ItemEvent e) {
   ImagePlus imp = WindowManager.getCurrentImage();
   if (imp == null) return;
   if (!imp.isComposite()) {
     int channels = imp.getNChannels();
     if (channels == 1 && imp.getStackSize() <= 4) channels = imp.getStackSize();
     if (imp.getBitDepth() == 24 || (channels > 1 && channels < CompositeImage.MAX_CHANNELS)) {
       GenericDialog gd = new GenericDialog(imp.getTitle());
       gd.addMessage("Convert to multi-channel composite image?");
       gd.showDialog();
       if (gd.wasCanceled()) return;
       else IJ.doCommand("Make Composite");
     } else {
       IJ.error(
           "Channels",
           "A composite image is required (e.g., "
               + moreLabel
               + " Open HeLa Cells),\nor create one using "
               + moreLabel
               + " Make Composite.");
       return;
     }
   }
   if (!imp.isComposite()) return;
   CompositeImage ci = (CompositeImage) imp;
   Object source = e.getSource();
   if (source == choice) {
     int index = ((Choice) source).getSelectedIndex();
     switch (index) {
       case 0:
         ci.setMode(IJ.COMPOSITE);
         break;
       case 1:
         ci.setMode(IJ.COLOR);
         break;
       case 2:
         ci.setMode(IJ.GRAYSCALE);
         break;
     }
     ci.updateAndDraw();
     if (Recorder.record) {
       String mode = null;
       switch (index) {
         case 0:
           mode = "composite";
           break;
         case 1:
           mode = "color";
           break;
         case 2:
           mode = "grayscale";
           break;
       }
       Recorder.record("Stack.setDisplayMode", mode);
     }
   } else if (source instanceof Checkbox) {
     for (int i = 0; i < checkbox.length; i++) {
       Checkbox cb = (Checkbox) source;
       if (cb == checkbox[i]) {
         if (ci.getMode() == IJ.COMPOSITE) {
           boolean[] active = ci.getActiveChannels();
           active[i] = cb.getState();
           if (Recorder.record) {
             String str = "";
             for (int c = 0; c < ci.getNChannels(); c++) str += active[c] ? "1" : "0";
             Recorder.record("Stack.setActiveChannels", str);
             Recorder.record("//Stack.toggleChannel", imp.getChannel());
           }
         } else {
           imp.setPosition(i + 1, imp.getSlice(), imp.getFrame());
           if (Recorder.record) Recorder.record("Stack.setChannel", i + 1);
         }
         ci.updateAndDraw();
         return;
       }
     }
   }
 }