ij.process.ByteProcessor Java Examples

The following examples show how to use ij.process.ByteProcessor. 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: Morphology.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Performs morphological erosion on each channel, and reconstitutes the
 * resulting color image.
 * 
 * @param image
 *            the input image to process (RGB)
 * @param strel
 *            the structuring element used for erosion
 * @return the result of the erosion
 */
private static ImageProcessor erosionRGB(ImageProcessor image, Strel strel)
{
	// extract channels and allocate memory for result
	Map<String, ByteProcessor> channels = ColorImages.mapChannels(image);
	Collection<ImageProcessor> res = new ArrayList<ImageProcessor>(channels.size());
	
	// Process each channel individually
	for (String name : new String[]{"red", "green", "blue"}) 
	{
		strel.setChannelName(name);
		res.add(strel.erosion(channels.get(name)));
	}
	
	return ColorImages.mergeChannels(res);
}
 
Example #2
Source File: IntrinsicVolumes2DTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link inra.ijpb.measure.IntrinsicVolumes2D#eulerNumber(ij.process.ImageProcessor, int)}.
 */
@Test
public final void testEulerNumber_crossC4()
{
	// create a binary image containing a square
	ImageProcessor image = new ByteProcessor(10, 10);
	for (int i = 2; i < 8; i++)
	{
		image.set(i, 4, 255);
		image.set(i, 5, 255);
		image.set(4, i, 255);
		image.set(5, i, 255);
	}
	
	int euler = IntrinsicVolumes2D.eulerNumber(image, 4);
	assertEquals(1, euler);
}
 
Example #3
Source File: DistanceTransform5x5FloatTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public final void testDistanceMap_ChessBoard() 
{
	ByteProcessor image = new ByteProcessor(12, 10);
	image.setBackgroundValue(0);
	image.fill();
	for (int y = 2; y < 8; y++) {
		for (int x = 2; x < 10; x++) {
			image.set(x, y, 255);
		}
	}
	
	float[] weights = ChamferWeights.CHESSBOARD.getFloatWeights();
	DistanceTransform5x5Float algo = new DistanceTransform5x5Float(weights, true);
	ImageProcessor result = algo.distanceMap(image);
	
	assertNotNull(result);
	assertEquals(image.getWidth(), result.getWidth());
	assertEquals(image.getHeight(), result.getHeight());
	assertEquals(3, result.getf(4, 4), 1e-12);
}
 
Example #4
Source File: TMLHandler.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
/** 
 * Backwards compatibility for alpha masks:
 * create the file path as it was before, and see if the file exists.
 * If it does, set it to the patch as the alpha mask.
 */
private void checkAlphaMasks(Patch patch) {
	if (0 == patch.getAlphaMaskId()) {
		final File f = new File(patch.getImageFilePath());
		final String path = new StringBuilder(loader.getMasksFolder()).append(FSLoader.createIdPath(Long.toString(patch.getId()), f.getName(), ".zip")).toString();
		if (new File(path).exists()) {
			try {
				if (patch.setAlphaMask((ByteProcessor)loader.openImagePlus(path).getProcessor().convertToByte(false))) {
					// On success, queue the file for deletion when saving the XML file
					loader.markStaleFileForDeletionUponSaving(path);
					Utils.log("Upgraded alpha mask for patch #" + patch.getId());
				} else {
					Utils.log("ERROR: failed to upgrade alpha mask for patch #" + patch.getId());
				}
			} catch (Exception e) {
				Utils.log("FAILED to restore alpha mask for patch #" + patch.getId() + ":");
				IJError.print(e);
			}
		}
	}
}
 
Example #5
Source File: IntrinsicVolumes2DTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link inra.ijpb.measure.IntrinsicVolumes2D#eulerNumber(ij.process.ImageProcessor, int)}.
 */
@Test
public final void testEulerNumber_torusC8()
{
	// create a binary image containing a square
	ImageProcessor image = new ByteProcessor(11, 11);
	for (int i = 2; i < 9; i++)
	{
		for (int j = 2; j < 9; j++)
		{
			image.set(i, j, 255);
		}
	}
	for (int i = 4; i < 7; i++)
	{
		for (int j = 4; j < 7; j++)
		{
			image.set(i, j, 0);
		}
	}
	
	int euler = IntrinsicVolumes2D.eulerNumber(image, 8);
	assertEquals(0, euler);
}
 
Example #6
Source File: AverageThicknessTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link inra.ijpb.measure.region2d.AverageThickness#analyzeRegions(ij.process.ImageProcessor, int[], ij.measure.Calibration)}.
 */
@Test
public final void testAnalyzeRegionsImageProcessorIntArrayCalibration()
{
    ImageProcessor image = new ByteProcessor(12, 8);
    for (int y = 2; y <= 6; y++)
    {
        for (int x = 2; x <= 10; x++)
        {
            image.set(x, y, 255);
        }
    }
    
    AverageThickness op = new AverageThickness();
    
    int[] labels = new int[] {255};
    Result[] results = op.analyzeRegions(image, labels, new Calibration());
    
    assertEquals(1, results.length);
    
    Result res = results[0];
    assertTrue(res.meanDist > 2);
    assertTrue(res.meanDist <= 3);
}
 
Example #7
Source File: IJHysteresis.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Double thresholding
 *
 * @param ima original image
 * @param T1  high threshold
 * @param T2  low threshold
 * @return "trinarised" image
 */
ImageProcessor trin(ImageProcessor ima, float T1, float T2) {
    int la = ima.getWidth();
    int ha = ima.getHeight();
    ByteProcessor res = new ByteProcessor(la, ha);
    float pix;

    for (int x = 0; x < la; x++) {
        for (int y = 0; y < ha; y++) {
            pix = ima.getPixelValue(x, y);
            if (pix >= T1) {
                res.putPixel(x, y, 255);
            } else if (pix >= T2) {
                res.putPixel(x, y, 128);
            }
        }
    }
    return res;
}
 
Example #8
Source File: ExportBestFlatImage.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
public Pair<ColorProcessor, ByteProcessor> makeFlatColorImage()
{
	if ( canUseAWTImage() ) { // less than 0.5 GB array size
		final ColorProcessor cp = new ColorProcessor( createAWTImage( ImagePlus.COLOR_RGB ) );
		final ByteProcessor alpha = new ByteProcessor( cp.getWidth(), cp.getHeight(), cp.getChannel( 4 ) );
		return new Pair<ColorProcessor, ByteProcessor>( cp, alpha );
	}

	if ( !isSmallerThan2GB() ) {
		Utils.log("Cannot create an image larger than 2 GB.");
		return null;
	}

	if ( loader.isMipMapsRegenerationEnabled() )
	{
		return ExportARGB.makeFlatImageARGBFromMipMaps( patches, finalBox, 0, scale );
	}

	// No mipmaps: create an image as large as possible, then downsample it
	final Pair<ColorProcessor, ByteProcessor> pair = ExportARGB.makeFlatImageARGBFromOriginals( patches, finalBox, 0, scaleUP );

	final double sigma = computeSigma( pair.a.getWidth(), pair.a.getHeight());
	new GaussianBlur().blurGaussian( pair.a, sigma, sigma, 0.0002 );
	new GaussianBlur().blurGaussian( pair.b, sigma, sigma, 0.0002 );
	return pair;
}
 
Example #9
Source File: DistanceTransform3x3FloatTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public final void testDistanceMap_UntilCorners_Borgefors34() 
{
	ByteProcessor image = new ByteProcessor(7, 7);
	image.setValue(255);
	image.fill();
	image.set(4, 4, 0);

	float[] weights = ChamferWeights.BORGEFORS.getFloatWeights();
	DistanceTransform3x3Float algo = new DistanceTransform3x3Float(weights, false);
	ImageProcessor result = algo.distanceMap(image);

	assertNotNull(result);
	assertEquals(image.getWidth(), result.getWidth());
	assertEquals(image.getHeight(), result.getHeight());
	assertEquals(16, result.getf(0, 0), .01);
	assertEquals(14, result.getf(6, 0), .01);
	assertEquals(14, result.getf(0, 6), .01);
	assertEquals(8, result.getf(6, 6), .01);
}
 
Example #10
Source File: TableUtil.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Print out a ByteProcessor.
 *
 * @param title a title for the print
 * @param buf   the input buffer
 */
public static void dump (String title,
                         ByteProcessor buf)
{
    final int width = buf.getWidth();
    final int height = buf.getHeight();

    if (title != null) {
        System.out.println(title);
    }

    final String yFormat = printAbscissae(width, height, 4);

    for (int y = 0; y < height; y++) {
        System.out.printf(yFormat, y);

        for (int x = 0; x < width; x++) {
            System.out.printf("%4d", buf.get(x, y));
        }

        System.out.println();
    }
}
 
Example #11
Source File: IntrinsicVolumes2DTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link inra.ijpb.measure.IntrinsicVolumes2D#perimeter(ij.process.ImageProcessor, Calibration, int)}.
 */
@Test
public final void testPerimeter_smallSquare_D2()
{
	// create a binary image containing a square
	ImageProcessor image = new ByteProcessor(8, 8);
	for (int y = 2; y < 6; y++)
	{
		for (int x = 2; x < 6; x++)
		{
			image.set(x, y, 255);
		}
	}
	
	double perim = IntrinsicVolumes2D.perimeter(image, new Calibration(), 2);
	assertEquals(12.5664, perim, .01);
}
 
Example #12
Source File: DiskStrel.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #13
Source File: IntrinsicVolumes2DTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link inra.ijpb.measure.IntrinsicVolumes2D#perimeter(ij.process.ImageProcessor, Calibration, int)}.
 */
@Test
public final void testPerimeters_smallSquare_D2()
{
	// create a binary image containing a square
	ImageProcessor image = new ByteProcessor(8, 8);
	for (int y = 2; y < 6; y++)
	{
		for (int x = 2; x < 6; x++)
		{
			image.set(x, y, 255);
		}
	}
	
	// compute perimeter with default (1,1) calibration
	Calibration calib = new Calibration();
	int[] labels = new int[] {255};
	double[] perims = IntrinsicVolumes2D.perimeters(image, labels, calib, 2);
	
	assertEquals(12.5664, perims[0], .01);
}
 
Example #14
Source File: IntrinsicVolumes2DTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link inra.ijpb.measure.IntrinsicVolumes2D#eulerNumber(ij.process.ImageProcessor, int)}.
 */
@Test
public final void testEulerNumber_crossTouchingBordersC8()
{
	// create a binary image containing a square
	ImageProcessor image = new ByteProcessor(6, 6);
	for (int i = 0; i < 6; i++)
	{
		image.set(i, 2, 255);
		image.set(i, 3, 255);
		image.set(2, i, 255);
		image.set(3, i, 255);
	}
	
	int euler = IntrinsicVolumes2D.eulerNumber(image, 8);
	assertEquals(1, euler);
}
 
Example #15
Source File: DistanceTransform5x5FloatTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public final void testDistanceMap_UntilCorners_CityBlock() 
{
	ByteProcessor image = new ByteProcessor(7, 7);
	image.setValue(255);
	image.fill();
	image.set(4, 4, 0);
	
	float[] weights = ChamferWeights.CITY_BLOCK.getFloatWeights();
	DistanceTransform5x5Float algo = new DistanceTransform5x5Float(weights, false);
	ImageProcessor result = algo.distanceMap(image);
	
	assertNotNull(result);
	assertEquals(image.getWidth(), result.getWidth());
	assertEquals(image.getHeight(), result.getHeight());
	assertEquals(8, result.getf(0, 0), .01);
	assertEquals(6, result.getf(6, 0), .01);
	assertEquals(6, result.getf(0, 6), .01);
	assertEquals(4, result.getf(6, 6), .01);
	assertEquals(5, result.getf(0, 5), .01);
}
 
Example #16
Source File: IntrinsicVolumes2DTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link inra.ijpb.measure.IntrinsicVolumes2D#perimeter(ij.process.ImageProcessor, Calibration, int)}.
 */
@Test
public final void testPerimeter_disk_D2()
{
	double radius = 16.0;

	// create a binary image containing a square
	ImageProcessor image = new ByteProcessor(40, 40);
	for (int y = 0; y < 40; y++)
	{
		double y2 = (y - 20.2);
		for (int x = 0; x < 40; x++)
		{
			double x2 = (x - 20.3);
			image.set(x, y, Math.hypot(x2, y2) < radius ? 255 : 0);
		}
	}
	
	// compute perimeter with default (1,1) calibration
	Calibration calib = new Calibration();
	double perim = IntrinsicVolumes2D.perimeter(image, calib, 2);
	
	// check to expected value with a tolerance of 5 percents
	double exp = 2 * Math.PI * radius;
	assertEquals(exp, perim, exp * 0.05);
}
 
Example #17
Source File: FloodFillTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link ijt.binary.FloodFiller#fill(int, int, int)}.
 */
@Test
public final void testFloodFill_Square() {
	ImageProcessor image = new ByteProcessor(10, 10);
	for (int y = 3; y < 7; y++) {
		for (int x = 3; x < 7; x++) {
			image.set(x, y, 8);
		}			
	}
	
	FloodFill.floodFill(image, 3, 3, 12, 4);
	
	for (int y = 3; y < 7; y++) {
		for (int x = 3; x < 7; x++) {
			assertEquals(12, image.get(x, y));
		}			
	}
}
 
Example #18
Source File: AreaOpeningQueueTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testProcess()
{
	int sizeX = 4;
	int sizeY = 4;
	ImageProcessor image = new ByteProcessor(sizeX, sizeY);
	image.set(1, 1, 5);
	image.set(2, 1, 4);
	image.set(1, 2, 3);
	image.set(2, 2, 2);
	
	AreaOpening algo = new AreaOpeningQueue();

	ImageProcessor output = algo.process(image, 4);
	
	assertEquals(2, output.get(1, 1));
	assertEquals(2, output.get(2, 1));
	assertEquals(2, output.get(1, 2));
	assertEquals(2, output.get(2, 2));
}
 
Example #19
Source File: CurveGap.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Compute the gap vector based on foreground pixels found in gap area.
 *
 * @param buf the binary buffer
 * @return the populated gap vector (in which a 1 value indicates a black pixel)
 */
public int[] computeVector (ByteProcessor buf)
{
    final Rectangle box = area.getBounds();

    for (int x = box.x, xBreak = box.x + box.width; x < xBreak; x++) {
        for (int y = box.y, yBreak = box.y + box.height; y < yBreak; y++) {
            if (area.contains(x, y)) {
                if (0 == buf.get(x, y)) {
                    populateVector(x - box.x, y - box.y);
                }
            }
        }
    }

    return vector;
}
 
Example #20
Source File: ClefBuilder.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Retrieve all glyph instances that could be part of clef.
 *
 * @param isFirstPass true for first pass
 * @return clef possible parts
 */
private List<Glyph> getParts (boolean isFirstPass)
{
    final Rectangle rect = isFirstPass ? outerRect : innerRect;

    // Grab pixels out of staff-free source
    ByteProcessor source = sheet.getPicture().getSource(Picture.SourceKey.NO_STAFF);
    ByteProcessor buf = new ByteProcessor(rect.width, rect.height);
    buf.copyBits(source, -rect.x, -rect.y, Blitter.COPY);

    // Extract parts
    RunTable runTable = new RunTableFactory(VERTICAL).createTable(buf);
    List<Glyph> parts = GlyphFactory.buildGlyphs(runTable, rect.getLocation());

    // Keep only interesting parts
    purgeParts(parts, isFirstPass);

    system.registerGlyphs(parts, null);
    logger.debug("{} parts: {}", this, parts.size());

    return parts;
}
 
Example #21
Source File: TimeBuilder.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * We use the NO_STAFF source of pixels.
 *
 * @return the projection on x-axis
 */
private IntegerFunction getProjection ()
{
    // Staff-free pixel source
    final ByteProcessor source = system.getSheet().getPicture().getSource(
            Picture.SourceKey.NO_STAFF);
    final int xMin = roi.x;
    final int xMax = (roi.x + roi.width) - 1;
    final IntegerFunction function = new IntegerFunction(xMin, xMax);

    for (int x = xMin; x <= xMax; x++) {
        short cumul = 0;

        for (int y = roi.y, yBreak = roi.y + roi.height; y < yBreak; y++) {
            if (source.get(x, y) == 0) {
                cumul++;
            }
        }

        function.setValue(x, cumul);
    }

    return function;
}
 
Example #22
Source File: Threshold.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new binary image with value 255 when input image has value
 * between <code>lower</code> and <code>upper</code> values (inclusive).
 * 
 * @param image
 *            the input grayscale image
 * @param lower
 *            the lower threshold bound (inclusive)
 * @param upper
 *            the upper threshold bound (inclusive)
 * @return a binary image
 */
public static final ImageProcessor threshold(ImageProcessor image, double lower, double upper)
{
	if (image instanceof ColorProcessor) 
	{
		throw new IllegalArgumentException("Requires a gray scale 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++)
		{
			double value = image.getf(x, y);
			if (value >= lower && value <= upper)
				result.set(x, y, 255);
		}

	}

	return result;
}
 
Example #23
Source File: IntrinsicVolumes2DTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link inra.ijpb.measure.IntrinsicVolumes2D#eulerNumber(ij.process.ImageProcessor, int)}.
 */
@Test
public final void testEulerNumber_fullSquareC4()
{
	// create a binary image containing a square
	ImageProcessor image = new ByteProcessor(6, 6);
	for (int i = 0; i < 6; i++)
	{
		for (int j = 0; j < 6; j++)
		{
			image.set(i, j, 255);
		}
	}
	
	int euler = IntrinsicVolumes2D.eulerNumber(image, 4);
	assertEquals(1, euler);
}
 
Example #24
Source File: SymbolsFilter.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Save the provided pixels as optional glyphs.
 *
 * @param box   the absolute bounding box of inter descriptor (perhaps larger than symbol)
 * @param fores foreground pixels with coordinates relative to descriptor bounding box
 */
private void savePixels (Rectangle box,
                         List<Point> fores)
{
    ByteProcessor buf = new ByteProcessor(box.width, box.height);
    ByteUtil.raz(buf); // buf.invert();

    for (Point p : fores) {
        buf.set(p.x, p.y, 0);
    }

    // Runs
    RunTableFactory factory = new RunTableFactory(SYMBOL_ORIENTATION);
    RunTable runTable = factory.createTable(buf);

    // Glyphs
    List<Glyph> glyphs = GlyphFactory.buildGlyphs(
            runTable,
            new Point(0, 0),
            GlyphGroup.SYMBOL);

    systemWeaks.addAll(glyphs);
}
 
Example #25
Source File: DistanceTransform5x5ShortTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public final void testDistanceMap_UntilCorners_Chessboard() 
{
	ByteProcessor image = new ByteProcessor(7, 7);
	image.setValue(255);
	image.fill();
	image.set(4, 4, 0);
	
	
	short[] weights = ChamferWeights.CHESSBOARD.getShortWeights();
	DistanceTransform5x5Short algo = new DistanceTransform5x5Short(weights, false);
	ImageProcessor result = algo.distanceMap(image);
	
	assertNotNull(result);
	assertEquals(image.getWidth(), result.getWidth());
	assertEquals(image.getHeight(), result.getHeight());
	assertEquals(4, result.get(0, 0));
	assertEquals(4, result.get(6, 0));
	assertEquals(4, result.get(0, 6));
	assertEquals(2, result.get(6, 6));
	
	assertEquals(4, result.get(0, 5));
}
 
Example #26
Source File: BinaryImages.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 #27
Source File: LargestInscribedCircleTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link inra.ijpb.measure.region2d.LargestInscribedCircle#analyzeRegions(ij.ImagePlus)}.
 */
@Test
public final void testAnalyzeRegionsImagePlus_Rectangles()
{
	ImageProcessor image = new ByteProcessor(14, 9);
	image.set(1, 1, 1);
	fillRect(image, 3, 4, 1, 2, 2);		// radius 2
	fillRect(image, 1, 1+3, 4, 4+3, 3); // radius 4
	fillRect(image, 6, 6+6, 1, 1+6, 4); // radius 7
	
	LargestInscribedCircle op = new LargestInscribedCircle();
	ResultsTable table = op.createTable(op.analyzeRegions(image, new Calibration()));
	
	assertEquals(1, table.getValue("InscrCircle.Radius", 0), .1);
	assertEquals(1, table.getValue("InscrCircle.Radius", 1), .1);
	assertEquals(2, table.getValue("InscrCircle.Radius", 2), .1);
	assertEquals(4, table.getValue("InscrCircle.Radius", 3), .1);
}
 
Example #28
Source File: DistanceTransform5x5FloatTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Another test for chess-knight weights, to fix a bug that incorrectly
 * checked image bounds.
 */
@Test
public final void testDistanceMap_UntilCorners_ChessKnight2()
{
	ByteProcessor image = new ByteProcessor(9, 9);
	image.setValue(255);
	image.fill();
	image.set(6, 6, 0);
	
	float[] weights = ChamferWeights.CHESSKNIGHT.getFloatWeights();
	DistanceTransform5x5Float algo = new DistanceTransform5x5Float(weights, false);
	ImageProcessor result = algo.distanceMap(image);
	
	assertNotNull(result);
	assertEquals(image.getWidth(), result.getWidth());
	assertEquals(image.getHeight(), result.getHeight());
	assertEquals(42, result.getf(0, 0), .01);
	assertEquals(32, result.getf(8, 0), .01);
	assertEquals(32, result.getf(0, 8), .01);
	assertEquals(14, result.getf(8, 8), .01);
	
	assertEquals(30, result.getf(0, 6), .01);
}
 
Example #29
Source File: OctagonStrelTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 #30
Source File: IntrinsicVolumes2DTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link inra.ijpb.measure.IntrinsicVolumes2D#perimeters(ij.process.ImageProcessor, int[], Calibration, int)}.
 */
@Test
public final void testPerimeters_disks_D2()
{
	// define several disks of increasing radius
	double xc1 = 25.2, yc1 = 25.3, r1 = 11.0;
	double xc2 = 75.2, yc2 = 25.3, r2 = 16.0;
	double xc3 = 21.2, yc3 = 75.3, r3 = 21.0;
	// the last one touching borders
	double xc4 = 73.2, yc4 = 73.3, r4 = 26.0;

	// create a binary image containing a square
	ImageProcessor image = new ByteProcessor(100, 100);
	for (int y = 0; y < 100; y++)
	{
		for (int x = 0; x < 100; x++)
		{
			if(Math.hypot(x-xc1, y-yc1) < r1) image.set(x, y, 1);
			if(Math.hypot(x-xc2, y-yc2) < r2) image.set(x, y, 2);
			if(Math.hypot(x-xc3, y-yc3) < r3) image.set(x, y, 3);
			if(Math.hypot(x-xc4, y-yc4) < r4) image.set(x, y, 4);
		}
	}
	
	// compute perimeter with default (1,1) calibration
	Calibration calib = new Calibration();
	int[] labels = new int[] {1, 2, 3, 4};
	double[] perims = IntrinsicVolumes2D.perimeters(image, labels, calib, 2);
	
	// check to expected values with a tolerance of 5 percents
	double exp1 = 2 * Math.PI * r1;
	assertEquals(exp1, perims[0], exp1 * 0.05);
	double exp2 = 2 * Math.PI * r2;
	assertEquals(exp2, perims[1], exp2 * 0.05);
	double exp3 = 2 * Math.PI * r3;
	assertEquals(exp3, perims[2], exp3 * 0.05);
	double exp4 = 2 * Math.PI * r4;
	assertEquals(exp4, perims[3], exp4 * 0.05);
}