/** Returns true is this image uses an inverting LUT that displays zero as white and 255 as black. */ public boolean isInvertedLut() { return ip!=null && ip.isInvertedLut(); }
/** Returns true is this image uses an inverting LUT that displays zero as white and 255 as black. */ public boolean isInvertedLut() { return ip!=null && ip.isInvertedLut(); }
/** Whether the (auto)-thresholded pixels should be those * with high values, i.e., the background should be at low values. * (E.g. dark background and non-inverting LUT) */ boolean thresholdHigh(ImageProcessor ip) { boolean darkb = darkBackground!=null && darkBackground.getState(); boolean invertedLut = ip.isInvertedLut(); return invertedLut ? !darkb : darkb; }
private void setThreshold(ImagePlus imp) { ImageProcessor ip = imp.getProcessor(); int threshold = ip.isInvertedLut()?255:0; if (Prefs.blackBackground) threshold = ip.isInvertedLut()?0:255; ip.setThreshold(threshold, threshold, ImageProcessor.NO_LUT_UPDATE); }
public void setBinaryThreshold() { //ij.IJ.log("setMaskThreshold1"); if (!(this instanceof ByteProcessor)) return; double t1=255.0, t2=255.0; boolean invertedLut = isInvertedLut(); if ((invertedLut&&ij.Prefs.blackBackground) || (!invertedLut&&!ij.Prefs.blackBackground)) { t1 = 0.0; t2 = 0.0; } //ij.IJ.log("setMaskThreshold2 "+t1+" "+t2); setThreshold(t1, t2, ImageProcessor.NO_LUT_UPDATE); }
public void setBinaryThreshold() { //ij.IJ.log("setMaskThreshold1"); if (!(this instanceof ByteProcessor)) return; double t1=255.0, t2=255.0; boolean invertedLut = isInvertedLut(); if ((invertedLut&&ij.Prefs.blackBackground) || (!invertedLut&&!ij.Prefs.blackBackground)) { t1 = 0.0; t2 = 0.0; } //ij.IJ.log("setMaskThreshold2 "+t1+" "+t2); setThreshold(t1, t2, ImageProcessor.NO_LUT_UPDATE); }
@Override public boolean isInvertedLut() { record("isInvertedLut"); return proc.isInvertedLut(); }
@Override public boolean isInvertedLut() { record("isInvertedLut"); return proc.isInvertedLut(); }
private void setThreshold(ImagePlus imp) { ImageProcessor ip = imp.getProcessor(); int threshold = ip.isInvertedLut()?255:0; if (Prefs.blackBackground) threshold = ip.isInvertedLut()?0:255; ip.setThreshold(threshold, threshold, ImageProcessor.NO_LUT_UPDATE); }
/** Whether the (auto)-thresholded pixels should be those * with high values, i.e., the background should be at low values. * (E.g. dark background and non-inverting LUT) */ boolean thresholdHigh(ImageProcessor ip) { boolean darkb = darkBackground!=null && darkBackground.getState(); boolean invertedLut = ip.isInvertedLut(); return invertedLut ? !darkb : darkb; }
/** The position code of the legend position where the smallest amount of foreground pixels is covered */ int autoLegendPosition(int width, int height, int frameThickness) { int background = ip instanceof ColorProcessor ? (0xffffff) : (ip.isInvertedLut() ? 0 : 0xff); int grid = ip instanceof ColorProcessor ? (gridColor.getRGB() & 0xffffff) : ip.getBestIndex(gridColor); int bestPosition = 0; int minCoveredPixels = Integer.MAX_VALUE; for (int positionCode : new int[]{TOP_LEFT, TOP_RIGHT, BOTTOM_RIGHT, BOTTOM_LEFT}) { Rectangle rect = legendRect(positionCode, width, height, frameThickness); int coveredPixels = 0; for (int y = rect.y - frameThickness/2; y <= rect.y + rect.height + frameThickness/2; y++) for (int x = rect.x - frameThickness/2; x <= rect.x + rect.width + frameThickness/2; x++) { int pixel = ip.getPixel(x, y) & 0xffffff; if (pixel != background && pixel != grid) coveredPixels ++; } if (coveredPixels < minCoveredPixels) { minCoveredPixels = coveredPixels; bestPosition = positionCode; } } return bestPosition; }
/** The position code of the legend position where the smallest amount of foreground pixels is covered */ int autoLegendPosition(int width, int height, int frameThickness) { int background = ip instanceof ColorProcessor ? (0xffffff) : (ip.isInvertedLut() ? 0 : 0xff); int grid = ip instanceof ColorProcessor ? (gridColor.getRGB() & 0xffffff) : ip.getBestIndex(gridColor); int bestPosition = 0; int minCoveredPixels = Integer.MAX_VALUE; for (int positionCode : new int[]{TOP_LEFT, TOP_RIGHT, BOTTOM_RIGHT, BOTTOM_LEFT}) { Rectangle rect = legendRect(positionCode, width, height, frameThickness); int coveredPixels = 0; for (int y = rect.y - frameThickness/2; y <= rect.y + rect.height + frameThickness/2; y++) for (int x = rect.x - frameThickness/2; x <= rect.x + rect.width + frameThickness/2; x++) { int pixel = ip.getPixel(x, y) & 0xffffff; if (pixel != background && pixel != grid) coveredPixels ++; } if (coveredPixels < minCoveredPixels) { minCoveredPixels = coveredPixels; bestPosition = positionCode; } } return bestPosition; }
public boolean isInvertedLut() { ImagePlus imp = patch[currentSlice-1].getProject().getLoader().fetchImagePlus(patch[currentSlice-1]); return imp.getProcessor().isInvertedLut(); }
void createSelectionFromMask(ImagePlus imp) { ImageProcessor ip = imp.getProcessor(); if (ip.getMinThreshold()!=ImageProcessor.NO_THRESHOLD) { IJ.runPlugIn("ij.plugin.filter.ThresholdToSelection", ""); return; } if (!ip.isBinary()) { IJ.error("Create Selection", "This command creates a composite selection from\n"+ "a mask (8-bit binary image with white background)\n"+ "or from an image that has been thresholded using\n"+ "the Image>Adjust>Threshold tool. The current\n"+ "image is not a mask and has not been thresholded."); return; } int threshold = ip.isInvertedLut()?255:0; if (Prefs.blackBackground) threshold = ip.isInvertedLut()?0:255; ip.setThreshold(threshold, threshold, ImageProcessor.NO_LUT_UPDATE); IJ.runPlugIn("ij.plugin.filter.ThresholdToSelection", ""); }
public void run (ImageProcessor ip) { int fg = Prefs.blackBackground ? 255 : 0; foreground = ip.isInvertedLut() ? 255-fg : fg; background = 255 - foreground; ip.setSnapshotCopyMode(true); if (arg.equals("outline")) outline(ip); else if (arg.startsWith("fill")) fill(ip, foreground, background); else if (arg.startsWith("skel")) { ip.resetRoi(); skeletonize(ip); } else if (arg.equals("erode") || arg.equals("dilate")) doIterations((ByteProcessor)ip, arg); else if (arg.equals("open")) { doIterations(ip, "erode"); doIterations(ip, "dilate"); } else if (arg.equals("close")) { doIterations(ip, "dilate"); doIterations(ip, "erode"); } ip.setSnapshotCopyMode(false); ip.setBinaryThreshold(); }
void createSelectionFromMask(ImagePlus imp) { ImageProcessor ip = imp.getProcessor(); if (ip.getMinThreshold()!=ImageProcessor.NO_THRESHOLD) { IJ.runPlugIn("ij.plugin.filter.ThresholdToSelection", ""); return; } if (!ip.isBinary()) { IJ.error("Create Selection", "This command creates a composite selection from\n"+ "a mask (8-bit binary image with white background)\n"+ "or from an image that has been thresholded using\n"+ "the Image>Adjust>Threshold tool. The current\n"+ "image is not a mask and has not been thresholded."); return; } int threshold = ip.isInvertedLut()?255:0; if (Prefs.blackBackground) threshold = ip.isInvertedLut()?0:255; ip.setThreshold(threshold, threshold, ImageProcessor.NO_LUT_UPDATE); IJ.runPlugIn("ij.plugin.filter.ThresholdToSelection", ""); }
public void run (ImageProcessor ip) { int fg = Prefs.blackBackground ? 255 : 0; foreground = ip.isInvertedLut() ? 255-fg : fg; background = 255 - foreground; ip.setSnapshotCopyMode(true); if (arg.equals("outline")) outline(ip); else if (arg.startsWith("fill")) fill(ip, foreground, background); else if (arg.startsWith("skel")) { ip.resetRoi(); skeletonize(ip); } else if (arg.equals("erode") || arg.equals("dilate")) doIterations((ByteProcessor)ip, arg); else if (arg.equals("open")) { doIterations(ip, "erode"); doIterations(ip, "dilate"); } else if (arg.equals("close")) { doIterations(ip, "dilate"); doIterations(ip, "erode"); } ip.setSnapshotCopyMode(false); ip.setBinaryThreshold(); }
/** * Displays the current structuring element in a new ImagePlus. * @param strel the structuring element to display */ private void showStrelImage(Strel3D strel) { // Size of the strel image (little bit larger than strel) int[] dim = strel.getSize(); int width = dim[0] + 20; int height = dim[1] + 20; // Creates strel image by dilating a point ImageProcessor maskProcessor = new ByteProcessor(width, height); maskProcessor.set(width / 2, height / 2, 255); ImageStack stack = new ImageStack(); stack.addSlice(maskProcessor); stack = Morphology.dilation(stack, strel); maskProcessor = stack.getProcessor(1); // Forces the display to inverted LUT (display a black over white) if (!maskProcessor.isInvertedLut()) maskProcessor.invertLut(); // Display strel image ImagePlus maskImage = new ImagePlus("Element", maskProcessor); maskImage.show(); }
/** * Apply the current filter settings to process the given image. */ public void run(ImageProcessor image) { if (floatProcessing) { result = processFloat(image, weights.getFloatWeights(), normalize); } else { result = processShort(image, weights.getShortWeights(), normalize); } if (previewing) { // Fill up the values of original image with values of the result double valMax = result.getMax(); for (int i = 0; i < image.getPixelCount(); i++) { image.set(i, (int) (255 * result.getf(i) / valMax)); } image.resetMinAndMax(); if (image.isInvertedLut()) image.invertLut(); } }
/** Converts this ImagePlus to 8-bit grayscale. */ public synchronized void convertToGray8() { if (imp.getStackSize()>1) { new StackConverter(imp).convertToGray8(); return; } ImageProcessor ip = imp.getProcessor(); if (type==ImagePlus.GRAY16 || type==ImagePlus.GRAY32) { imp.setProcessor(null, ip.convertToByte(doScaling)); imp.setCalibration(imp.getCalibration()); //update calibration record(); } else if (type==ImagePlus.COLOR_RGB) imp.setProcessor(null, ip.convertToByte(doScaling)); else if (ip.isPseudoColorLut()) { boolean invertedLut = ip.isInvertedLut(); ip.setColorModel(LookUpTable.createGrayscaleColorModel(invertedLut)); imp.updateAndDraw(); } else { ip = new ColorProcessor(imp.getImage()); imp.setProcessor(null, ip.convertToByte(doScaling)); } ImageProcessor ip2 = imp.getProcessor(); if (Prefs.useInvertingLut && ip2 instanceof ByteProcessor && !ip2.isInvertedLut()&& !ip2.isColorLut()) { ip2.invertLut(); ip2.invert(); } }