@Override public int getPixelCount() { record("getPixelCount"); return proc.getPixelCount(); }
@Override public int getPixelCount() { record("getPixelCount"); return proc.getPixelCount(); }
private static final int computeMaxLabel(ImageProcessor image) { int labelMax = 0; if (image instanceof FloatProcessor) { for (int i = 0; i < image.getPixelCount(); i++) { labelMax = Math.max(labelMax, (int) image.getf(i)); } } else { for (int i = 0; i < image.getPixelCount(); i++) { labelMax = Math.max(labelMax, image.get(i)); } } return labelMax; }
private void save16BitImage(ImageProcessor ip, String path) { ip.resetMinAndMax(); int max = (int)ip.getMax(); if (max<256) max=256; try { DataOutputStream output = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(path))); output.writeBytes("P5\n# Written by ImageJ PNM Writer\n" + ip.getWidth() + " " + ip.getHeight() + "\n"+max+"\n"); for (int i=0; i<ip.getPixelCount(); i++) output.writeShort(ip.get(i)); output.close(); } catch(IOException e) { IJ.handleException(e); } }
private void save16BitImage(ImageProcessor ip, String path) { ip.resetMinAndMax(); int max = (int)ip.getMax(); if (max<256) max=256; try { DataOutputStream output = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(path))); output.writeBytes("P5\n# Written by ImageJ PNM Writer\n" + ip.getWidth() + " " + ip.getHeight() + "\n"+max+"\n"); for (int i=0; i<ip.getPixelCount(); i++) output.writeShort(ip.get(i)); output.close(); } catch(IOException e) { IJ.handleException(e); } }
@Override public void run(ImageProcessor image) { if (previewing) { // Iterate over pixels to change value of reference image boolean keepPixel; for (int i = 0; i < image.getPixelCount(); i++) { keepPixel = false; int label = (int) this.labelImage.get(i); if (label > 0) { int index = this.labelMap.get(label); keepPixel = this.pixelCountArray[index] > this.minPixelCount; } image.set(i, keepPixel ? 255 : 0); } } }
@Override public void run(ImageProcessor image) { this.result = AttributeFiltering.areaOpening(image, this.minPixelCount); if (previewing) { // Iterate over pixels to change value of reference image for (int i = 0; i < image.getPixelCount(); i++) { image.set(i, result.get(i)); } } }
private void resetPreview() { ImageProcessor image = this.imagePlus.getProcessor(); if (image instanceof FloatProcessor) { for (int i = 0; i < image.getPixelCount(); i++) image.setf(i, this.baseImage.getf(i)); } else { for (int i = 0; i < image.getPixelCount(); i++) image.set(i, this.baseImage.get(i)); } imagePlus.updateAndDraw(); }
/** * Find largest label (by number of pixels/voxels) in input image * @param imagePlus input image * @return value of the largest label in the input label image */ public final static int findLargestLabel(ImagePlus imagePlus) { int max = 0; for (int i = 1; i <= imagePlus.getImageStackSize(); i++) { ImageProcessor slice = imagePlus.getStack().getProcessor(i); for (int j = 0; j < slice.getPixelCount(); j++) { max = Math.max(max, (int) slice.getf(j)); } } return max; }
private void resetPreview() { ImageProcessor image = this.imagePlus.getProcessor(); if (image instanceof FloatProcessor) { for (int i = 0; i < image.getPixelCount(); i++) image.setf(i, this.baseImage.getf(i)); } else { for (int i = 0; i < image.getPixelCount(); i++) image.set(i, this.baseImage.get(i)); } image.resetMinAndMax(); imagePlus.updateAndDraw(); }
@Override public void run(ImageProcessor image) { // Create structuring element of the given size // Execute core of the plugin result = op.apply(image, connectivity); if (previewing) { // Fill up the values of original image with inverted values of the // (binary) result double valMax = result.getMax(); for (int i = 0; i < image.getPixelCount(); i++) { image.set(i, 255 - (int) (255 * result.getf(i) / valMax)); } } }
@Override public void run(ImageProcessor image) { // Create structuring element of the given size // Execute core of the plugin result = op.apply(image, dynamic, connectivity); if (previewing) { // Fill up the values of original image with inverted values of the // (binary) result double valMax = result.getMax(); for (int i = 0; i < image.getPixelCount(); i++) { image.set(i, 255 - (int) (255 * result.getf(i) / valMax)); } } }
private static ImageProcessor RGBtoLab(ImageProcessor ip) { int n = ip.getPixelCount(); byte[] L = new byte[n]; byte[] a = new byte[n]; byte[] b = new byte[n]; ColorThresholder.getLab(ip, L, a, b); ColorProcessor cp = new ColorProcessor(ip.getWidth(),ip.getHeight()); cp.setRGB(L,a,b); return cp; }
private static ImageProcessor RGBtoLab(ImageProcessor ip) { int n = ip.getPixelCount(); byte[] L = new byte[n]; byte[] a = new byte[n]; byte[] b = new byte[n]; ColorThresholder.getLab(ip, L, a, b); ColorProcessor cp = new ColorProcessor(ip.getWidth(),ip.getHeight()); cp.setRGB(L,a,b); return cp; }
@Override public void run(ImageProcessor image) { BoxDiagonalOpeningQueue algo = new BoxDiagonalOpeningQueue(); DefaultAlgoListener.monitor(algo); this.result = algo.process(image, this.minDiagonalLength); if (previewing) { // Iterate over pixels to change value of reference image for (int i = 0; i < image.getPixelCount(); i++) { image.set(i, result.get(i)); } } }
@Override public void run(ImageProcessor image) { IJ.log("Run directional filter"); DirectionalFilter filter = new DirectionalFilter(this.type, this.op, this.lineLength, this.nDirections); DefaultAlgoListener.monitor(filter); this.result = filter.process(image); if (previewing) { // Fill up the values of original image with values of the result for (int i = 0; i < image.getPixelCount(); i++) { image.set(i, result.get(i)); } } }
@Override public void run(ImageProcessor image) { // Create structuring element of the given size Strel strel = shape.fromRadius(radius); // add some listeners DefaultAlgoListener.monitor(strel); // Eventually display the structuring element used for processing if (showStrel) { showStrelImage(strel); } // Execute core of the plugin on the original image result = op.apply(this.baseImage, strel); if (!(result instanceof ColorProcessor)) result.setLut(this.baseImage.getLut()); if (previewing) { // Fill up the values of original image with values of the result for (int i = 0; i < image.getPixelCount(); i++) { image.setf(i, result.getf(i)); } image.resetMinAndMax(); } }
/** * Apply the current filter settings to process the given image. */ public void run(ImageProcessor image) { synchronized (this){ 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(); } }
/** * 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(); } }
/** * Considers the image of a single point, and applies a closing. * One should get the same image back. */ @Test public void testStabilityByClosing() { ImageProcessor image = new ByteProcessor(50, 50); for (int x = 22; x < 27; x++) { for (int y = 22; y < 27; y++) { image.set(x, y, 150); } } image.set(24, 25, 200); image.set(25, 24, 200); image.set(25, 25, 200); int[] radiusList = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 15, 20}; for (int i = 0; i < radiusList.length; i++) { int diam = 2*radiusList[i] + 1; Strel se = new OctagonStrel(diam); ImageProcessor result = se.closing(image); for (int p = 0; p < image.getPixelCount(); p++) { assertEquals(image.get(p), result.get(p)); } } }