/** Called from io/Opener.java. */ public void run(String path) { if (path.equals("")) return; File theFile = new File(path); String directory = theFile.getParent(); String fileName = theFile.getName(); if (directory == null) directory = ""; // Try and recognise file type and load the file if recognised ImagePlus imp = openImage(directory, fileName, path); if (imp == null) { IJ.showStatus(""); return; // failed to load file or plugin has opened and displayed it } ImageStack stack = imp.getStack(); // get the title from the stack (falling back to the fileName) String title = imp.getTitle().equals("") ? fileName : imp.getTitle(); // set the stack of this HandleExtraFileTypes object // to that attached to the ImagePlus object returned by openImage() setStack(title, stack); // copy over the calibration info since it doesn't come with the ImageProcessor setCalibration(imp.getCalibration()); // also copy the Show Info field over if it exists if (imp.getProperty("Info") != null) setProperty("Info", imp.getProperty("Info")); // copy the FileInfo setFileInfo(imp.getOriginalFileInfo()); // copy dimensions if (IJ.getVersion().compareTo("1.38s") >= 0) setDimensions(imp.getNChannels(), imp.getNSlices(), imp.getNFrames()); if (IJ.getVersion().compareTo("1.41o") >= 0) setOpenAsHyperStack(imp.getOpenAsHyperStack()); }
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); }
public void run(ImageProcessor ip) { if (canceled) return; slice++; if (imp.getStackSize() > 1 && processStack) imp.setSlice(slice); if (imp.getType() == ImagePlus.COLOR_RGB) { ip = (ImageProcessor) imp.getProperty("Mask"); ip.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE); } if (!analyze(imp, ip)) canceled = true; if (slice == imp.getStackSize()) { imp.updateAndDraw(); if (saveRoi != null) imp.setRoi(saveRoi); } }
public String getImageInfo(ImagePlus imp, ImageProcessor ip) { String infoProperty = null; if (imp.getStackSize() > 1) { ImageStack stack = imp.getStack(); String label = stack.getSliceLabel(imp.getCurrentSlice()); if (label != null && label.indexOf('\n') > 0) infoProperty = label; } if (infoProperty == null) { infoProperty = (String) imp.getProperty("Info"); if (infoProperty == null) infoProperty = getExifData(imp); } String info = getInfo(imp, ip); if (infoProperty != null) return infoProperty + "\n------------------------\n" + info; else return info; }
/** * Performs particle analysis on the specified ImagePlus and ImageProcessor. Returns false if * there is an error. */ public boolean analyze(ImagePlus imp, ImageProcessor ip) { if (this.imp == null) this.imp = imp; showResults = (options & SHOW_RESULTS) != 0; excludeEdgeParticles = (options & EXCLUDE_EDGE_PARTICLES) != 0; resetCounter = (options & CLEAR_WORKSHEET) != 0; showProgress = (options & SHOW_PROGRESS) != 0; floodFill = (options & INCLUDE_HOLES) == 0; recordStarts = (options & RECORD_STARTS) != 0; addToManager = (options & ADD_TO_MANAGER) != 0; displaySummary = (options & DISPLAY_SUMMARY) != 0; inSituShow = (options & IN_SITU_SHOW) != 0; outputImage = null; ip.snapshot(); ip.setProgressBar(null); if (Analyzer.isRedirectImage()) { redirectImp = Analyzer.getRedirectImage(imp); if (redirectImp == null) return false; int depth = redirectImp.getStackSize(); if (depth > 1 && depth == imp.getStackSize()) { ImageStack redirectStack = redirectImp.getStack(); redirectIP = redirectStack.getProcessor(imp.getCurrentSlice()); } else redirectIP = redirectImp.getProcessor(); } else if (imp.getType() == ImagePlus.COLOR_RGB) { ImagePlus original = (ImagePlus) imp.getProperty("OriginalImage"); if (original != null && original.getWidth() == imp.getWidth() && original.getHeight() == imp.getHeight()) { redirectImp = original; redirectIP = original.getProcessor(); } } if (!setThresholdLevels(imp, ip)) return false; width = ip.getWidth(); height = ip.getHeight(); if (!(showChoice == NOTHING || showChoice == OVERLAY_OUTLINES || showChoice == OVERLAY_MASKS)) { blackBackground = Prefs.blackBackground && inSituShow; if (slice == 1) outlines = new ImageStack(width, height); if (showChoice == ROI_MASKS) drawIP = new ShortProcessor(width, height); else drawIP = new ByteProcessor(width, height); drawIP.setLineWidth(lineWidth); if (showChoice == ROI_MASKS) { } // Place holder for now... else if (showChoice == MASKS && !blackBackground) drawIP.invertLut(); else if (showChoice == OUTLINES) { if (!inSituShow) { if (customLut == null) makeCustomLut(); drawIP.setColorModel(customLut); } drawIP.setFont(new Font("SansSerif", Font.PLAIN, fontSize)); if (fontSize > 12 && inSituShow) drawIP.setAntialiasedText(true); } outlines.addSlice(null, drawIP); if (showChoice == ROI_MASKS || blackBackground) { drawIP.setColor(Color.black); drawIP.fill(); drawIP.setColor(Color.white); } else { drawIP.setColor(Color.white); drawIP.fill(); drawIP.setColor(Color.black); } } calibration = redirectImp != null ? redirectImp.getCalibration() : imp.getCalibration(); if (rt == null) { rt = Analyzer.getResultsTable(); analyzer = new Analyzer(imp); } else analyzer = new Analyzer(imp, measurements, rt); if (resetCounter && slice == 1) { if (!Analyzer.resetCounter()) return false; } beginningCount = Analyzer.getCounter(); byte[] pixels = null; if (ip instanceof ByteProcessor) pixels = (byte[]) ip.getPixels(); if (r == null) { r = ip.getRoi(); mask = ip.getMask(); if (displaySummary) { if (mask != null) totalArea = ImageStatistics.getStatistics(ip, AREA, calibration).area; else totalArea = r.width * calibration.pixelWidth * r.height * calibration.pixelHeight; } } minX = r.x; maxX = r.x + r.width; minY = r.y; maxY = r.y + r.height; if (r.width < width || r.height < height || mask != null) { if (!eraseOutsideRoi(ip, r, mask)) return false; } int offset; double value; int inc = Math.max(r.height / 25, 1); int mi = 0; ImageWindow win = imp.getWindow(); if (win != null) win.running = true; if (measurements == 0) measurements = Analyzer.getMeasurements(); if (showChoice == ELLIPSES) measurements |= ELLIPSE; measurements &= ~LIMIT; // ignore "Limit to Threshold" roiNeedsImage = (measurements & PERIMETER) != 0 || (measurements & SHAPE_DESCRIPTORS) != 0 || (measurements & FERET) != 0; particleCount = 0; wand = new Wand(ip); pf = new PolygonFiller(); if (floodFill) { ImageProcessor ipf = ip.duplicate(); ipf.setValue(fillColor); ff = new FloodFiller(ipf); } roiType = Wand.allPoints() ? Roi.FREEROI : Roi.TRACED_ROI; for (int y = r.y; y < (r.y + r.height); y++) { offset = y * width; for (int x = r.x; x < (r.x + r.width); x++) { if (pixels != null) value = pixels[offset + x] & 255; else if (imageType == SHORT) value = ip.getPixel(x, y); else value = ip.getPixelValue(x, y); if (value >= level1 && value <= level2) analyzeParticle(x, y, imp, ip); } if (showProgress && ((y % inc) == 0)) IJ.showProgress((double) (y - r.y) / r.height); if (win != null) canceled = !win.running; if (canceled) { Macro.abort(); break; } } if (showProgress) IJ.showProgress(1.0); if (showResults) rt.updateResults(); imp.killRoi(); ip.resetRoi(); ip.reset(); if (displaySummary && IJ.getInstance() != null) updateSliceSummary(); if (addToManager && roiManager != null) roiManager.setEditMode(imp, true); maxParticleCount = (particleCount > maxParticleCount) ? particleCount : maxParticleCount; totalCount += particleCount; if (!canceled) showResults(); return true; }
private boolean isThresholdedRGB(ImagePlus imp) { Object obj = imp.getProperty("Mask"); if (obj == null || !(obj instanceof ImageProcessor)) return false; ImageProcessor mask = (ImageProcessor) obj; return mask.getWidth() == imp.getWidth() && mask.getHeight() == imp.getHeight(); }