本文整理汇总了Java中boofcv.alg.filter.binary.BinaryImageOps.erode8方法的典型用法代码示例。如果您正苦于以下问题:Java BinaryImageOps.erode8方法的具体用法?Java BinaryImageOps.erode8怎么用?Java BinaryImageOps.erode8使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boofcv.alg.filter.binary.BinaryImageOps
的用法示例。
在下文中一共展示了BinaryImageOps.erode8方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getContours
import boofcv.alg.filter.binary.BinaryImageOps; //导入方法依赖的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);
}
示例2: init
import boofcv.alg.filter.binary.BinaryImageOps; //导入方法依赖的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());
}
}
示例3: generateBlackWhiteImage
import boofcv.alg.filter.binary.BinaryImageOps; //导入方法依赖的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;
}
示例4: main
import boofcv.alg.filter.binary.BinaryImageOps; //导入方法依赖的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");
}
示例5: main
import boofcv.alg.filter.binary.BinaryImageOps; //导入方法依赖的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");
}
示例6: process
import boofcv.alg.filter.binary.BinaryImageOps; //导入方法依赖的package包/类
/**
* Processes the image and detects calibration targets. If one is found then
* true is returned and calibration points are extracted.
*
* @param thresholded Binary image where potential grid squares are set to one.
* @return True if it was successful and false otherwise. If false call getMessage() for details.
*/
public boolean process( ImageUInt8 thresholded )
{
// discard old results
interestPoints = new ArrayList<Point2D_F64>();
interestSquares = new ArrayList<QuadBlob>();
// adjust threshold for image size
int contourSize = (int)(relativeSizeThreshold*80.0/640.0*thresholded.width);
detectBlobs.setMinContourSize(contourSize);
// initialize data structures
binaryA.reshape(thresholded.width,thresholded.height);
binaryB.reshape(thresholded.width,thresholded.height);
// filter out small objects
BinaryImageOps.erode8(thresholded,binaryA);
BinaryImageOps.erode8(binaryA,binaryB);
BinaryImageOps.dilate8(binaryB, binaryA);
BinaryImageOps.dilate8(binaryA,binaryB);
if( !detectBlobs.process(binaryB) )
return fail(detectBlobs.getMessage());
squares = detectBlobs.getDetected();
// find connections between squares
ConnectGridSquares.connect(squares);
// Remove all but the largest islands in the graph to reduce the number of combinations
List<QuadBlob> squaresPruned = ConnectGridSquares.pruneSmallIslands(squares);
// System.out.println("Found "+squaresPruned.size()+" blobs");
// given all the blobs, only consider N at one time until a valid target is found
return shuffleToFindTarget(squaresPruned);
}
示例7: detectChessBoard
import boofcv.alg.filter.binary.BinaryImageOps; //导入方法依赖的package包/类
/**
* Threshold the image and find squares
*/
private boolean detectChessBoard(T gray, double threshold , boolean first ) {
actualBinaryThreshold = threshold;
if( actualBinaryThreshold < 0 )
actualBinaryThreshold = UtilCalibrationGrid.selectThreshold(gray,histogram);
GThresholdImageOps.threshold(gray, binary, actualBinaryThreshold, true);
// erode to make the squares separated
BinaryImageOps.erode8(binary, eroded);
if (findBound.process(eroded)) {
if( userBinaryThreshold < 0 ) {
// second pass to improve threshold
return detectChessBoardSubImage(gray);
} else {
return true;
}
} else if( first && userBinaryThreshold < 0 ) {
// if the target is small and the background dark, the threshold will be too low
// if the target is small and the background white, it will still estimate a good threshold
// so try a larger value before giving up
threshold = (255+threshold)/2;
return detectChessBoard(gray,threshold,false);
}
return false;
}
示例8: detectChessBoardSubImage
import boofcv.alg.filter.binary.BinaryImageOps; //导入方法依赖的package包/类
/**
* Look for the target only inside a specific region. The threshold can be more accurate selected this way
*/
private boolean detectChessBoardSubImage( T gray ) {
// region the target is contained inside of
ImageRectangle targetBound = findBound.getBoundRect();
// expand the bound a bit
int w = targetBound.getWidth();
int h = targetBound.getHeight();
ImageRectangle expanded = new ImageRectangle();
int adj = (int)(w*0.12);
expanded.x0 = targetBound.x0-adj;
expanded.x1 = targetBound.x1+adj;
adj = (int)(h*0.12);
expanded.y0 = targetBound.y0-adj;
expanded.y1 = targetBound.y1+adj;
BoofMiscOps.boundRectangleInside(gray, expanded);
// create sub-images for processing. recompute threshold just around the area of interest and
// only look for the target inside that
T subGray = (T)gray.subimage(expanded.x0,expanded.y0,expanded.x1,expanded.y1);
actualBinaryThreshold = UtilCalibrationGrid.selectThreshold(subGray,histogram);
GImageMiscOps.fill(binary,0);
ImageUInt8 subBinary = (ImageUInt8)binary.subimage(expanded.x0,expanded.y0,expanded.x1,expanded.y1);
GThresholdImageOps.threshold(subGray, subBinary, actualBinaryThreshold, true);
// The new threshold tends to require two erodes
BinaryImageOps.erode8(binary, eroded);
BinaryImageOps.erode4(eroded, binary);
BinaryImageOps.dilate4(binary, eroded);
if (findBound.process(eroded))
return true;
return false;
}
示例9: process
import boofcv.alg.filter.binary.BinaryImageOps; //导入方法依赖的package包/类
public void process( final BufferedImage input ) {
setInputImage(input);
this.input.reshape(input.getWidth(),input.getHeight());
ConvertBufferedImage.convertFromSingle(input, this.input, ImageUInt8.class);
this.binary.reshape(input.getWidth(), input.getHeight());
this.filtered.reshape(input.getWidth(),input.getHeight());
this.output = new BufferedImage( input.getWidth(), input.getHeight(), BufferedImage.TYPE_INT_RGB);
// the mean pixel value is often a reasonable threshold when creating a binary image
double mean = ImageStatistics.mean(this.input);
// create a binary image by thresholding
GThresholdImageOps.threshold(this.input, binary, mean, true);
// reduce noise with some filtering
BinaryImageOps.erode8(binary, filtered);
BinaryImageOps.dilate8(filtered, binary);
// Find the contour around the shapes
contours = BinaryImageOps.contour(binary,8,null);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
gui.setPreferredSize(new Dimension(input.getWidth(), input.getHeight()));
processImage = true;
}});
doRefreshAll();
}
示例10: erode
import boofcv.alg.filter.binary.BinaryImageOps; //导入方法依赖的package包/类
public GrayImageProcessor erode() {
GrayU8 newImage = BinaryImageOps.erode8(image, 1, null);
addImageToPanel(newImage, String.format("Erode"));
return new GrayImageProcessor(newImage);
}
示例11: fitBinaryImage
import boofcv.alg.filter.binary.BinaryImageOps; //导入方法依赖的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;
}
示例12: main
import boofcv.alg.filter.binary.BinaryImageOps; //导入方法依赖的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);
}
示例13: erode8
import boofcv.alg.filter.binary.BinaryImageOps; //导入方法依赖的package包/类
public SimpleBinary erode8( int numTimes ) {
GrayU8 out = new GrayU8(image.width, image.height);
BinaryImageOps.erode8(image,numTimes,out);
return new SimpleBinary(out);
}
示例14: fitBinaryImage
import boofcv.alg.filter.binary.BinaryImageOps; //导入方法依赖的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");
}