本文整理汇总了Java中boofcv.alg.filter.binary.BinaryImageOps类的典型用法代码示例。如果您正苦于以下问题:Java BinaryImageOps类的具体用法?Java BinaryImageOps怎么用?Java BinaryImageOps使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BinaryImageOps类属于boofcv.alg.filter.binary包,在下文中一共展示了BinaryImageOps类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: removeBinaryNoise
import boofcv.alg.filter.binary.BinaryImageOps; //导入依赖的package包/类
/**
* Remove all but the largest blob. Any sporadic pixels will be zapped this way
*
* @param binary Initial binary image. Modified
*/
private void removeBinaryNoise(ImageUInt8 binary) {
// remove potential noise by only saving the largest cluster
List<Contour> contours = BinaryImageOps.contour(binary, 4, blobs);
// find the largest blob
Contour largest = null;
for( Contour c : contours ) {
if( largest == null || largest.external.size() < c.external.size() ) {
largest = c;
}
}
if( largest == null )
return;
// recreate the binary image using only the largest blob
int labels[] = new int[ contours.size() + 1 ];
labels[ largest.id ] = 1;
BinaryImageOps.relabel(blobs,labels);
BinaryImageOps.labelToBinary(blobs,binary);
}
示例4: performWork
import boofcv.alg.filter.binary.BinaryImageOps; //导入依赖的package包/类
private synchronized void performWork() {
if( filter1 == null || filter2 == null )
return;
GThresholdImageOps.threshold(imageInput, imageBinary, selectThresh.getThreshold(), selectThresh.isDown());
filter1.process(imageBinary,imageOutput1);
filter2.process(imageOutput1,imageOutput2);
List<Contour> found = BinaryImageOps.contour(imageOutput2, connectRule, imageLabeled);
if( colors == null || colors.length <= found.size() )
colors = BinaryImageOps.selectRandomColors(found.size(),rand);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (work == null || work.getWidth() != imageInput.width || work.getHeight() != imageInput.height) {
work = new BufferedImage(imageInput.width, imageInput.height, BufferedImage.TYPE_INT_BGR);
}
renderVisualizeImage();
gui.setBufferedImage(work);
gui.setPreferredSize(new Dimension(imageInput.width, imageInput.height));
processedImage = true;
gui.repaint();
}
});
}
示例5: getCannyContours
import boofcv.alg.filter.binary.BinaryImageOps; //导入依赖的package包/类
public static List<Contour> getCannyContours(BufferedImage image) {
GrayU8 gray = ConvertBufferedImage.convertFrom(image, (GrayU8) null);
GrayU8 edgeImage = gray.createSameShape();
canny.process(gray, 0.1f, 0.3f, edgeImage);
List<Contour> contours = BinaryImageOps.contour(edgeImage, ConnectRule.EIGHT, null);
return contours;
}
示例6: run
import boofcv.alg.filter.binary.BinaryImageOps; //导入依赖的package包/类
private void run() throws IOException {
BufferedImage image = UtilImageIO.loadImage(UtilIO.pathExample("C:\\development\\readySET\\deck\\1221.png"));
GrayU8 gray = ConvertBufferedImage.convertFrom(image,(GrayU8)null);
GrayU8 edgeImage = gray.createSameShape();
// Create a canny edge detector which will dynamically compute the threshold based on maximum edge intensity
// It has also been configured to save the trace as a graph. This is the graph created while performing
// hysteresis thresholding.
CannyEdge<GrayU8,GrayS16> canny = FactoryEdgeDetectors.canny(2,true, true, GrayU8.class, GrayS16.class);
// The edge image is actually an optional parameter. If you don't need it just pass in null
canny.process(gray,0.1f,0.3f,edgeImage);
// First get the contour created by canny
List<EdgeContour> edgeContours = canny.getContours();
// The 'edgeContours' is a tree graph that can be difficult to process. An alternative is to extract
// the contours from the binary image, which will produce a single loop for each connected cluster of pixels.
// Note that you are only interested in verticesnal contours.
List<Contour> contours = BinaryImageOps.contour(edgeImage, ConnectRule.EIGHT, null);
// display the results
BufferedImage visualBinary = VisualizeBinaryData.renderBinary(edgeImage, false, null);
BufferedImage visualCannyContour = VisualizeBinaryData.renderContours(edgeContours,null,
gray.width,gray.height,null);
BufferedImage visualEdgeContour = new BufferedImage(gray.width, gray.height,BufferedImage.TYPE_INT_RGB);
VisualizeBinaryData.render(contours, (int[]) null, visualEdgeContour);
ListDisplayPanel panel = new ListDisplayPanel();
panel.addImage(visualBinary,"Binary Edges from Canny");
panel.addImage(visualCannyContour, "Canny Trace Graph");
panel.addImage(visualEdgeContour,"Contour from Canny Binary");
ShowImages.showWindow(panel,"Canny Edge", true);
}
示例7: 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;
}
示例8: iteration
import boofcv.alg.filter.binary.BinaryImageOps; //导入依赖的package包/类
@Override
public long iteration() {
long count = 0;
for (int i = 0; i < repeats; i++) {
List<Contour> contours = BinaryImageOps.contour(filtered,
ConnectRule.EIGHT, null);
for (Contour c : contours) {
result = ShapeFittingOps.fitEllipse_I32(c.external, 0, false,
null);
}
count++;
}
return count;
}
示例9: contour
import boofcv.alg.filter.binary.BinaryImageOps; //导入依赖的package包/类
/**
* Finds the contours of blobs in a binary image. Uses 8-connect rule
*
* @see BinaryImageOps#contour
*/
public ResultsBlob contour() {
GrayS32 labeled = new GrayS32(image.width,image.height);
List<Contour> contours = BinaryImageOps.contour(image, ConnectRule.EIGHT, labeled);
return new ResultsBlob(contours,labeled);
}
示例10: main
import boofcv.alg.filter.binary.BinaryImageOps; //导入依赖的package包/类
public static void main( String args[] ) {
BufferedImage image = UtilImageIO.loadImage("../data/applet/simple_objects.jpg");
ImageUInt8 gray = ConvertBufferedImage.convertFrom(image,(ImageUInt8)null);
ImageUInt8 edgeImage = new ImageUInt8(gray.width,gray.height);
// Create a canny edge detector which will dynamically compute the threshold based on maximum edge intensity
// It has also been configured to save the trace as a graph. This is the graph created while performing
// hysteresis thresholding.
CannyEdge<ImageUInt8,ImageSInt16> canny = FactoryEdgeDetectors.canny(2,true, true, ImageUInt8.class, ImageSInt16.class);
// The edge image is actually an optional parameter. If you don't need it just pass in null
canny.process(gray,0.1f,0.3f,edgeImage);
// First get the contour created by canny
List<EdgeContour> edgeContours = canny.getContours();
// The 'edgeContours' is a tree graph that can be difficult to process. An alternative is to extract
// the contours from the binary image, which will produce a single loop for each connected cluster of pixels.
// Note that you are only interested in external contours.
List<Contour> contours = BinaryImageOps.contour(edgeImage, 8, null);
// display the results
BufferedImage visualBinary = VisualizeBinaryData.renderBinary(edgeImage, null);
BufferedImage visualCannyContour = VisualizeBinaryData.renderContours(edgeContours,null,
gray.width,gray.height,null);
BufferedImage visualEdgeContour = VisualizeBinaryData.renderExternal(contours, null,
gray.width, gray.height, null);
ShowImages.showWindow(visualBinary,"Binary Edges from Canny");
ShowImages.showWindow(visualCannyContour,"Canny Trace Graph");
ShowImages.showWindow(visualEdgeContour,"Contour from Canny Binary");
}
示例11: fitCannyBinary
import boofcv.alg.filter.binary.BinaryImageOps; //导入依赖的package包/类
/**
* Detects contours inside the binary image generated by canny. Only the external contour is relevant. Often
* easier to deal with than working with Canny edges directly.
*/
public static void fitCannyBinary( ImageFloat32 input ) {
BufferedImage displayImage = new BufferedImage(input.width,input.height,BufferedImage.TYPE_INT_RGB);
ImageUInt8 binary = new ImageUInt8(input.width,input.height);
// Finds edges inside the image
CannyEdge<ImageFloat32,ImageFloat32> canny =
FactoryEdgeDetectors.canny(2, false, true, ImageFloat32.class, ImageFloat32.class);
canny.process(input,0.1f,0.3f,binary);
List<Contour> contours = BinaryImageOps.contour(binary, 8, null);
Graphics2D g2 = displayImage.createGraphics();
g2.setStroke(new BasicStroke(2));
// used to select colors for each line
Random rand = new Random(234);
for( Contour c : contours ) {
// Only the external contours are relevant.
List<PointIndex_I32> vertexes = ShapeFittingOps.fitPolygon(c.external,true,
toleranceDist,toleranceAngle,100);
g2.setColor(new Color(rand.nextInt()));
VisualizeShapes.drawPolygon(vertexes,true,g2);
}
ShowImages.showWindow(displayImage,"Canny Contour");
}
示例12: 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");
}
示例13: 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");
}
示例14: 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);
}
示例15: 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;
}