本文整理汇总了Java中boofcv.alg.filter.binary.BinaryImageOps.dilate8方法的典型用法代码示例。如果您正苦于以下问题:Java BinaryImageOps.dilate8方法的具体用法?Java BinaryImageOps.dilate8怎么用?Java BinaryImageOps.dilate8使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boofcv.alg.filter.binary.BinaryImageOps
的用法示例。
在下文中一共展示了BinaryImageOps.dilate8方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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();
}
示例8: dilate
import boofcv.alg.filter.binary.BinaryImageOps; //导入方法依赖的package包/类
public GrayImageProcessor dilate() {
GrayU8 newImage = BinaryImageOps.dilate8(image, 1, null);
addImageToPanel(newImage, String.format("Dilate"));
return new GrayImageProcessor(newImage);
}
示例9: 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;
}
示例10: 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);
}
示例11: dilate8
import boofcv.alg.filter.binary.BinaryImageOps; //导入方法依赖的package包/类
public SimpleBinary dilate8( int numTimes ) {
GrayU8 out = new GrayU8(image.width, image.height);
BinaryImageOps.dilate8(image,numTimes,out);
return new SimpleBinary(out);
}
示例12: 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");
}