Java Code Examples for ij.process.ImageProcessor#invert()
The following examples show how to use
ij.process.ImageProcessor#invert() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LayerStack.java From TrakEM2 with GNU General Public License v3.0 | 6 votes |
/** Returns an ImageProcessor for the specified slice, where {@code 1<=n<=nslices}. Returns null if the stack is empty. */ @Override public ImageProcessor getProcessor(int n) { if (n < 1 || n > layers.size()) return null; // Create a flat image on the fly with everything on it, and return its processor. final Layer layer = layers.get(n-1); final Loader loader = layer.getProject().getLoader(); Long cid; synchronized (id_cache) { cid = id_cache.get(layer.getId()); if (null == cid) { cid = loader.getNextTempId(); id_cache.put(layer.getId(), cid); } } ImageProcessor ip; synchronized (cid) { ImagePlus imp = loader.getCachedImagePlus(cid); if (null == imp || null == imp.getProcessor() || null == imp.getProcessor().getPixels()) { ip = loader.getFlatImage(layer, this.roi, this.scale, this.c_alphas, this.type, this.clazz, null).getProcessor(); if (invert) ip.invert(); loader.cacheImagePlus(cid, new ImagePlus("", ip)); } else ip = imp.getProcessor(); } return ip; }
Example 2
Source File: MinimaAndMaximaTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
@Test public final void testExtendedMinMaxConsistency_C8 () { String fileName = getClass().getResource("/files/grains-crop.png").getFile(); ImagePlus imagePlus = IJ.openImage(fileName); ImageProcessor image = imagePlus.getProcessor(); ImageProcessor result1 = MinimaAndMaxima.extendedMaxima(image, 10, 8); image.invert(); ImageProcessor result2 = MinimaAndMaxima.extendedMinima(image, 10, 8); int width = image.getWidth(); int height = image.getHeight(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { assertEquals(result1.get(x, y), result2.get(x, y)); } } }
Example 3
Source File: MinimaAndMaximaTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
@Test public final void testExtendedMinMaxConsistency_C4 () { String fileName = getClass().getResource("/files/grains-crop.png").getFile(); ImagePlus imagePlus = IJ.openImage(fileName); ImageProcessor image = imagePlus.getProcessor(); ImageProcessor result1 = MinimaAndMaxima.extendedMaxima(image, 10); image.invert(); ImageProcessor result2 = MinimaAndMaxima.extendedMinima(image, 10); int width = image.getWidth(); int height = image.getHeight(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { assertEquals(result1.get(x, y), result2.get(x, y)); } } }
Example 4
Source File: BinaryOrbit.java From orbit-image-analysis with GNU General Public License v3.0 | 5 votes |
public void skeletonize(ImageProcessor ip) { if (Prefs.blackBackground) ip.invert(); boolean edgePixels = hasEdgePixels(ip); ImageProcessor ip2 = expand(ip, edgePixels); ((ByteProcessor)ip2).skeletonize(); ip = shrink(ip, ip2, edgePixels); if (Prefs.blackBackground) ip.invert(); }
Example 5
Source File: MinimaAndMaximaTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
@Test public final void testImposeMinimaMaximaConsistency_C8 () { String fileName = getClass().getResource("/files/grains-crop.png").getFile(); ImagePlus imagePlus = IJ.openImage(fileName); ImageProcessor image = imagePlus.getProcessor(); Strel strel = SquareStrel.fromDiameter(3); ImageProcessor grad = Morphology.gradient(image, strel); ImageProcessor markers = MinimaAndMaxima.extendedMinima(grad, 20, 8); ImageProcessor imp = MinimaAndMaxima.imposeMinima(grad, markers, 8); ImageProcessor rmin = MinimaAndMaxima.regionalMinima(imp, 8); grad.invert(); ImageProcessor imp2 = MinimaAndMaxima.imposeMaxima(grad, markers, 8); ImageProcessor rmax = MinimaAndMaxima.regionalMaxima(imp2, 8); int width = image.getWidth(); int height = image.getHeight(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { assertEquals("Results differ at position " + x + "," + y, rmin.get(x, y), rmax.get(x, y)); } } }
Example 6
Source File: InteractiveMarkerControlledWatershed.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
/** * Update the overlay in the display image based on * the current result and slice */ void updateResultOverlay() { if( null != resultImage ) { int slice = displayImage.getCurrentSlice(); final String displayOption = (String) resultDisplayList.getSelectedItem(); ImageRoi roi = null; if( displayOption.equals( catchmentBasinsText ) ) { roi = new ImageRoi(0, 0, resultImage.getImageStack().getProcessor( slice ) ); roi.setOpacity( 1.0 ); } else if( displayOption.equals( overlaidDamsText ) ) { ImageProcessor lines = BinaryImages.binarize( resultImage.getImageStack().getProcessor( slice ) ); lines.invert(); lines.setLut( LUT.createLutFromColor( Color.red ) ); roi = new ImageRoi( 0, 0, lines ); roi.setZeroTransparent( true ); roi.setOpacity( 1.0 ); } else if( displayOption.equals( watershedLinesText ) ) { roi = new ImageRoi(0, 0, BinaryImages.binarize( resultImage.getImageStack().getProcessor( slice ) ) ); roi.setOpacity( 1.0 ); } else if( displayOption.equals( overlaidBasinsText ) ) { roi = new ImageRoi(0, 0, resultImage.getImageStack().getProcessor( slice ) ); roi.setOpacity( opacity ); } displayImage.setOverlay( new Overlay( roi ) ); } }
Example 7
Source File: MorphologicalSegmentation.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
/** * Update the overlay in the display image based on * the current result and slice */ void updateResultOverlay() { if( null != resultImage ) { int slice = displayImage.getCurrentSlice(); final String displayOption = (String) resultDisplayList.getSelectedItem(); ImageRoi roi = null; if( displayOption.equals( catchmentBasinsText ) ) { roi = new ImageRoi(0, 0, resultImage.getImageStack().getProcessor( slice ) ); roi.setOpacity( 1.0 ); } else if( displayOption.equals( overlaidDamsText ) ) { ImageProcessor lines = BinaryImages.binarize( resultImage.getImageStack().getProcessor( slice ) ); lines.invert(); lines.setLut( LUT.createLutFromColor( Color.red ) ); roi = new ImageRoi( 0, 0, lines ); roi.setZeroTransparent( true ); roi.setOpacity( 1.0 ); } else if( displayOption.equals( watershedLinesText ) ) { roi = new ImageRoi(0, 0, BinaryImages.binarize( resultImage.getImageStack().getProcessor( slice ) ) ); roi.setOpacity( 1.0 ); } else if( displayOption.equals( overlaidBasinsText ) ) { roi = new ImageRoi(0, 0, resultImage.getImageStack().getProcessor( slice ) ); roi.setOpacity( opacity ); } displayImage.setOverlay( new Overlay( roi ) ); } }
Example 8
Source File: DistanceTransformWatershed.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
private ImageProcessor processShort( ImageProcessor image, short[] weights, boolean normalize ) { // Compute distance on specified image final ImageProcessor dist = BinaryImages.distanceMap( image, weights, normalize ); dist.invert(); return ExtendedMinimaWatershed.extendedMinimaWatershed( dist, image, dynamic, connectivity, 16, false ); }
Example 9
Source File: DistanceTransformWatershed.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
private ImageProcessor processFloat( ImageProcessor image, float[] weights, boolean normalize ) { final ImageProcessor dist = BinaryImages.distanceMap( image, weights, normalize ); dist.invert(); return ExtendedMinimaWatershed.extendedMinimaWatershed( dist, image, dynamic, connectivity, 32, false ); }
Example 10
Source File: ThresholderOrbit.java From orbit-image-analysis with GNU General Public License v3.0 | 5 votes |
void setInvertedLut(ImagePlus imp) { ImageProcessor ip = imp.getProcessor(); ip.invertLut(); int nImages = imp.getStackSize(); if (nImages==1) ip.invert(); else { ImageStack stack = imp.getStack(); for (int slice=1; slice<=nImages; slice++) stack.getProcessor(slice).invert(); stack.setColorModel(ip.getColorModel()); } }
Example 11
Source File: ReconstructionTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 4 votes |
/** * Test method for {@link ijt.filter.morphology.Reconstruction#reconstructByErosion()}. */ @Test public void testReconstructByErosion() { int BG = 0; int FG = 255; int[][] data = new int[][]{ {BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, FG, FG, FG, FG, FG, FG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, FG, FG, FG, FG, FG, FG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, BG, BG, BG, FG, FG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, FG, FG, BG, BG, BG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, FG, FG, FG, FG, FG, FG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, FG, FG, FG, FG, FG, FG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG}, }; int height = data.length; int width = data[0].length; ImageProcessor mask = new ByteProcessor(width, height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { mask.set(x, y, data[y][x]); } } mask.invert(); ImageProcessor marker = new ByteProcessor(width, height); marker.setColor(255); marker.fill(); marker.set(2, 3, 0); ImageProcessor result = Reconstruction.reconstructByErosion(marker, mask); assertEquals(16, result.getWidth()); assertEquals(10, result.getHeight()); assertEquals(0, result.get(2, 8)); assertEquals(0, result.get(8, 8)); assertEquals(0, result.get(8, 5)); assertEquals(0, result.get(14, 8)); }
Example 12
Source File: ReconstructionTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 4 votes |
/** * Test method for {@link ijt.filter.morphology.Reconstruction#reconstructByErosion()}. */ @Test public void testReconstructByErosion_C8() { int BG = 0; int FG = 255; int[][] data = new int[][]{ {BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG}, {BG, FG, FG, BG, FG, FG, BG, BG, BG, FG, FG, FG, FG, BG, BG, BG}, {BG, FG, FG, BG, FG, FG, BG, BG, BG, FG, FG, FG, FG, BG, BG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, BG, BG, BG, FG, FG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, FG, FG, BG, BG, BG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, BG, BG, FG, FG, FG, FG, BG, BG, BG, FG, FG, BG, FG, FG, BG}, {BG, BG, BG, FG, FG, FG, FG, BG, BG, BG, FG, FG, BG, FG, FG, BG}, {BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG}, }; int height = data.length; int width = data[0].length; ImageProcessor mask = new ByteProcessor(width, height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { mask.set(x, y, data[y][x]); } } mask.invert(); ImageProcessor marker = new ByteProcessor(width, height); marker.setColor(255); marker.fill(); marker.set(2, 3, 0); ImageProcessor result = Reconstruction.reconstructByErosion(marker, mask, 8); assertEquals(16, result.getWidth()); assertEquals(10, result.getHeight()); assertEquals(0, result.get(2, 6)); assertEquals(0, result.get(4, 8)); assertEquals(0, result.get(8, 5)); assertEquals(0, result.get(14, 8)); }
Example 13
Source File: GeodesicReconstructionScanningTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 4 votes |
/** * Test method for {@link ijt.filter.morphology.GeodesicReconstruction#reconstructByErosion()}. */ @Test public void testReconstructByErosion_C4() { int BG = 0; int FG = 255; int[][] data = new int[][]{ {BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, FG, FG, FG, FG, FG, FG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, FG, FG, FG, FG, FG, FG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, BG, BG, BG, FG, FG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, FG, FG, BG, BG, BG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, FG, FG, FG, FG, FG, FG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, FG, FG, FG, FG, FG, FG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG}, }; int height = data.length; int width = data[0].length; ImageProcessor mask = new ByteProcessor(width, height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { mask.set(x, y, data[y][x]); } } mask.invert(); ImageProcessor marker = new ByteProcessor(width, height); marker.setColor(255); marker.fill(); marker.set(2, 3, 0); // System.out.println("Marker Image:"); // printImage(marker); // System.out.println("Mask Image:"); // printImage(mask); GeodesicReconstructionScanning algo = new GeodesicReconstructionScanning( GeodesicReconstructionType.BY_EROSION, 4); ImageProcessor result = algo.applyTo(marker, mask); // System.out.println("Result Image:"); // printImage(result); assertEquals(16, result.getWidth()); assertEquals(10, result.getHeight()); assertEquals(0, result.get(2, 8)); assertEquals(0, result.get(8, 8)); assertEquals(0, result.get(8, 5)); assertEquals(0, result.get(14, 8)); assertEquals(255, result.get(15, 9)); assertEquals(255, result.get(0, 0)); assertEquals(255, result.get(5, 3)); assertEquals(255, result.get(11, 5)); }
Example 14
Source File: GeodesicReconstructionScanningTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 4 votes |
/** * Test method for {@link ijt.filter.morphology.GeodesicReconstruction#reconstructByErosion()}. */ @Test public void testReconstructByErosion_C8() { int BG = 0; int FG = 255; int[][] data = new int[][]{ {BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG}, {BG, FG, FG, BG, FG, FG, BG, BG, BG, FG, FG, FG, FG, BG, BG, BG}, {BG, FG, FG, BG, FG, FG, BG, BG, BG, FG, FG, FG, FG, BG, BG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, BG, BG, BG, FG, FG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, FG, FG, BG, BG, BG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, BG, BG, FG, FG, FG, FG, BG, BG, BG, FG, FG, BG, FG, FG, BG}, {BG, BG, BG, FG, FG, FG, FG, BG, BG, BG, FG, FG, BG, FG, FG, BG}, {BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG}, }; int height = data.length; int width = data[0].length; ImageProcessor mask = new ByteProcessor(width, height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { mask.set(x, y, data[y][x]); } } mask.invert(); ImageProcessor marker = new ByteProcessor(width, height); marker.setColor(255); marker.fill(); marker.set(2, 3, 0); GeodesicReconstructionScanning algo = new GeodesicReconstructionScanning( GeodesicReconstructionType.BY_EROSION, 8); ImageProcessor result = algo.applyTo(marker, mask); assertEquals(16, result.getWidth()); assertEquals(10, result.getHeight()); assertEquals(0, result.get(2, 6)); assertEquals(0, result.get(4, 8)); assertEquals(0, result.get(8, 5)); assertEquals(0, result.get(14, 8)); assertEquals(255, result.get(15, 9)); assertEquals(255, result.get(0, 0)); assertEquals(255, result.get(5, 3)); assertEquals(255, result.get(11, 5)); }
Example 15
Source File: GeodesicReconstructionHybridTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 4 votes |
/** * Test method for {@link ijt.filter.morphology.GeodesicReconstruction#reconstructByErosion()}. */ @Test public void testReconstructByErosion_C4() { int BG = 0; int FG = 255; int[][] data = new int[][]{ {BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, FG, FG, FG, FG, FG, FG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, FG, FG, FG, FG, FG, FG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, BG, BG, BG, FG, FG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, FG, FG, BG, BG, BG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, FG, FG, FG, FG, FG, FG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, FG, FG, FG, FG, FG, FG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG}, }; int height = data.length; int width = data[0].length; ImageProcessor mask = new ByteProcessor(width, height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { mask.set(x, y, data[y][x]); } } mask.invert(); ImageProcessor marker = new ByteProcessor(width, height); marker.setColor(255); marker.fill(); marker.set(2, 3, 0); GeodesicReconstructionHybrid algo = new GeodesicReconstructionHybrid( GeodesicReconstructionType.BY_EROSION, 4); ImageProcessor result = algo.applyTo(marker, mask); assertEquals(16, result.getWidth()); assertEquals(10, result.getHeight()); assertEquals(0, result.get(2, 8)); assertEquals(0, result.get(8, 8)); assertEquals(0, result.get(8, 5)); assertEquals(0, result.get(14, 8)); assertEquals(FG, result.get(15, 9)); assertEquals(FG, result.get(0, 0)); assertEquals(FG, result.get(5, 3)); assertEquals(FG, result.get(11, 5)); }
Example 16
Source File: GeodesicReconstructionHybridTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 4 votes |
/** * Test method for {@link ijt.filter.morphology.GeodesicReconstruction#reconstructByErosion()}. */ @Test public void testReconstructByErosion_C8() { int BG = 0; int FG = 255; int[][] data = new int[][]{ {BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG}, {BG, FG, FG, BG, FG, FG, BG, BG, BG, FG, FG, FG, FG, BG, BG, BG}, {BG, FG, FG, BG, FG, FG, BG, BG, BG, FG, FG, FG, FG, BG, BG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, BG, BG, BG, FG, FG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, FG, FG, BG, BG, BG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG}, {BG, BG, BG, FG, FG, FG, FG, BG, BG, BG, FG, FG, BG, FG, FG, BG}, {BG, BG, BG, FG, FG, FG, FG, BG, BG, BG, FG, FG, BG, FG, FG, BG}, {BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG}, }; int height = data.length; int width = data[0].length; ImageProcessor mask = new ByteProcessor(width, height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { mask.set(x, y, data[y][x]); } } mask.invert(); ImageProcessor marker = new ByteProcessor(width, height); marker.setColor(255); marker.fill(); marker.set(2, 3, 0); GeodesicReconstructionHybrid algo = new GeodesicReconstructionHybrid( GeodesicReconstructionType.BY_EROSION, 8); ImageProcessor result = algo.applyTo(marker, mask); assertEquals(16, result.getWidth()); assertEquals(10, result.getHeight()); assertEquals(0, result.get(2, 6)); assertEquals(0, result.get(4, 8)); assertEquals(0, result.get(8, 5)); assertEquals(0, result.get(14, 8)); assertEquals(255, result.get(15, 9)); assertEquals(255, result.get(0, 0)); assertEquals(255, result.get(5, 3)); assertEquals(255, result.get(11, 5)); }
Example 17
Source File: BinaryOrbit.java From orbit-image-analysis with GNU General Public License v3.0 | 4 votes |
void outline(ImageProcessor ip) { if (Prefs.blackBackground) ip.invert(); ((ByteProcessor)ip).outline(); if (Prefs.blackBackground) ip.invert(); }
Example 18
Source File: Invert.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
@Override public ImageProcessor process(ImageProcessor ip) { ip.invert(); return ip; }