本文整理汇总了Java中boofcv.alg.filter.binary.GThresholdImageOps类的典型用法代码示例。如果您正苦于以下问题:Java GThresholdImageOps类的具体用法?Java GThresholdImageOps怎么用?Java GThresholdImageOps使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GThresholdImageOps类属于boofcv.alg.filter.binary包,在下文中一共展示了GThresholdImageOps类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getContours
import boofcv.alg.filter.binary.GThresholdImageOps; //导入依赖的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: process
import boofcv.alg.filter.binary.GThresholdImageOps; //导入依赖的package包/类
/**
* Processes the image and automatically detects calibration grid. If successful then
* true is returned and the found target is contained in the target detector.
*
* @param detector Target detection algorithm.
* @param gray Gray scale image which is being thresholded
* @return true if a threshold was successfully found and target detected.
*/
public boolean process( DetectSquareCalibrationPoints detector , ImageFloat32 gray ) {
binary.reshape(gray.width,gray.height);
double threshold = initialThreshold;
if( threshold < 0 )
threshold = UtilCalibrationGrid.selectThreshold(gray,histogram);
GThresholdImageOps.threshold(gray,binary,threshold,true);
// see if the target was detected
if( detector.process(binary) ) {
refinedThreshold = refineThreshold(detector.getInterestSquares(),gray);
GThresholdImageOps.threshold(gray,binary,threshold,true);
if( !detector.process(binary) ) {
throw new RuntimeException("Crap new threshold doesn't work!");
}
return true;
}
return false;
}
开发者ID:intrack,项目名称:BoofCV-master,代码行数:31,代码来源:AutoThresholdCalibrationGrid.java
示例3: detect
import boofcv.alg.filter.binary.GThresholdImageOps; //导入依赖的package包/类
@Override
public List<LineSegment2D_F32> detect(T input) {
derivX.reshape(input.width,input.height);
derivY.reshape(input.width,input.height);
edgeIntensity.reshape(input.width,input.height);
detected.reshape(input.width,input.height);
gradient.process(input,derivX,derivY);
GGradientToEdgeFeatures.intensityAbs(derivX, derivY, edgeIntensity);
GThresholdImageOps.threshold(edgeIntensity, detected, edgeThreshold, false);
detectorGrid.process(derivX,derivY,detected);
MatrixOfList<LineSegment2D_F32> grid = detectorGrid.getFoundLines();
if( connect != null ) {
connect.process(grid);
}
List<LineSegment2D_F32> found = grid.createSingleList();
LineImageOps.mergeSimilar(found, (float) (Math.PI * 0.03), 5f);
return found;
}
开发者ID:intrack,项目名称:BoofCV-master,代码行数:25,代码来源:DetectLineSegmentsGridRansac.java
示例4: performWork
import boofcv.alg.filter.binary.GThresholdImageOps; //导入依赖的package包/类
private synchronized void performWork() {
if( filter == null )
return;
GThresholdImageOps.threshold(imageInput, imageBinary, selectThresh.getThreshold(), selectThresh.isDown());
filter.process(imageBinary,imageOutput);
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);
}
VisualizeBinaryData.renderBinary(selectedVisualize, work);
gui.setBufferedImage(work);
gui.setPreferredSize(new Dimension(imageInput.width, imageInput.height));
processedImage = true;
gui.repaint();
}
});
}
开发者ID:intrack,项目名称:BoofCV-master,代码行数:20,代码来源:DemoBinaryImageOpsApp.java
示例5: performWork
import boofcv.alg.filter.binary.GThresholdImageOps; //导入依赖的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();
}
});
}
开发者ID:intrack,项目名称:BoofCV-master,代码行数:24,代码来源:DemoBinaryImageLabelOpsApp.java
示例6: binarize
import boofcv.alg.filter.binary.GThresholdImageOps; //导入依赖的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
示例7: generateBlackWhiteImage
import boofcv.alg.filter.binary.GThresholdImageOps; //导入依赖的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
示例8: iteration
import boofcv.alg.filter.binary.GThresholdImageOps; //导入依赖的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: detectChessBoard
import boofcv.alg.filter.binary.GThresholdImageOps; //导入依赖的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;
}
开发者ID:intrack,项目名称:BoofCV-master,代码行数:32,代码来源:DetectChessCalibrationPoints.java
示例10: detectChessBoardSubImage
import boofcv.alg.filter.binary.GThresholdImageOps; //导入依赖的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;
}
开发者ID:intrack,项目名称:BoofCV-master,代码行数:42,代码来源:DetectChessCalibrationPoints.java
示例11: detectTarget
import boofcv.alg.filter.binary.GThresholdImageOps; //导入依赖的package包/类
/**
* Process the gray scale image. Use a manually selected threshold or
*/
private void detectTarget() {
if( calibGUI.isManual() ) {
GThresholdImageOps.threshold(gray,binary,calibGUI.getThresholdLevel(),true);
foundTarget = alg.process(binary);
} else {
foundTarget = auto.process(alg,gray);
calibGUI.setThreshold((int)auto.getThreshold());
binary.setTo(auto.getBinary());
}
}
开发者ID:intrack,项目名称:BoofCV-master,代码行数:17,代码来源:DetectCalibrationSquaresApp.java
示例12: doProcess
import boofcv.alg.filter.binary.GThresholdImageOps; //导入依赖的package包/类
private void doProcess() {
if( input == null )
return;
final BufferedImage temp;
if( activeAlg == 0 ) {
if( previousBlur != barCanny.getBlurRadius() ) {
previousBlur = barCanny.getBlurRadius();
canny = FactoryEdgeDetectors.canny(previousBlur,true, true, imageType, derivType);
}
double thresh = barCanny.getThreshold()/100.0;
canny.process(workImage,(float)thresh*0.1f,(float)thresh,null);
List<EdgeContour> contours = canny.getContours();
temp = VisualizeBinaryData.renderContours(contours,null,workImage.width,workImage.height,null);
} else {
// create a binary image by thresholding
GThresholdImageOps.threshold(workImage, binary, barBinary.getThreshold(), barBinary.isDown());
contour.process(binary,labeled);
temp = VisualizeBinaryData.renderContours(contour.getContours().toList(),null,0xFF1010,
workImage.width,workImage.height,null);
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
panel.setBufferedImage(temp);
panel.repaint();
}});
}
开发者ID:intrack,项目名称:BoofCV-master,代码行数:33,代码来源:ShowEdgeContourApp.java
示例13: process
import boofcv.alg.filter.binary.GThresholdImageOps; //导入依赖的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();
}
开发者ID:intrack,项目名称:BoofCV-master,代码行数:29,代码来源:ShapeFitContourApp.java
示例14: doInBackground
import boofcv.alg.filter.binary.GThresholdImageOps; //导入依赖的package包/类
@Override
protected Bitmap doInBackground(String... params) {
Bitmap image = BitmapFactory.decodeFile(params[0]);
Bitmap image2 = Bitmap.createScaledBitmap(image, 500, 500, false);
// convert into a usable format
ImageFloat32 input = ConvertBitmap.bitmapToGray(image2,(ImageFloat32)null,null); //(image, null, ImageFloat32.class);
ImageUInt8 binary = new ImageUInt8(input.width,input.height);
GThresholdImageOps.localSauvola(input, binary, progress, 0.3f, false);
VisualizeImageData.binaryToBitmap(binary, false, image2, null);
image = image2;
return image;
}
开发者ID:acien101,项目名称:DiedricoApp,代码行数:19,代码来源:Thresholding.java
示例15: main
import boofcv.alg.filter.binary.GThresholdImageOps; //导入依赖的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
示例16: thresholdOtsu
import boofcv.alg.filter.binary.GThresholdImageOps; //导入依赖的package包/类
/**
* @see GThresholdImageOps#computeOtsu
*/
public SimpleBinary thresholdOtsu(boolean down ) {
double threshold = GThresholdImageOps.computeOtsu(image,0,255);
return new SimpleBinary(GThresholdImageOps.threshold(image, null, threshold, down));
}
开发者ID:lessthanoptimal,项目名称:BoofProcessing,代码行数:8,代码来源:SimpleGray.java
示例17: thresholdEntropy
import boofcv.alg.filter.binary.GThresholdImageOps; //导入依赖的package包/类
/**
* @see GThresholdImageOps#computeEntropy
*/
public SimpleBinary thresholdEntropy(boolean down ) {
double threshold = GThresholdImageOps.computeEntropy(image,0,255);
return new SimpleBinary(GThresholdImageOps.threshold(image, null, threshold, down));
}
开发者ID:lessthanoptimal,项目名称:BoofProcessing,代码行数:8,代码来源:SimpleGray.java
示例18: thresholdSquare
import boofcv.alg.filter.binary.GThresholdImageOps; //导入依赖的package包/类
/**
* @see GThresholdImageOps#localSquare
*/
public SimpleBinary thresholdSquare( int radius, double bias, boolean down ) {
return new SimpleBinary(GThresholdImageOps.localSquare(image, null, radius, bias, down, null, null));
}
开发者ID:lessthanoptimal,项目名称:BoofProcessing,代码行数:7,代码来源:SimpleGray.java
示例19: thresholdGaussian
import boofcv.alg.filter.binary.GThresholdImageOps; //导入依赖的package包/类
/**
* @see GThresholdImageOps#localGaussian
*/
public SimpleBinary thresholdGaussian( int radius, double bias, boolean down ) {
return new SimpleBinary(GThresholdImageOps.localGaussian(image, null, radius, bias, down, null, null));
}
开发者ID:lessthanoptimal,项目名称:BoofProcessing,代码行数:7,代码来源:SimpleGray.java
示例20: detectEdgePoints
import boofcv.alg.filter.binary.GThresholdImageOps; //导入依赖的package包/类
/**
* Detects edges along the black square. If the square is partially inside a pixel the
* pixel's value will be between the dark and light value. In a perfect sensor the border
* region would be at most two pixels thick, both values lighter than the pure black square.
* This border is captured using two threshold, one 1/2 between light and dark, and one much
* close to light.
*
* One case is not handled correctly given perfect observations. If the line splits 1/2 way down
* two pixels then the edge will only be one pixel thick and not two.
*/
private void detectEdgePoints( ImageFloat32 image ) {
// Added or subtracted one to handle pathological case where sigma is zero
double lowThresh = low.getMean()+low.getSigma()*3+1;
double highThresh = high.getMean()-high.getSigma()*3-1;
// sanity check
if( highThresh <= lowThresh ) {
// BoofMiscOps.print(image);
// for( int i = 0; i < histHighRes.histogram.length; i++ ) {
// int c = histHighRes.histogram[i];
// if( c != 0 ) {
// System.out.println("["+i+"] = "+c);
// }
// }
// return;
throw new InvalidCalibrationTarget("Bad statistics");
}
// do a threshold in the middle first
double middleThresh = (lowThresh*0.5+highThresh*0.5);
// extract two regions at different threshold levels
GThresholdImageOps.threshold(image, binaryMiddle,middleThresh,true);
removeBinaryNoise(binaryMiddle);
// binaryMiddle will be a subset of binaryHigh
GThresholdImageOps.threshold(image, binaryHigh,highThresh,true);
removeBinaryNoise(binaryHigh);
// UtilImageIO.print(image);
// UtilImageIO.print(binaryHigh);
// find the region outside of 'binaryMiddle' in 'binaryHigh' and include
// the edges in 'binaryMiddle'
BinaryImageOps.logicXor(binaryMiddle, binaryHigh, binaryHigh);
BinaryImageOps.edge4(binaryMiddle, binary);
BinaryImageOps.logicOr(binaryHigh,binary,binary);
// binary.print();
// System.out.println("--------------------");
// extract the points from the binary image and compute weights
// weight is a linear function of distance from black square value
points.reset();
double middle = (high.getMean()+low.getMean())/2;
for( int y = 0; y < height; y++ ) {
for( int x = 0; x < width; x++ ) {
if( binary.get(x,y) == 1 ) {
PointInfo p = points.grow();
p.set(x,y);
double v = image.get(x,y);
// weight pixels more that are close to the middle value since only an
// edge point can have that value
p.weight = 1.0-Math.abs(middle-v)/middle;
p.weight = p.weight*p.weight;
}
}
}
}
开发者ID:intrack,项目名称:BoofCV-master,代码行数:70,代码来源:RefineCornerSegmentFit.java
注:本文中的boofcv.alg.filter.binary.GThresholdImageOps类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论