void drawAllROIs(Graphics g) { RoiManager rm = RoiManager.getInstance(); if (rm == null) { rm = Interpreter.getBatchModeRoiManager(); if (rm != null && rm.getList().getItemCount() == 0) rm = null; } if (rm == null) { // if (showAllList!=null) // overlay = showAllList; showAllROIs = false; repaint(); return; } initGraphics(g, null, showAllColor); Hashtable rois = rm.getROIs(); java.awt.List list = rm.getList(); boolean drawLabels = rm.getDrawLabels(); currentRoi = null; int n = list.getItemCount(); if (IJ.debugMode) IJ.log("paint: drawing " + n + " \"Show All\" ROIs"); if (labelRects == null || labelRects.length != n) labelRects = new Rectangle[n]; if (!drawLabels) showAllList = new Overlay(); else showAllList = null; if (imp == null) return; int currentImage = imp.getCurrentSlice(); int channel = 0, slice = 0, frame = 0; boolean hyperstack = imp.isHyperStack(); if (hyperstack) { channel = imp.getChannel(); slice = imp.getSlice(); frame = imp.getFrame(); } drawNames = Prefs.useNamesAsLabels; for (int i = 0; i < n; i++) { String label = list.getItem(i); Roi roi = (Roi) rois.get(label); if (roi == null) continue; if (showAllList != null) showAllList.add(roi); if (i < 200 && drawLabels && roi == imp.getRoi()) currentRoi = roi; if (Prefs.showAllSliceOnly && imp.getStackSize() > 1) { if (hyperstack && roi.getPosition() == 0) { int c = roi.getCPosition(); int z = roi.getZPosition(); int t = roi.getTPosition(); if ((c == 0 || c == channel) && (z == 0 || z == slice) && (t == 0 || t == frame)) drawRoi(g, roi, drawLabels ? i : -1); } else { int position = roi.getPosition(); if (position == 0) position = getSliceNumber(roi.getName()); if (position == 0 || position == currentImage) drawRoi(g, roi, drawLabels ? i : -1); } } else drawRoi(g, roi, drawLabels ? i : -1); } ((Graphics2D) g).setStroke(Roi.onePixelWide); drawNames = false; }
public StackWindow(ImagePlus imp, ImageCanvas ic) { super(imp, ic); addScrollbars(imp); addMouseWheelListener(this); if (sliceSelector == null && this.getClass().getName().indexOf("Image5D") != -1) sliceSelector = new Scrollbar(); // prevents Image5D from crashing // IJ.log(nChannels+" "+nSlices+" "+nFrames); pack(); ic = imp.getCanvas(); if (ic != null) ic.setMaxBounds(); show(); int previousSlice = imp.getCurrentSlice(); if (previousSlice > 1 && previousSlice <= imp.getStackSize()) imp.setSlice(previousSlice); else imp.setSlice(1); thread = new Thread(this, "zSelector"); thread.start(); }
public void run(String arg) { imp = IJ.getImage(); if (imp == null) return; stackSize = imp.getStackSize(); Roi roi = imp.getRoi(); Calibration cal = imp.getCalibration(); if (roi != null && roi.getBounds().equals(prevRoi) && cal.pixelWidth == prevPixelWidth) roi = null; if (roi != null) { boolean rectOrOval = roi != null && (roi.getType() == Roi.RECTANGLE || roi.getType() == Roi.OVAL); oval = rectOrOval && (roi.getType() == Roi.OVAL); // Handle existing oval ROI Rectangle r = roi.getBounds(); width = r.width; height = r.height; xRoi = r.x; yRoi = r.y; if (scaledUnits && cal.scaled()) { xRoi = xRoi * cal.pixelWidth; yRoi = yRoi * cal.pixelHeight; width = width * cal.pixelWidth; height = height * cal.pixelHeight; } if (centered) { // Make xRoi and yRoi consistent when centered mode is active xRoi += width / 2.0; yRoi += height / 2.0; } } else if (!validDialogValues()) { width = imp.getWidth() / 2; height = imp.getHeight() / 2; xRoi = width / 2; yRoi = height / 2; } iSlice = imp.getCurrentSlice(); showDialog(); }
void drawOverlay(Graphics g) { if (imp != null && imp.getHideOverlay()) return; Color labelColor = overlay.getLabelColor(); if (labelColor == null) labelColor = Color.white; initGraphics(g, labelColor, Roi.getColor()); int n = overlay.size(); if (IJ.debugMode) IJ.log("paint: drawing " + n + " ROI display list"); int currentImage = imp != null ? imp.getCurrentSlice() : -1; if (imp.getStackSize() == 1) currentImage = -1; int channel = 0, slice = 0, frame = 0; boolean hyperstack = imp.isHyperStack(); if (hyperstack) { channel = imp.getChannel(); slice = imp.getSlice(); frame = imp.getFrame(); } drawNames = overlay.getDrawNames(); boolean drawLabels = drawNames || overlay.getDrawLabels(); for (int i = 0; i < n; i++) { if (overlay == null) break; Roi roi = overlay.get(i); if (hyperstack && roi.getPosition() == 0) { int c = roi.getCPosition(); int z = roi.getZPosition(); int t = roi.getTPosition(); if ((c == 0 || c == channel) && (z == 0 || z == slice) && (t == 0 || t == frame)) drawRoi(g, roi, drawLabels ? i + LIST_OFFSET : -1); } else { int position = roi.getPosition(); if (position == 0 || position == currentImage) drawRoi(g, roi, drawLabels ? i + LIST_OFFSET : -1); } } ((Graphics2D) g).setStroke(Roi.onePixelWide); drawNames = false; }
boolean roiManagerSelect(int x, int y) { RoiManager rm = RoiManager.getInstance(); if (rm == null) return false; Hashtable rois = rm.getROIs(); java.awt.List list = rm.getList(); int n = list.getItemCount(); if (labelRects == null || labelRects.length != n) return false; boolean stackMode = imp != null && imp.getStackSize() > 1 && Prefs.showAllSliceOnly; for (int i = 0; i < n; i++) { if (labelRects[i] != null && labelRects[i].contains(x, y)) { if (stackMode) { int slice = getSliceNumber(list.getItem(i)); if (slice != imp.getCurrentSlice()) continue; } // rm.select(i); // this needs to run on a separate thread, at least on OS X // "update2" does not clone the ROI so the "Show All" // outline moves as the user moves the RO. new ij.macro.MacroRunner("roiManager('select', " + i + "); roiManager('update2');"); return true; } } return false; }
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; }