当前位置: 首页>>代码示例>>Java>>正文


Java ThresholdImageOps类代码示例

本文整理汇总了Java中boofcv.alg.filter.binary.ThresholdImageOps的典型用法代码示例。如果您正苦于以下问题:Java ThresholdImageOps类的具体用法?Java ThresholdImageOps怎么用?Java ThresholdImageOps使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ThresholdImageOps类属于boofcv.alg.filter.binary包,在下文中一共展示了ThresholdImageOps类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getContours

import boofcv.alg.filter.binary.ThresholdImageOps; //导入依赖的package包/类
/**
 * Applies a contour-detection algorithm on the provided image and returns a list of detected contours. First, the image
 * is converted to a BinaryImage using a threshold algorithm (Otsu). Afterwards, blobs in the image are detected using
 * an 8-connect rule.
 *
 * @param image BufferedImage in which contours should be detected.
 * @return List of contours.
 */
public static List<Contour> getContours(BufferedImage image) {
    /* Draw a black frame around to image so as to make sure that all detected contours are internal contours. */
    BufferedImage resized = new BufferedImage(image.getWidth() + 4, image.getHeight() + 4, image.getType());
    Graphics g = resized.getGraphics();
    g.setColor(Color.BLACK);
    g.fillRect(0,0,resized.getWidth(),resized.getHeight());
    g.drawImage(image, 2,2, image.getWidth(), image.getHeight(), null);

    /* Convert to BufferedImage to Gray-scale image and prepare Binary image. */
    GrayF32 input = ConvertBufferedImage.convertFromSingle(resized, null, GrayF32.class);
    GrayU8 binary = new GrayU8(input.width,input.height);
    GrayS32 label = new GrayS32(input.width,input.height);

    /* Select a global threshold using Otsu's method and apply that threshold. */
    double threshold = GThresholdImageOps.computeOtsu(input, 0, 255);
    ThresholdImageOps.threshold(input, binary,(float)threshold,true);

    /* Remove small blobs through erosion and dilation;  The null in the input indicates that it should internally
     * declare the work image it needs this is less efficient, but easier to code. */
    GrayU8 filtered = BinaryImageOps.erode8(binary, 1, null);
    filtered = BinaryImageOps.dilate8(filtered, 1, null);

    /* Detect blobs inside the image using an 8-connect rule. */
    return BinaryImageOps.contour(filtered, ConnectRule.EIGHT, label);
}
 
开发者ID:vitrivr,项目名称:cineast,代码行数:34,代码来源:ContourHelper.java

示例2: init

import boofcv.alg.filter.binary.ThresholdImageOps; //导入依赖的package包/类
@Override
public void init(RunConfig config) throws InvalidTestFormatException {
	super.init(config);

	File file = new File(GR.getGoldenDir(), goldenFileName);
	try {
		InputStream inImageStream = MTTestResourceManager.openFileAsInputStream(file.getPath());
		ImageUInt8 inImage = UtilImageIO.loadPGM_U8(inImageStream, (ImageUInt8) null);
		image = ConvertImage.convert(inImage, (ImageFloat32) null);
		ImageUInt8 bin = new ImageUInt8(image.width, image.height);
		double mean = ImageStatistics.mean(image);
		ThresholdImageOps.threshold(image, bin, (float) mean, true);
		filtered = BinaryImageOps.erode8(bin, 1, null);
		filtered = BinaryImageOps.dilate8(filtered, 1, null);
	} catch (IOException e) {
		throw new GoldenFileNotFoundException(file, this.getClass());
	}
}
 
开发者ID:android-workloads,项目名称:JACWfA,代码行数:19,代码来源:FitEllipse.java

示例3: detect

import boofcv.alg.filter.binary.ThresholdImageOps; //导入依赖的package包/类
@Override
public List<LineParametric2D_F32> detect(I input) {
	derivX.reshape(input.width,input.height);
	derivY.reshape(input.width,input.height);
	intensity.reshape(input.width,input.height);
	binary.reshape(input.width,input.height);

	gradient.process(input,derivX,derivY);
	GGradientToEdgeFeatures.intensityAbs(derivX, derivY, intensity);

	ThresholdImageOps.threshold(intensity, binary, thresholdEdge, false);

	alg.transform(derivX,derivY,binary);
	FastQueue<LineParametric2D_F32> lines = alg.extractLines();

	List<LineParametric2D_F32> ret = new ArrayList<LineParametric2D_F32>();
	for( int i = 0; i < lines.size; i++ )
		ret.add(lines.get(i));

	ret = pruneLines(input,ret);

	return ret;
}
 
开发者ID:intrack,项目名称:BoofCV-master,代码行数:24,代码来源:DetectLineHoughFoot.java

示例4: maskBackground

import boofcv.alg.filter.binary.ThresholdImageOps; //导入依赖的package包/类
public static BufferedImage maskBackground(BufferedImage image) {
    GrayU8 gray = ConvertBufferedImage.convertFromSingle(image, null, GrayU8.class);
    int threshold = gray.get(1, 1); // get background pixel - would be better to average some
    GrayU8 binary = ThresholdImageOps.threshold(gray, null, threshold, true);
    GrayF32 mask = ConvertImage.convert(binary, (GrayF32) null);
    return mask(image, mask);
}
 
开发者ID:tomwhite,项目名称:set-game,代码行数:8,代码来源:ImageUtils.java

示例5: binarize

import boofcv.alg.filter.binary.ThresholdImageOps; //导入依赖的package包/类
public GrayImageProcessor binarize(int minValue, int maxValue, boolean down) {
    // Select a global threshold using Otsu's method.
    double threshold = GThresholdImageOps.computeOtsu(image, minValue, maxValue);
    // Apply the threshold to create a binary image
    GrayU8 newImage = ThresholdImageOps.threshold(image, null, (int) threshold, down);
    addImageToPanel(newImage, String.format("Binarize (min %d, max %d, down %s)", minValue, maxValue, down));
    return new GrayImageProcessor(newImage);
}
 
开发者ID:tomwhite,项目名称:set-game,代码行数:9,代码来源:ImageProcessingPipeline.java

示例6: generateBlackWhiteImage

import boofcv.alg.filter.binary.ThresholdImageOps; //导入依赖的package包/类
static BufferedImage generateBlackWhiteImage(String path, boolean save) throws IOException {
    BufferedImage in = ImageIO.read(new File(path));

    // convert into a usable format
    GrayF32 input = ConvertBufferedImage.convertFromSingle(in, null, GrayF32.class);
    GrayU8 binary = new GrayU8(input.width, input.height);
    GrayS32 label = new GrayS32(input.width, input.height);

    // Select a global threshold using Otsu's method.
    double threshold = GThresholdImageOps.computeOtsu(input, 0, 255);

    // Apply the threshold to create a binary image
    ThresholdImageOps.threshold(input, binary, (float) threshold, true);

    // remove small blobs through erosion and dilation
    // The null in the input indicates that it should internally declare the work image it needs
    // this is less efficient, but easier to code.
    GrayU8 filtered = BinaryImageOps.erode8(binary, 1, null);
    filtered = BinaryImageOps.dilate8(filtered, 1, null);

    // Detect blobs inside the image using an 8-connect rule
    List<Contour> contours = BinaryImageOps.contour(filtered, ConnectRule.EIGHT, label);

    // display the results
    BufferedImage visualBinary = VisualizeBinaryData.renderBinary(binary, false, null);


    if (save) { // Save the image, if necessary
        File outputfile = new File("saved.png");
        ImageIO.write(visualBinary, "png", outputfile);
    }

    System.out.println("Done with part 1!");

    return visualBinary;

}
 
开发者ID:tuomilabs,项目名称:readySET,代码行数:38,代码来源:Test.java

示例7: threshold3D

import boofcv.alg.filter.binary.ThresholdImageOps; //导入依赖的package包/类
public static ArrayList<GrayU8> threshold3D(ArrayList<GrayU8> input, ArrayList<GrayU8> output, int threshold){
	
	for (int i = 0; i < input.size(); ++i){
		ThresholdImageOps.threshold(input.get(i), output.get(i), threshold, false);
	}
	
	return output;
}
 
开发者ID:vitrivr,项目名称:cineast,代码行数:9,代码来源:MaskGenerator.java

示例8: iteration

import boofcv.alg.filter.binary.ThresholdImageOps; //导入依赖的package包/类
@Override
public long iteration() {
	long count = 0;
	for (int i = 0; i < repeats; i++) {
		double threshold = GThresholdImageOps.computeOtsu(image, 0, 256);
		ThresholdImageOps.threshold(image, binary, (float) threshold, true);
		count++;
	}
	return count++;
}
 
开发者ID:android-workloads,项目名称:JACWfA,代码行数:11,代码来源:BinaryImage.java

示例9: main

import boofcv.alg.filter.binary.ThresholdImageOps; //导入依赖的package包/类
public static void main( String args[] ) {
	// load and convert the image into a usable format
	BufferedImage image = UtilImageIO.loadImage("../data/applet/particles01.jpg");

	// convert into a usable format
	ImageFloat32 input = ConvertBufferedImage.convertFromSingle(image, null, ImageFloat32.class);
	ImageUInt8 binary = new ImageUInt8(input.width,input.height);
	ImageSInt32 label = new ImageSInt32(input.width,input.height);

	// the mean pixel value is often a reasonable threshold when creating a binary image
	double mean = ImageStatistics.mean(input);

	// create a binary image by thresholding
	ThresholdImageOps.threshold(input,binary,(float)mean,true);

	// remove small blobs through erosion and dilation
	// The null in the input indicates that it should internally declare the work image it needs
	// this is less efficient, but easier to code.
	ImageUInt8 filtered = BinaryImageOps.erode8(binary,null);
	filtered = BinaryImageOps.dilate8(filtered, null);

	// Detect blobs inside the image using an 8-connect rule
	List<Contour> contours = BinaryImageOps.contour(filtered, 8, label);

	// colors of contours
	int colorExternal = 0xFFFFFF;
	int colorInternal = 0xFF2020;

	// display the results
	BufferedImage visualBinary = VisualizeBinaryData.renderBinary(binary, null);
	BufferedImage visualFiltered = VisualizeBinaryData.renderBinary(filtered, null);
	BufferedImage visualLabel = VisualizeBinaryData.renderLabeled(label, contours.size(), null);
	BufferedImage visualContour = VisualizeBinaryData.renderContours(contours,colorExternal,colorInternal,
			input.width,input.height,null);

	ShowImages.showWindow(visualBinary,"Binary Original");
	ShowImages.showWindow(visualFiltered,"Binary Filtered");
	ShowImages.showWindow(visualLabel,"Labeled Blobs");
	ShowImages.showWindow(visualContour,"Contours");
}
 
开发者ID:intrack,项目名称:BoofCV-master,代码行数:41,代码来源:ExampleBinaryOps.java

示例10: main

import boofcv.alg.filter.binary.ThresholdImageOps; //导入依赖的package包/类
public static void main( String args[] ) {
		// load and convert the image into a usable format
		BufferedImage image = UtilImageIO.loadImage("../data/applet/particles01.jpg");
		ImageFloat32 input = ConvertBufferedImage.convertFromSingle(image, null, ImageFloat32.class);

		ImageUInt8 binary = new ImageUInt8(input.width,input.height);

		// the mean pixel value is often a reasonable threshold when creating a binary image
		double mean = ImageStatistics.mean(input);

		// create a binary image by thresholding
		ThresholdImageOps.threshold(input, binary, (float) mean, true);

		// reduce noise with some filtering
		ImageUInt8 filtered = BinaryImageOps.erode8(binary,null);
		filtered = BinaryImageOps.dilate8(filtered, null);

		// Find the contour around the shapes
		List<Contour> contours = BinaryImageOps.contour(filtered,8,null);

		// Fit an ellipse to each external contour and draw the results
		Graphics2D g2 = image.createGraphics();
		g2.setStroke(new BasicStroke(3));
		g2.setColor(Color.RED);

		for( Contour c : contours ) {
			FitData<EllipseRotated_F64> ellipse = ShapeFittingOps.fitEllipse_I32(c.external,0,false,null);
			VisualizeShapes.drawEllipse(ellipse.shape, g2);
		}

//		ShowImages.showWindow(VisualizeBinaryData.renderBinary(filtered,null),"Binary");
		ShowImages.showWindow(image,"Ellipses");
	}
 
开发者ID:intrack,项目名称:BoofCV-master,代码行数:34,代码来源:ExampleFitEllipse.java

示例11: detect

import boofcv.alg.filter.binary.ThresholdImageOps; //导入依赖的package包/类
@Override
public List<LineParametric2D_F32> detect(I input) {
	derivX.reshape(input.width,input.height);
	derivY.reshape(input.width,input.height);
	intensity.reshape(input.width,input.height);
	binary.reshape(input.width,input.height);

	gradient.process(input,derivX,derivY);
	GGradientToEdgeFeatures.intensityAbs(derivX, derivY, intensity);

	ThresholdImageOps.threshold(intensity, binary, thresholdEdge, false);

	List<LineParametric2D_F32> ret = new ArrayList<LineParametric2D_F32>();
	post.reset();

	for( int i = 0; i < totalVerticalDivisions; i++ ) {
		int y0 = input.height*i/totalVerticalDivisions;
		int y1 = input.height*(i+1)/totalVerticalDivisions;

		for( int j = 0; j < totalHorizontalDivisions; j++ ) {
			int x0 = input.width*j/totalVerticalDivisions;
			int x1 = input.width*(j+1)/totalVerticalDivisions;

			processSubimage(x0,y0,x1,y1,ret);
		}
	}

	// removing duplicate lines  caused by processing sub-images
	ret = pruneLines(input);

	return ret;
}
 
开发者ID:intrack,项目名称:BoofCV-master,代码行数:33,代码来源:DetectLineHoughFootSubimage.java

示例12: fitBinaryImage

import boofcv.alg.filter.binary.ThresholdImageOps; //导入依赖的package包/类
/**
     * Fits polygons to found contours around binary blobs.
     */
    private static List<Card> fitBinaryImage(GrayF32 input, String path) throws IOException {
        List<Card> cards = new ArrayList<>();

        GrayU8 binary = new GrayU8(input.width, input.height);
        BufferedImage polygon = new BufferedImage(input.width, input.height, BufferedImage.TYPE_INT_RGB);

        // the mean pixel value is often a reasonable threshold when creating a binary image
        double mean = ImageStatistics.mean(input);

        // create a binary image by thresholding
        ThresholdImageOps.threshold(input, binary, (float) mean, true);

        // reduce noise with some filtering
        GrayU8 filtered = BinaryImageOps.erode8(binary, 1, null);
        filtered = BinaryImageOps.dilate8(filtered, 1, null);

        // Find the contour around the shapes
        List<Contour> contours = BinaryImageOps.contour(filtered, ConnectRule.EIGHT, null);

        // Fit a polygon to each shape and draw the results
        Graphics2D g2 = polygon.createGraphics();
        g2.setStroke(new BasicStroke(2));

        int count = FILENAME_START_INTEGER;
        for (Contour c : contours) {
            // Fit the polygon to the found external contour.  Note loop = true
            List<PointIndex_I32> vertexes = ShapeFittingOps.fitPolygon(c.external, true,
                    splitFraction, minimumSideFraction, 100);

            g2.setColor(Color.RED);
            int longDiagonal = getLongDiagonal(vertexes);
            //System.out.println(longDiagonal);

            if (longDiagonal > CARD_MIN_DIAGONAL_SIZE_PIXELS) {
                VisualizeShapes.drawPolygon(vertexes, true, g2);
                extractPolygon(vertexes, count++, path);
            }

            // handle internal contours now
            g2.setColor(Color.BLUE);
            int number = 0;
            for (List<Point2D_I32> internal : c.internal) {
                number++;
                vertexes = ShapeFittingOps.fitPolygon(internal, true, splitFraction, minimumSideFraction, 100);
                VisualizeShapes.drawPolygon(vertexes, true, g2);
            }

            if (number != 0) {
                System.out.println("Number: " + number);

                int shape = 0;
//                Scanner reader = new Scanner(System.in);  // Reading from System.in
//                System.out.println("Can't read shape. Which shape is it?");
//                shape = reader.nextInt(); // Scans the next token of the input as an int.
                shape = 2;

                int color = 0;

                int fill = 0;
//                System.out.println("Can't read fill. Which fill is it?");
//                shape = reader.nextInt(); // Scans the next token of the input as an int.



                cards.add(new Card(shape, color, number - 1, fill));
            }
        }

        gui.addImage(polygon, "Binary Blob Contours");

        return cards;
    }
 
开发者ID:tuomilabs,项目名称:readySET,代码行数:76,代码来源:ActualMain.java

示例13: main

import boofcv.alg.filter.binary.ThresholdImageOps; //导入依赖的package包/类
/**
 * The main method.
 *
 * @param args the arguments
 */
public static void main( String args[] ) {
	// load and convert the image into a usable format
	BufferedImage image = UtilImageIO.loadImage(UtilIO.pathExample("/home/pete/development/gitrepo/iote2e/iote2e-tests/images/iote2e-test.png"));

	// convert into a usable format
	GrayF32 input = ConvertBufferedImage.convertFromSingle(image, null, GrayF32.class);
	GrayU8 binary = new GrayU8(input.width,input.height);
	GrayS32 label = new GrayS32(input.width,input.height);

	// Select a global threshold using Otsu's method.
	double threshold = GThresholdImageOps.computeOtsu(input, 0, 255);

	// Apply the threshold to create a binary image
	ThresholdImageOps.threshold(input,binary,(float)threshold,true);

	// remove small blobs through erosion and dilation
	// The null in the input indicates that it should internally declare the work image it needs
	// this is less efficient, but easier to code.
	GrayU8 filtered = BinaryImageOps.erode8(binary, 1, null);
	filtered = BinaryImageOps.dilate8(filtered, 1, null);

	// Detect blobs inside the image using an 8-connect rule
	List<Contour> contours = BinaryImageOps.contour(filtered, ConnectRule.EIGHT, label);

	// colors of contours
	int colorExternal = 0xFFFFFF;
	int colorInternal = 0xFF2020;

	// display the results
	BufferedImage visualBinary = VisualizeBinaryData.renderBinary(binary, false, null);
	BufferedImage visualFiltered = VisualizeBinaryData.renderBinary(filtered, false, null);
	BufferedImage visualLabel = VisualizeBinaryData.renderLabeledBG(label, contours.size(), null);
	BufferedImage visualContour = VisualizeBinaryData.renderContours(contours, colorExternal, colorInternal,
			input.width, input.height, null);

	ListDisplayPanel panel = new ListDisplayPanel();
	panel.addImage(visualBinary, "Binary Original");
	panel.addImage(visualFiltered, "Binary Filtered");
	panel.addImage(visualLabel, "Labeled Blobs");
	panel.addImage(visualContour, "Contours");
	ShowImages.showWindow(panel,"Binary Operations",true);
}
 
开发者ID:petezybrick,项目名称:iote2e,代码行数:48,代码来源:ExampleBinaryOps.java

示例14: fitBinaryImage

import boofcv.alg.filter.binary.ThresholdImageOps; //导入依赖的package包/类
/**
 * Fits polygons to found contours around binary blobs.
 */
public static void fitBinaryImage(ImageFloat32 input) {

	ImageUInt8 binary = new ImageUInt8(input.width,input.height);
	BufferedImage polygon = new BufferedImage(input.width,input.height,BufferedImage.TYPE_INT_RGB);

	// the mean pixel value is often a reasonable threshold when creating a binary image
	double mean = ImageStatistics.mean(input);

	// create a binary image by thresholding
	ThresholdImageOps.threshold(input, binary, (float) mean, true);

	// reduce noise with some filtering
	ImageUInt8 filtered = BinaryImageOps.erode8(binary,null);
	filtered = BinaryImageOps.dilate8(filtered, null);

	// Find the contour around the shapes
	List<Contour> contours = BinaryImageOps.contour(filtered,8,null);

	// Fit a polygon to each shape and draw the results
	Graphics2D g2 = polygon.createGraphics();
	g2.setStroke(new BasicStroke(2));

	for( Contour c : contours ) {
		// Fit the polygon to the found external contour.  Note loop = true
		List<PointIndex_I32> vertexes = ShapeFittingOps.fitPolygon(c.external,true,
				toleranceDist,toleranceAngle,100);

		g2.setColor(Color.RED);
		VisualizeShapes.drawPolygon(vertexes,true,g2);

		// handle internal contours now
		g2.setColor(Color.BLUE);
		for( List<Point2D_I32> internal : c.internal ) {
			vertexes = ShapeFittingOps.fitPolygon(internal,true,toleranceDist,toleranceAngle,100);
			VisualizeShapes.drawPolygon(vertexes,true,g2);
		}
	}

	ShowImages.showWindow(polygon,"Binary Blob Contours");
}
 
开发者ID:intrack,项目名称:BoofCV-master,代码行数:44,代码来源:ExampleFitPolygon.java

示例15: detect

import boofcv.alg.filter.binary.ThresholdImageOps; //导入依赖的package包/类
@Override
	public List<LineParametric2D_F32> detect(I input) {
		// see if the input image shape has changed.
		if( derivX.width != input.width || derivY.height != input.height ) {
			double r = Math.sqrt(input.width*input.width + input.height*input.height);
			int numBinsRange = (int)Math.ceil(r/resolutionRange);
			int numBinsAngle = (int)Math.ceil(Math.PI/resolutionAngle);

			alg = new HoughTransformLinePolar(extractor,numBinsRange,numBinsAngle);
			derivX.reshape(input.width,input.height);
			derivY.reshape(input.width,input.height);
			intensity.reshape(input.width,input.height);
			binary.reshape(input.width, input.height);
//		angle.reshape(input.width, input.height);
//		direction.reshape(input.width, input.height);
			suppressed.reshape(input.width, input.height);
		}

		gradient.process(input, derivX, derivY);
		GGradientToEdgeFeatures.intensityAbs(derivX, derivY, intensity);

		// non-max suppression reduces the number of line pixels, reducing the number of false positives
		// When too many pixels are flagged, then more curves randomly cross over in transform space causing
		// false positives

//		GGradientToEdgeFeatures.direction(derivX, derivY, angle);
//		GradientToEdgeFeatures.discretizeDirection4(angle, direction);
//		GradientToEdgeFeatures.nonMaxSuppression4(intensity,direction, suppressed);

		GGradientToEdgeFeatures.nonMaxSuppressionCrude4(intensity,derivX,derivY,suppressed);

		ThresholdImageOps.threshold(suppressed, binary, thresholdEdge, false);

		alg.transform(binary);
		FastQueue<LineParametric2D_F32> lines = alg.extractLines();

		List<LineParametric2D_F32> ret = new ArrayList<LineParametric2D_F32>();
		for( int i = 0; i < lines.size; i++ )
			ret.add(lines.get(i));

		ret = pruneLines(input, ret);

		return ret;
	}
 
开发者ID:intrack,项目名称:BoofCV-master,代码行数:45,代码来源:DetectLineHoughPolar.java


注:本文中的boofcv.alg.filter.binary.ThresholdImageOps类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。