Java Code Examples for ij.process.ImageProcessor#get()
The following examples show how to use
ij.process.ImageProcessor#get() .
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: BoxDiagonalOpeningQueue.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
private Collection<Point> findMaximaPositions(ImageProcessor image) { // identify each maxima ImageProcessor maxima = MinimaAndMaxima.regionalMaxima(image, conn); int sizeX = image.getWidth(); int sizeY = image.getHeight(); Collection<Point> positions = new ArrayList<Point>(); for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { // if current pixel is a regional maximum, keep the position, // and remove the regional maximum if (maxima.get(x, y) > 0) { positions.add(new Point(x, y)); FloodFill.floodFill(maxima, x, y, 0, this.conn); } } } return positions; }
Example 2
Source File: HistogramMatcher.java From orbit-image-analysis with GNU General Public License v3.0 | 6 votes |
public static BufferedImage matchHisto(BufferedImage bi2, int[] histoToMatch) { ImagePlus ip = new ImagePlus("img",bi2); ImageConverter ic = new ImageConverter(ip); ic.convertToHSB(); ImageProcessor processor = ip.getStack().getProcessor(2); // HSB -> processor 2 = saturation // ic.convertToGray8(); // ImageProcessor processor = ip.getProcessor(); int[] histo2 = processor.getHistogram(); int[] lut = matchHistograms(histo2, histoToMatch); int c; for (int x=0; x<processor.getWidth(); x++) for (int y=0; y<processor.getHeight(); y++) { c = processor.get(x,y); if (c>18) processor.set(x,y,lut[c]); } //processor.setThreshold(20,200,ImageProcessor.NO_LUT_UPDATE); //processor.setAutoThreshold(AutoThresholder.Method.Otsu, false,ImageProcessor.OVER_UNDER_LUT); //processor.applyTable(lut); ic.convertHSBToRGB(); return ip.getBufferedImage(); }
Example 3
Source File: LabelBoxValidator.java From render with GNU General Public License v2.0 | 6 votes |
public static Set<Integer> getNonEmptyLabelColors(final String labelPath) throws IOException { final ImagePlus labelImagePlus = Utils.openImagePlus(labelPath); if (labelImagePlus == null) { throw new IOException(labelPath + " could not be loaded into an ImagePlus instance"); } final ImageProcessor ip = labelImagePlus.getProcessor(); final Set<Integer> colorSet = new HashSet<>(); for (int y = 0; y < ip.getHeight(); y++) { for (int x = 0; x < ip.getWidth(); x++) { final int rgb = ip.get(x, y); if (rgb != LabelImageProcessorCache.MAX_LABEL_INTENSITY) { colorSet.add(rgb); } } } return colorSet; }
Example 4
Source File: ShiftedCross3x3Strel_RightTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testErosion_Square4x4() { ImageProcessor image = createImage_Square4x4(); Strel strel = ShiftedCross3x3Strel.RIGHT; ImageProcessor expected = image.createProcessor(10, 10); for (int y = 4; y < 6; y++) { for (int x = 3; x < 5; x++) { expected.set(x, y, 255); } } ImageProcessor result = strel.erosion(image); for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { int exp = expected.get(x, y); int res = result.get(x, y); if(expected.get(x, y) != result.get(x, y)) { System.out.println("At x=" + x + " and y=" + y + ", exp=" + exp + " and res = " + res); } assertEquals(exp, res); } } }
Example 5
Source File: BinaryImages.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
/** * Converts a grayscale 2D image into a binary 2D image by setting non-zero * pixels to 255. * * @param image * a gray scale image * @return a binary image containing 255 for all non-zero elements of * original image */ public static final ImageProcessor binarize(ImageProcessor image) { int width = image.getWidth(); int height = image.getHeight(); ImageProcessor result = new ByteProcessor(width, height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (image.get(x, y) > 0) result.set(x, y, 255); } } return result; }
Example 6
Source File: GeodesicDistanceTransformShort.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
private ShortProcessor initialize(ImageProcessor marker) { // size of image sizeX = marker.getWidth(); sizeY = marker.getHeight(); ShortProcessor distMap = new ShortProcessor(sizeX, sizeY); distMap.setValue(0); distMap.fill(); // initialize empty image with either 0 (foreground) or Inf (background) for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { int val = marker.get(x, y) & 0x00ff; distMap.set(x, y, val == 0 ? Short.MAX_VALUE : 0); } } return distMap; }
Example 7
Source File: DiskStrel.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
@Override public int[][] getMask() { // Create an empty image with just a white pixel in the middle int intRadius = (int) Math.round(radius); int size = 2 * intRadius + 1; ImageProcessor img = new ByteProcessor(size, size); img.set(intRadius, intRadius, 255); // apply dilation this.inPlaceDilation(img); // convert to int array int[][] mask = new int[size][size]; for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { mask[y][x] = img.get(x, y); } } return mask; }
Example 8
Source File: ShiftedCross3x3Strel_LeftTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testErosion_Square4x4() { ImageProcessor image = createImage_Square4x4(); Strel strel = ShiftedCross3x3Strel.LEFT; ImageProcessor expected = image.createProcessor(10, 10); for (int y = 4; y < 6; y++) { for (int x = 5; x < 7; x++) { expected.set(x, y, 255); } } ImageProcessor result = strel.erosion(image); for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { int exp = expected.get(x, y); int res = result.get(x, y); if(expected.get(x, y) != result.get(x, y)) { System.out.println("At x=" + x + " and y=" + y + ", exp=" + exp + " and res = " + res); } assertEquals(exp, res); } } }
Example 9
Source File: GeodesicDistanceTransformFloat.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
private FloatProcessor initialize(ImageProcessor marker) { // size of image sizeX = marker.getWidth(); sizeY = marker.getHeight(); FloatProcessor distMap = new FloatProcessor(sizeX, sizeY); distMap.setValue(0); distMap.fill(); // initialize empty image with either 0 (foreground) or NaN (background) for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { int val = marker.get(x, y) & 0x00ff; distMap.setf(x, y, val == 0 ? Float.POSITIVE_INFINITY : 0); } } return distMap; }
Example 10
Source File: FloodFillTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
@Test public final void testFloodFillC8_AllCases() { 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]); } } ImageProcessor result = image.duplicate(); FloodFill.floodFill(result, 7, 4, 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(10, result.get(x, y)); } } }
Example 11
Source File: MinimaAndMaxima.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
/** * Imposes the maxima given by marker image into the input image, using * the specified connectivity. * * @param image * the image to process * @param maxima * a binary image of maxima * @param conn * the connectivity for maxima, that should be either 4 or 8 * @return the result of maxima imposition */ public final static ImageProcessor imposeMaxima(ImageProcessor image, ImageProcessor maxima, int conn) { ImageProcessor marker = image.duplicate(); ImageProcessor mask = image.duplicate(); int width = image.getWidth(); int height = image.getHeight(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (maxima.get(x, y) > 0) { marker.set(x, y, 255); mask.set(x, y, 255); } else { marker.set(x, y, 0); mask.set(x, y, image.get(x, y)-1); } } } return Reconstruction.reconstructByDilation(marker, mask, conn); }
Example 12
Source File: ShiftedCross3x3Strel_LeftTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testDilation_Square4x4() { ImageProcessor image = createImage_Square4x4(); Strel strel = ShiftedCross3x3Strel.LEFT; ImageProcessor expected = image.createProcessor(10, 10); for (int x = 4; x < 8; x++) { expected.set(x, 2, 255); expected.set(x, 7, 255); } for (int y = 3; y < 7; y++) { for (int x = 3; x < 9; x++) { expected.set(x, y, 255); } } ImageProcessor result = strel.dilation(image); for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { int exp = expected.get(x, y); int res = result.get(x, y); if(expected.get(x, y) != result.get(x, y)) { System.out.println("At x=" + x + " and y=" + y + ", exp=" + exp + " and res = " + res); } assertEquals(exp, res); } } }
Example 13
Source File: ValueToNoise.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
final static private void processGray(final ImageProcessor ip, final int value, final int min, final int max) { final int scale = max - min + 1; final Random rnd = new Random(); final int n = ip.getWidth() * ip.getHeight(); for (int i =0; i < n; ++i) { final int v = ip.get(i); if (v == value) ip.set(i, rnd.nextInt(scale) + min); } }
Example 14
Source File: FloodFillTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
@Test public final void testFloodFill_AllCases() { int[][] data = new int[][]{ {10, 10, 10, 20, 20, 20, 10, 10, 10, 10, 20, 20, 10, 10, 10}, {10, 20, 20, 20, 20, 20, 20, 20, 10, 20, 20, 20, 20, 20, 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, 20, 10, 10, 20, 10, 10, 20, 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, 20, 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]); } } ImageProcessor result = image.duplicate(); FloodFill.floodFill(result, 7, 4, 50, 4); // 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(10, result.get(x, y)); } } }
Example 15
Source File: ColorImages.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
/** * Assumes reference image contains a ByteProcessor. */ private final static ImageProcessor binaryOverlayGray8(ImageProcessor refImage, ImageProcessor mask, Color color) { int width = refImage.getWidth(); int height = refImage.getHeight(); ColorProcessor result = new ColorProcessor(width, height); int value; int rgbValue = color.getRGB(); // Iterate on image pixels, and choose result value depending on mask for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if(mask.get(x, y) == 0) { // choose value from reference image value = refImage.get(x, y); // convert grayscale to equivalent color value = (value & 0x00FF) << 16 | (value & 0x00FF) << 8 | (value & 0x00FF); result.set(x, y, value); } else { // set value to chosen color result.set(x, y, rgbValue); } } } return result; }
Example 16
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 17
Source File: HistogramMatcher.java From orbit-image-analysis with GNU General Public License v3.0 | 5 votes |
public static BufferedImage matchHisto(BufferedImage bi1, BufferedImage bi2) { int[] histo1 = getBrightnessHistogram(bi1); ImagePlus ip = new ImagePlus("img",bi2); ImageConverter ic = new ImageConverter(ip); ic.convertToHSB(); ImageProcessor processor = ip.getStack().getProcessor(2); // HSB -> processor 3 = brightness // ic.convertToGray8(); // ImageProcessor processor = ip.getProcessor(); int[] histo2 = processor.getHistogram(); int[] lut = matchHistograms(histo2, histo1); //System.out.println(Arrays.toString(lut)); int c; for (int x=0; x<processor.getWidth(); x++) for (int y=0; y<processor.getHeight(); y++) { c = processor.get(x,y); if (c>18) processor.set(x,y,lut[c]); } //processor.setThreshold(20,200,ImageProcessor.NO_LUT_UPDATE); //processor.setAutoThreshold(AutoThresholder.Method.Otsu, false,ImageProcessor.OVER_UNDER_LUT); //processor.applyTable(lut); ic.convertHSBToRGB(); return ip.getBufferedImage(); }
Example 18
Source File: LabelImages.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 4 votes |
/** * Returns a binary image that contains only the selected particle or * region, by automatically cropping the image and eventually adding some * borders. * * @param image a, image containing label of particles * @param label the label of the particle to select * @param border the number of pixels to add to each side of the particle * @return a smaller binary image containing only the selected particle */ public static final ImageProcessor cropLabel(ImageProcessor image, int label, int border) { // image size int sizeX = image.getWidth(); int sizeY = image.getHeight(); // Initialize label bounds int xmin = Integer.MAX_VALUE; int xmax = Integer.MIN_VALUE; int ymin = Integer.MAX_VALUE; int ymax = Integer.MIN_VALUE; // update bounds by iterating on voxels for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { // process only specified label int val = image.get(x, y); if (val != label) { continue; } // update bounds of current label xmin = min(xmin, x); xmax = max(xmax, x); ymin = min(ymin, y); ymax = max(ymax, y); } } // Compute size of result, taking into account border int sizeX2 = (xmax - xmin + 1 + 2 * border); int sizeY2 = (ymax - ymin + 1 + 2 * border); // allocate memory for result image ImageProcessor result = new ByteProcessor(sizeX2, sizeY2); // fill result with binary label for (int y = ymin, y2 = border; y <= ymax; y++, y2++) { for (int x = xmin, x2 = border; x <= xmax; x++, x2++) { if ((image.get(x, y)) == label) { result.set(x2, y2, 255); } } } return result; }
Example 19
Source File: LargestInscribedCircle.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 4 votes |
/** * Find one position of maximum value within each label. * * @param image * the input image containing the value (for example a distance * map) * @param labelImage * the input image containing label of particles * @param labels * the set of labels contained in the label image * */ private final static Point[] findPositionOfMaxValues(ImageProcessor image, ImageProcessor labelImage, int[] labels) { int width = labelImage.getWidth(); int height = labelImage.getHeight(); // Compute value of greatest label int nbLabel = labels.length; int maxLabel = 0; for (int i = 0; i < nbLabel; i++) { maxLabel = Math.max(maxLabel, labels[i]); } // init index of each label // to make correspondence between label value and label index int[] labelIndex = new int[maxLabel+1]; for (int i = 0; i < nbLabel; i++) { labelIndex[labels[i]] = i; } // Init Position and value of maximum for each label Point[] posMax = new Point[nbLabel]; int[] maxValues = new int[nbLabel]; for (int i = 0; i < nbLabel; i++) { maxValues[i] = -1; posMax[i] = new Point(-1, -1); } // store current value int value; int index; // iterate on image pixels for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int label = (int) labelImage.getf(x, y); // do not process pixels that do not belong to particle if (label==0) continue; index = labelIndex[label]; // update values and positions value = image.get(x, y); if (value > maxValues[index]) { posMax[index].setLocation(x, y); maxValues[index] = value; } } } return posMax; }
Example 20
Source File: GeometricMeasures2D.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 4 votes |
/** * Compute bounding box of each label in input stack and returns the result * as an array of double for each label. * * @deprecated use BoundingBox class instead * * @see inra.ijpb.measure.region2d.BoundingBox#boundingBoxes(ImageProcessor, int[], Calibration) * * @param labelImage * the input image containing label of particles * @param labels an array of unique labels in image * @return a data table containing for each labeled particle the extent in * each dimension */ @Deprecated public final static double[][] boundingBox(ImageProcessor labelImage, int[] labels) { // create associative array to know index of each label HashMap<Integer, Integer> labelIndices = LabelImages.mapLabelIndices(labels); // initialize result int nLabels = labels.length; double[][] boxes = new double[nLabels][6]; for (int i = 0; i < nLabels; i++) { boxes[i][0] = Double.POSITIVE_INFINITY; boxes[i][1] = Double.NEGATIVE_INFINITY; boxes[i][2] = Double.POSITIVE_INFINITY; boxes[i][3] = Double.NEGATIVE_INFINITY; } // size of image int sizeX = labelImage.getWidth(); int sizeY = labelImage.getHeight(); // iterate on image voxels to update bounding boxes IJ.showStatus("Compute Bounding boxes"); for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { int label = labelImage.get(x, y); // do not consider background if (label == 0) continue; int labelIndex = labelIndices.get(label); // update bounding box of current label boxes[labelIndex][0] = min(boxes[labelIndex][0], x); boxes[labelIndex][1] = max(boxes[labelIndex][1], x); boxes[labelIndex][2] = min(boxes[labelIndex][2], y); boxes[labelIndex][3] = max(boxes[labelIndex][3], y); } } IJ.showStatus(""); return boxes; }