コード例 #1
0
ファイル: Channels.java プロジェクト: hellotod/HadoopLung
 public void update() {
   CompositeImage ci = getImage();
   if (ci == null || checkbox == null) return;
   int n = checkbox.length;
   int nChannels = ci.getNChannels();
   if (nChannels != n && nChannels <= CompositeImage.MAX_CHANNELS) {
     instance = null;
     location = getLocation();
     close();
     new Channels();
     return;
   }
   boolean[] active = ci.getActiveChannels();
   for (int i = 0; i < checkbox.length; i++) checkbox[i].setState(active[i]);
   int index = 0;
   switch (ci.getMode()) {
     case IJ.COMPOSITE:
       index = 0;
       break;
     case IJ.COLOR:
       index = 1;
       break;
     case IJ.GRAYSCALE:
       index = 2;
       break;
   }
   choice.select(index);
 }
コード例 #2
0
ファイル: Channels.java プロジェクト: hellotod/HadoopLung
  public Channels() {
    super("Channels");
    if (instance != null) {
      instance.toFront();
      return;
    }
    WindowManager.addWindow(this);
    instance = this;
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    setLayout(gridbag);
    int y = 0;
    c.gridx = 0;
    c.gridy = y++;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.BOTH;
    c.anchor = GridBagConstraints.CENTER;
    int margin = 32;
    if (IJ.isMacOSX()) margin = 20;
    c.insets = new Insets(10, margin, 10, margin);
    choice = new Choice();
    for (int i = 0; i < modes.length; i++) choice.addItem(modes[i]);
    choice.select(0);
    choice.addItemListener(this);
    add(choice, c);

    CompositeImage ci = getImage();
    int nCheckBoxes = ci != null ? ci.getNChannels() : 3;
    if (nCheckBoxes > CompositeImage.MAX_CHANNELS) nCheckBoxes = CompositeImage.MAX_CHANNELS;
    checkbox = new Checkbox[nCheckBoxes];
    for (int i = 0; i < nCheckBoxes; i++) {
      checkbox[i] = new Checkbox("Channel " + (i + 1), true);
      c.insets = new Insets(0, 25, i < nCheckBoxes - 1 ? 0 : 10, 5);
      c.gridy = y++;
      add(checkbox[i], c);
      checkbox[i].addItemListener(this);
    }

    c.insets = new Insets(0, 15, 10, 15);
    c.fill = GridBagConstraints.NONE;
    c.gridy = y++;
    moreButton = new Button(moreLabel);
    moreButton.addActionListener(this);
    add(moreButton, c);
    update();

    pm = new PopupMenu();
    for (int i = 0; i < menuItems.length; i++) addPopupItem(menuItems[i]);
    add(pm);

    addKeyListener(IJ.getInstance()); // ImageJ handles keyboard shortcuts
    setResizable(false);
    pack();
    if (location == null) {
      GUI.center(this);
      location = getLocation();
    } else setLocation(location);
    show();
  }
コード例 #3
0
ファイル: ZProjector.java プロジェクト: halirutan/imagej1
 public void doHyperStackProjection(boolean allTimeFrames) {
   int start = startSlice;
   int stop = stopSlice;
   int firstFrame = 1;
   int lastFrame = imp.getNFrames();
   if (!allTimeFrames) firstFrame = lastFrame = imp.getFrame();
   ImageStack stack = new ImageStack(imp.getWidth(), imp.getHeight());
   int channels = imp.getNChannels();
   int slices = imp.getNSlices();
   if (slices == 1) {
     slices = imp.getNFrames();
     firstFrame = lastFrame = 1;
   }
   int frames = lastFrame - firstFrame + 1;
   increment = channels;
   boolean rgb = imp.getBitDepth() == 24;
   for (int frame = firstFrame; frame <= lastFrame; frame++) {
     for (int channel = 1; channel <= channels; channel++) {
       startSlice = (frame - 1) * channels * slices + (start - 1) * channels + channel;
       stopSlice = (frame - 1) * channels * slices + (stop - 1) * channels + channel;
       if (rgb) doHSRGBProjection(imp);
       else doProjection();
       stack.addSlice(null, projImage.getProcessor());
     }
   }
   projImage = new ImagePlus(makeTitle(), stack);
   projImage.setDimensions(channels, 1, frames);
   if (channels > 1) {
     projImage = new CompositeImage(projImage, 0);
     ((CompositeImage) projImage).copyLuts(imp);
     if (method == SUM_METHOD || method == SD_METHOD)
       ((CompositeImage) projImage).resetDisplayRanges();
   }
   if (frames > 1) projImage.setOpenAsHyperStack(true);
   Overlay overlay = imp.getOverlay();
   if (overlay != null) {
     startSlice = start;
     stopSlice = stop;
     if (imp.getType() == ImagePlus.COLOR_RGB)
       projImage.setOverlay(projectRGBHyperStackRois(overlay));
     else projImage.setOverlay(projectHyperStackRois(overlay));
   }
   IJ.showProgress(1, 1);
 }
コード例 #4
0
ファイル: Scaler.java プロジェクト: BinRoot/Photometer
 void createNewStack(ImagePlus imp, ImageProcessor ip) {
   int nSlices = imp.getStackSize();
   int w = imp.getWidth(), h = imp.getHeight();
   ImagePlus imp2 = imp.createImagePlus();
   Rectangle r = ip.getRoi();
   boolean crop = r.width != imp.getWidth() || r.height != imp.getHeight();
   ImageStack stack1 = imp.getStack();
   ImageStack stack2 = new ImageStack(newWidth, newHeight);
   ImageProcessor ip1, ip2;
   int method = interpolationMethod;
   if (w == 1 || h == 1) method = ImageProcessor.NONE;
   for (int i = 1; i <= nSlices; i++) {
     IJ.showStatus("Scale: " + i + "/" + nSlices);
     ip1 = stack1.getProcessor(i);
     String label = stack1.getSliceLabel(i);
     if (crop) {
       ip1.setRoi(r);
       ip1 = ip1.crop();
     }
     ip1.setInterpolationMethod(method);
     ip2 = ip1.resize(newWidth, newHeight, averageWhenDownsizing);
     if (ip2 != null) stack2.addSlice(label, ip2);
     IJ.showProgress(i, nSlices);
   }
   imp2.setStack(title, stack2);
   Calibration cal = imp2.getCalibration();
   if (cal.scaled()) {
     cal.pixelWidth *= 1.0 / xscale;
     cal.pixelHeight *= 1.0 / yscale;
   }
   IJ.showProgress(1.0);
   int[] dim = imp.getDimensions();
   imp2.setDimensions(dim[2], dim[3], dim[4]);
   if (imp.isComposite()) {
     imp2 = new CompositeImage(imp2, ((CompositeImage) imp).getMode());
     ((CompositeImage) imp2).copyLuts(imp);
   }
   if (imp.isHyperStack()) imp2.setOpenAsHyperStack(true);
   if (newDepth > 0 && newDepth != oldDepth)
     imp2 = (new Resizer()).zScale(imp2, newDepth, interpolationMethod);
   if (imp2 != null) {
     imp2.show();
     imp2.changes = true;
   }
 }
コード例 #5
0
ファイル: Scaler.java プロジェクト: TaihaoJin/ImgSigJ
 void createNewStack(ImagePlus imp, ImageProcessor ip) {
   Rectangle r = ip.getRoi();
   boolean crop = r.width != imp.getWidth() || r.height != imp.getHeight();
   int nSlices = imp.getStackSize();
   ImageStack stack1 = imp.getStack();
   ImageStack stack2 = new ImageStack(newWidth, newHeight);
   ImageProcessor ip1, ip2;
   boolean interp = interpolate;
   if (imp.getWidth() == 1 || imp.getHeight() == 1) interp = false;
   for (int i = 1; i <= nSlices; i++) {
     IJ.showStatus("Scale: " + i + "/" + nSlices);
     ip1 = stack1.getProcessor(i);
     String label = stack1.getSliceLabel(i);
     if (crop) {
       ip1.setRoi(r);
       ip1 = ip1.crop();
     }
     ip1.setInterpolate(interp);
     ip2 = ip1.resize(newWidth, newHeight);
     if (ip2 != null) stack2.addSlice(label, ip2);
     IJ.showProgress(i, nSlices);
   }
   ImagePlus imp2 = imp.createImagePlus();
   imp2.setStack(title, stack2);
   Calibration cal = imp2.getCalibration();
   if (cal.scaled()) {
     cal.pixelWidth *= 1.0 / xscale;
     cal.pixelHeight *= 1.0 / yscale;
   }
   int[] dim = imp.getDimensions();
   imp2.setDimensions(dim[2], dim[3], dim[4]);
   IJ.showProgress(1.0);
   if (imp.isComposite()) {
     imp2 = new CompositeImage(imp2, 0);
     ((CompositeImage) imp2).copyLuts(imp);
   }
   if (imp.isHyperStack()) imp2.setOpenAsHyperStack(true);
   imp2.show();
   imp2.changes = true;
 }
コード例 #6
0
 public void run(String arg) {
   String[] labels = {
     "Masked_Chromosomes", "Unmixed_Image", "Spectral_Image(optional)", "Spectra(optional)"
   };
   ImagePlus[] imps = jutils.selectImages(true, 4, labels);
   if (imps == null) {
     return;
   }
   if (imps[0] == null) {
     return;
   }
   float[] mask = (float[]) imps[0].getStack().getPixels(2);
   findblobs3 fb = new findblobs3(imps[0].getWidth(), imps[0].getHeight());
   float[] objects = fb.dofindblobs(mask, 0.5f);
   WaitForUserDialog dg =
       new WaitForUserDialog(
           "Optional Input", "Place RoiManager Points on Chromosome Segments (if desired)");
   dg.show();
   if (!dg.escPressed()) {
     RoiManager rman = RoiManager.getInstance();
     while (rman != null && rman.getCount() > 1) {
       Roi[] rois = rman.getRoisAsArray();
       int[] ids = new int[rois.length];
       for (int i = 0; i < rois.length; i++) {
         Rectangle r = rois[i].getBounds();
         ids[i] = (int) objects[r.x + fb.width * r.y];
       }
       objects = fb.link_objects(objects, ids);
       rman.reset();
       dg =
           new WaitForUserDialog(
               "Optional Input",
               "Place More RoiManager Points on Chromosome Segments (if desired)");
       dg.show();
       if (dg.escPressed()) break;
     }
   }
   int[] areas = fb.get_areas(objects);
   int[] temprank = jsort.get_javasort_order(areas);
   int[] arearank = jsort.get_javasort_order(temprank);
   for (int i = 0; i < fb.nobjects; i++) {
     arearank[i] = fb.nobjects - arearank[i] - 1;
   }
   // if the spectra are available, get them
   float[][][] spectra = null;
   Object[] data = null;
   if (imps[1] != null && imps[2] != null && imps[3] != null) {
     ImageWindow iw = imps[3].getWindow();
     if (iw.getClass().getName().equals("jguis.PlotWindow4")) {
       float[][] yvals = (float[][]) jutils.runPW4VoidMethod(iw, "getYValues");
       data = jutils.stack2array(imps[2].getStack());
       Object[] coef = jutils.stack2array(imps[1].getStack());
       spectra = new float[fb.nobjects][2][];
       for (int i = 0; i < fb.nobjects; i++) {
         spectra[i][0] = fb.get_object_spectrum(objects, (i + 1), data, "Sum");
         spectra[i][1] = new float[yvals[0].length];
         float[] tempcoef = fb.get_object_spectrum(objects, (i + 1), coef, "Sum");
         for (int j = 0; j < yvals[0].length; j++) {
           for (int k = 0; k < 5; k++) {
             spectra[i][1][j] += tempcoef[k] * yvals[k][j];
           }
         }
       }
     }
   }
   CompositeImage imp = (CompositeImage) imps[0];
   imp.setPosition(1, 1, 1);
   LUT graylut = jutils.get_lut_for_color(Color.white);
   imp.setChannelColorModel(graylut);
   imp.setPosition(2, 1, 1);
   LUT redlut = jutils.get_lut_for_color(Color.red);
   imp.setChannelColorModel(redlut);
   imp.setPosition(1, 1, 1);
   imp.updateAndRepaintWindow();
   SkyPanel_v3 sp = new SkyPanel_v3();
   int skychan = 6;
   if (imps[1] != null) skychan = imps[1].getNChannels();
   // assume that the sky image has 6 channels and that the second is the unknown green
   // shift the unknown green to the end
   ImagePlus skyimp = null;
   if (imps[1] != null) {
     Object[] skystack = jutils.stack2array(imps[1].getStack());
     // Object[]
     // skystack2={skystack[0],skystack[2],skystack[3],skystack[4],skystack[5],skystack[1]};
     Object[] skystack2 = null;
     if (skychan == 6)
       skystack2 = new Object[] {skystack[0], skystack[2], skystack[3], skystack[4], skystack[5]};
     else
       skystack2 = new Object[] {skystack[0], skystack[1], skystack[2], skystack[3], skystack[4]};
     skyimp =
         new ImagePlus(
             "rearranged", jutils.array2stack(skystack2, imps[1].getWidth(), imps[1].getHeight()));
   }
   int nch = 5;
   if (skyimp != null) nch = skyimp.getStack().getSize();
   GenericDialog gd2 = new GenericDialog("Options");
   gd2.addNumericField("Area Accuracy (percent)", 30, 0);
   for (int i = 0; i < nch; i++) {
     gd2.addNumericField("Ch_" + (i + 1) + "_Contr_Thresh", 0.35, 5, 15, null);
   }
   // gd2.addNumericField("Contribution Threshold",0.35,5,15,null);
   gd2.addCheckbox("Mouse?", false);
   gd2.addNumericField("Box_Width", 150, 0);
   gd2.addNumericField("Box_Height", 100, 0);
   gd2.showDialog();
   if (gd2.wasCanceled()) {
     return;
   }
   sp.areathresh = (float) gd2.getNextNumber();
   sp.objthresh2 = new float[nch];
   for (int i = 0; i < nch; i++) sp.objthresh2[i] = (float) gd2.getNextNumber();
   // sp.objthresh=(float)gd2.getNextNumber();
   boolean mouse = gd2.getNextBoolean();
   int bwidth = (int) gd2.getNextNumber();
   int bheight = (int) gd2.getNextNumber();
   int[] colorindices = {4, 1, 2, 6, 3};
   GenericDialog gd3 = new GenericDialog("Color Options");
   for (int i = 0; i < 5; i++)
     gd3.addChoice(
         "Ch" + (i + 1) + " Color",
         SkyPanel_v3.colornames,
         SkyPanel_v3.colornames[colorindices[i]]);
   gd3.showDialog();
   if (gd3.wasCanceled()) return;
   for (int i = 0; i < 5; i++) colorindices[i] = gd3.getNextChoiceIndex();
   sp.colorindices = colorindices;
   sp.nch = 5;
   sp.dapilast = false;
   sp.cellwidth = bwidth;
   sp.cellheight = bheight;
   sp.init(imps[0], skyimp, objects, areas, arearank, fb, true, spectra, data, mouse);
   SkyPanel_v3.launch_frame(sp);
 }
コード例 #7
0
ファイル: Channels.java プロジェクト: hellotod/HadoopLung
 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;
       }
     }
   }
 }