Java Code Examples for ij.process.ImageProcessor#setValue()
The following examples show how to use
ij.process.ImageProcessor#setValue() .
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: OctagonStrelTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
/** * Dilates a single pixel by a 3x3 octagon, and check the shape of the result. * The result should be a 3x3 square (approximation of 3x3 octagon) */ @Test public void testDilateOctagon3x3() { Strel strel = new OctagonStrel(3); ImageProcessor image = new ByteProcessor(10, 10); image.setValue(0); image.fill(); image.set(5, 5, 255); ImageProcessor result = strel.dilation(image); // Check all values inside square for (int y = 4; y < 7; y++) for (int x = 4; x < 7; x++) assertEquals(255, result.get(x, y)); }
Example 2
Source File: Utils.java From TrakEM2 with GNU General Public License v3.0 | 6 votes |
/** Paints an approximation of the pipe into the set of slices. */ static public void paint(final Pipe pipe, final Map<Layer,ImageProcessor> slices, final int value, final float scale) { final VectorString3D vs = pipe.asVectorString3D(); vs.resample(1); // one pixel final double[] px = vs.getPoints(0); final double[] py = vs.getPoints(1); final double[] pz = vs.getPoints(2); final double[] pr = vs.getDependent(0); // For each point for (int i=0; i<px.length-1; i++) { final ImageProcessor ip = slices.get(pipe.getLayerSet().getNearestLayer(pz[i])); if (null == ip) continue; final OvalRoi ov = new OvalRoi((int)((px[i] - pr[i]) * scale), (int)((py[i] - pr[i]) * scale), (int)(pr[i]*2*scale), (int)(pr[i]*2*scale)); ip.setRoi(ov); ip.setValue(value); ip.fill(ip.getMask()); } }
Example 3
Source File: LinearHorizontalStrelTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
private ImageProcessor createImage_Square10x10 () { ImageProcessor image = new ByteProcessor(30, 30); image.setValue(0); image.fill(); for (int y = 10; y < 20; y++) { for (int x = 10; x < 20; x++) { image.set(x, y, 255); } } return image; }
Example 4
Source File: DiskStrelTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
/** * Dilates a single pixel by a disk with diameter 4. * The result should be larger than dilation with diameter 3. */ @Test public void testDilate_SinglePixel_EvenDiameter() { Strel disk3 = DiskStrel.fromDiameter(3); Strel disk4 = DiskStrel.fromDiameter(4); ImageProcessor image = new ByteProcessor(10, 10); image.setValue(0); image.fill(); image.set(5, 5, 255); ImageProcessor result3 = disk3.dilation(image); ImageProcessor result4 = disk4.dilation(image); // Check result3 <= result4 boolean different = false; for (int y = 0; y < 10; y++) { for (int x = 0; x < 10; x++) { int res3 = result3.get(x, y); int res4 = result4.get(x, y); assertTrue(res3 <= res4); if (res3 != res4) { different = true; } } } assertTrue(different); }
Example 5
Source File: OctagonStrelTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
private ImageProcessor createImage_Square10x10 () { ImageProcessor image = new ByteProcessor(30, 30); image.setValue(0); image.fill(); for (int y = 10; y < 20; y++) { for (int x = 10; x < 20; x++) { image.set(x, y, 255); } } return image; }
Example 6
Source File: ShiftedCross3x3Strel_LeftTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
private ImageProcessor createImage_Square4x4 () { ImageProcessor image = new ByteProcessor(10, 10); image.setValue(0); image.fill(); for (int y = 3; y < 7; y++) { for (int x = 3; x < 7; x++) { image.set(x, y, 255); } } return image; }
Example 7
Source File: OctagonStrelTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
/** * Considers the image of a single point, and applies a closing. * One should get the same image back. */ @Test public void testStabilityByOpening() { ImageProcessor image = new ByteProcessor(50, 50); image.setValue(255); image.fill(); for (int x = 22; x < 27; x++) { for (int y = 22; y < 27; y++) { image.set(x, y, 100); } } image.set(24, 25, 50); image.set(25, 24, 50); image.set(25, 25, 50); 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.opening(image); for (int p = 0; p < image.getPixelCount(); p++) { assertEquals(image.get(p), result.get(p)); } } }
Example 8
Source File: ShiftedCross3x3Strel_RightTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
private ImageProcessor createImage_Square10x10 () { ImageProcessor image = new ByteProcessor(30, 30); image.setValue(0); image.fill(); for (int y = 10; y < 20; y++) { for (int x = 10; x < 20; x++) { image.set(x, y, 255); } } return image; }
Example 9
Source File: LinearDiagUpStrelTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
private ImageProcessor createImage10x15_Square4x4 () { ImageProcessor image = new ByteProcessor(10, 15); image.setValue(0); image.fill(); for (int y = 3; y < 7; y++) { for (int x = 3; x < 7; x++) { image.set(x, y, 255); } } return image; }
Example 10
Source File: SquareStrelTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
/** * Creates a 30-by-30 image with a 10-by-10 square in the middle. */ private ImageProcessor createImage_Square10x10 () { ImageProcessor image = new ByteProcessor(30, 30); image.setValue(0); image.fill(); for (int y = 10; y < 20; y++) { for (int x = 10; x < 20; x++) { image.set(x, y, 255); } } return image; }
Example 11
Source File: Coloc_2.java From Colocalisation_Analysis with GNU General Public License v3.0 | 5 votes |
/** * Creates appropriate data structures from the ROI information * passed. If an irregular ROI is found, it will be put into a * frame of its bounding box size and put into an {@code Image<T>}. * * In the end the members ROIs, masks and maskBBs will be * filled if ROIs or masks were found. They will be null * otherwise. */ protected void createMasksAndRois(final Roi[] rois, final int width, final int height) { // create empty list masks.clear(); for (final Roi r : rois) { final MaskInfo mi = new MaskInfo(); // add it to the list of masks/ROIs masks.add(mi); // get the ROIs/masks bounding box final Rectangle rect = r.getBounds(); mi.roi = new BoundingBox(new long[] { rect.x, rect.y }, new long[] { rect.width, rect.height }); final ImageProcessor ipMask = r.getMask(); // check if we got a regular ROI and return if so if (ipMask == null) { continue; } // create a mask processor of the same size as a slice final ImageProcessor ipSlice = ipMask.createProcessor(width, height); // fill the new slice with black ipSlice.setValue(0.0); ipSlice.fill(); // position the mask on the new mask processor ipSlice.copyBits(ipMask, (int) mi.roi.offset[0], (int) mi.roi.offset[1], Blitter.COPY); // create an Image<T> out of it final ImagePlus maskImp = new ImagePlus("Mask", ipSlice); // and remember it and the masks bounding box mi.mask = ImagePlusAdapter.<T> wrap(maskImp); } }
Example 12
Source File: LinearHorizontalStrelTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
private ImageProcessor createImage_Square4x4 () { ImageProcessor image = new ByteProcessor(10, 10); image.setValue(0); image.fill(); for (int y = 3; y < 7; y++) { for (int x = 3; x < 7; x++) { image.set(x, y, 255); } } return image; }
Example 13
Source File: LinearVerticalStrelTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
private ImageProcessor createImage_Square10x10 () { ImageProcessor image = new ByteProcessor(30, 30); image.setValue(0); image.fill(); for (int y = 10; y < 20; y++) { for (int x = 10; x < 20; x++) { image.set(x, y, 255); } } return image; }
Example 14
Source File: LinearDiagDownStrelTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
private ImageProcessor createImage_Square10x10 () { ImageProcessor image = new ByteProcessor(30, 30); image.setValue(0); image.fill(); for (int y = 10; y < 20; y++) { for (int x = 10; x < 20; x++) { image.set(x, y, 255); } } return image; }
Example 15
Source File: LinearDiagDownStrelTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
private ImageProcessor createImage_Square4x4 () { ImageProcessor image = new ByteProcessor(10, 10); image.setValue(0); image.fill(); for (int y = 3; y < 7; y++) { for (int x = 3; x < 7; x++) { image.set(x, y, 255); } } return image; }
Example 16
Source File: DiamondStrelTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
private ImageProcessor createImage_Square10x10 () { ImageProcessor image = new ByteProcessor(30, 30); image.setValue(0); image.fill(); for (int y = 10; y < 20; y++) { for (int x = 10; x < 20; x++) { image.set(x, y, 255); } } return image; }
Example 17
Source File: DiamondStrelTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
private ImageProcessor createImage_Square4x4 () { ImageProcessor image = new ByteProcessor(10, 10); image.setValue(0); image.fill(); for (int y = 3; y < 7; y++) { for (int x = 3; x < 7; x++) { image.set(x, y, 255); } } return image; }
Example 18
Source File: FloodFillTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
@Test public final void testFloodFill_EmptySquaresC4() { int[] data = new int[]{ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 10, 10, 10, 30, 30, 30, 10, 10, 20, 20, 20, 10, 10, 10, 30, 30, 30, 10, 10, 20, 20, 20, 10, 10, 10, 30, 30, 30, 10, 10, 10, 10, 10, 40, 40, 40, 10, 10, 10, 10, 10, 10, 10, 10, 40, 40, 40, 10, 10, 10, 10, 10, 10, 10, 10, 40, 40, 40, 10, 10, 10, 10, 10, 20, 20, 20, 10, 10, 10, 30, 30, 30, 10, 10, 20, 20, 20, 10, 10, 10, 30, 30, 30, 10, 10, 20, 20, 20, 10, 10, 10, 30, 30, 30, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 }; ImageProcessor image = new ByteProcessor(11, 11); for (int i = 0; i < 11*11; i++) { image.set(i, data[i]); } // initialize result ImageProcessor result = new ByteProcessor(11, 11); result.setValue(255); result.fill(); // compute flood fill result FloodFill.floodFill(image, 1, 0, result, 50, 4); assertEquals(50, result.get(0, 0)); assertEquals(50, result.get(10, 0)); assertEquals(50, result.get(0, 10)); assertEquals(50, result.get(10, 10)); assertEquals(50, result.get(5, 3)); assertEquals(50, result.get(5, 7)); assertEquals(50, result.get(3, 5)); assertEquals(50, result.get(7, 5)); // printImage(result); }
Example 19
Source File: FloodFillTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 4 votes |
@Test public final void testFloodFillC8Marker() { int[][] data = new int[][]{ {10, 10, 10, 20, 20, 20, 10, 10, 10, 10, 20, 20, 10, 10, 10}, {10, 10, 20, 20, 20, 20, 20, 20, 10, 20, 20, 20, 20, 10, 10}, {10, 20, 10, 10, 10, 10, 20, 20, 10, 20, 10, 10, 20, 20, 10}, {20, 20, 10, 20, 10, 10, 10, 20, 10, 20, 20, 10, 10, 20, 20}, {20, 20, 10, 20, 10, 10, 10, 20, 10, 10, 10, 20, 10, 20, 20}, {20, 20, 10, 10, 20, 20, 10, 20, 10, 10, 10, 20, 10, 20, 20}, {10, 20, 10, 10, 10, 20, 10, 20, 20, 10, 10, 10, 10, 20, 10}, {10, 20, 10, 20, 20, 20, 10, 20, 20, 20, 20, 20, 20, 20, 10}, {10, 10, 20, 20, 10, 10, 10, 10, 10, 10, 10, 20, 20, 10, 10}, }; int height = data.length; int width = data[0].length; ImageProcessor image = new ByteProcessor(width, height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { image.set(x, y, data[y][x]); } } // initialize empty result image fill with 255 ImageProcessor result = new ByteProcessor(width, height); result.setValue(255); result.fill(); // Apply FloodFill.floodFill(image, 7, 4, result, 50, 8); // printImage(result); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (image.get(x, y) == 20) assertEquals(50, result.get(x, y)); else assertEquals(255, result.get(x, y)); } } }
Example 20
Source File: RegionalExtremaByFlooding.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 4 votes |
/** * Computes regional extrema in current input image, using * flood-filling-like algorithm with 4 connectivity. * Computations are made with double values. */ private ImageProcessor regionalExtremaC8(ImageProcessor image) { // get image size int sizeX = image.getWidth(); int sizeY = image.getHeight(); // allocate memory for output, and fill with 255 ImageProcessor result = new ByteProcessor(sizeX, sizeY); result.setValue(255); result.fill(); // initialize local data depending on extrema type int sign = 1; if (this.extremaType == ExtremaType.MAXIMA) { sign = -1; } // Iterate over image pixels for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { // Check if current pixel was already processed if (result.getf(x, y) == 0) continue; // current value float currentValue = image.getf(x, y); // compute extrema value in 4-neighborhood (computes max value // if sign is -1) float value = currentValue * sign; for (int y2 = Math.max(y-1, 0); y2 <= Math.min(y+1, sizeY-1); y2++) { for (int x2 = Math.max(x-1, 0); x2 <= Math.min(x+1, sizeX-1); x2++) { value = min(value, image.getf(x2, y2) * sign); } } // if one of the neighbors of current pixel has a lower (resp. // greater) value, the the current pixel is not an extremum. // Consequently, the current pixel, and all its connected // neighbors with same value are set to 0 in the output image. if (value < currentValue * sign) { FloodFill.floodFillFloat(image, x, y, result, 0.f, 8); } } } return result; }