本文整理汇总了Java中boofcv.io.image.ConvertBufferedImage.convertFromSingle方法的典型用法代码示例。如果您正苦于以下问题:Java ConvertBufferedImage.convertFromSingle方法的具体用法?Java ConvertBufferedImage.convertFromSingle怎么用?Java ConvertBufferedImage.convertFromSingle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boofcv.io.image.ConvertBufferedImage
的用法示例。
在下文中一共展示了ConvertBufferedImage.convertFromSingle方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getContours
import boofcv.io.image.ConvertBufferedImage; //导入方法依赖的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: countPills
import boofcv.io.image.ConvertBufferedImage; //导入方法依赖的package包/类
/**
* Count pills.
*
* @param image the image
* @return the int
* @throws Exception the exception
*/
public static int countPills( BufferedImage image ) throws Exception {
GrayF32 input = ConvertBufferedImage.convertFromSingle(image, null, GrayF32.class);
GrayU8 binary = new GrayU8(input.width,input.height);
int totPixels = 0;
for( int x = 0 ; x<input.width ; x++ ) {
for( int y=0 ; y<input.height ; y++ ) {
int binout = input.get(x, y) < PIXEL_THRESHOLD ? 0 : 1;
binary.set(x, y, binout );
totPixels += binout;
}
}
dumpImage(binary, input.width, input.height );
int numPills = -1;
for( int checkNumPills=1 ; checkNumPills<CHECK_MAX_NUM_PILLS ; checkNumPills++ ) {
int checkMaxPixels = (int)(checkNumPills * PIXELS_PER_PILL * PIXELS_PER_PILL_FUDGE_FACTOR);
if( totPixels <= checkMaxPixels ) {
numPills = checkNumPills;
break;
}
}
logger.info("NumPills found in image: {}", numPills);
return numPills;
}
示例3: ImageDesc
import boofcv.io.image.ConvertBufferedImage; //导入方法依赖的package包/类
public ImageDesc(BufferedImage in)
{
if(!AverageHash.isInitiated())
{
AverageHash.init(2, 2);
}
hash = AverageHash.avgHash(in,2,2);
GrayF32 img = ConvertBufferedImage.convertFromSingle(in, null, GrayF32.class);
desc.reset();
describeImage(img,desc);
}
示例4: maskBackground
import boofcv.io.image.ConvertBufferedImage; //导入方法依赖的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);
}
示例5: generateBlackWhiteImage
import boofcv.io.image.ConvertBufferedImage; //导入方法依赖的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;
}
示例6: getStableSurf
import boofcv.io.image.ConvertBufferedImage; //导入方法依赖的package包/类
/**
* Returns SURF descriptors for an image using the settings above. Uses the BoofCV stable SURF algorithm.
*
* @param image Image for which to obtain the SURF descriptors.
* @return
*/
public static DetectDescribePoint<GrayF32, BrightFeature> getStableSurf(BufferedImage image) {
/* Obtain raw SURF descriptors using the configuration above (FH-9 according to [1]). */
GrayF32 gray = ConvertBufferedImage.convertFromSingle(image, null, GrayF32.class);
ConfigFastHessian config = new ConfigFastHessian(0, 2, FH_MAX_FEATURES_PER_SCALE, FH_INITIAL_SAMPLE_SIZE, FH_INITIAL_SIZE, FH_NUMBER_SCALES_PER_OCTAVE, FH_NUMBER_OF_OCTAVES);
DetectDescribePoint<GrayF32, BrightFeature> surf = FactoryDetectDescribe.surfStable(config, null, null, GrayF32.class);
surf.detect(gray);
return surf;
}
示例7: getFastSurf
import boofcv.io.image.ConvertBufferedImage; //导入方法依赖的package包/类
/**
* Returns SURF descriptors for an image using the settings above. Uses the BoofCV fast SURF algorithm,
* which yields less images but operates a bit faster.
*
* @param image Image for which to obtain the SURF descriptors.
* @return
*/
public static DetectDescribePoint<GrayF32, BrightFeature> getFastSurf(BufferedImage image) {
/* Obtain raw SURF descriptors using the configuration above (FH-9 according to [1]). */
GrayF32 gray = ConvertBufferedImage.convertFromSingle(image, null, GrayF32.class);
ConfigFastHessian config = new ConfigFastHessian(0, 2, FH_MAX_FEATURES_PER_SCALE, FH_INITIAL_SAMPLE_SIZE, FH_INITIAL_SIZE, FH_NUMBER_SCALES_PER_OCTAVE, FH_NUMBER_OF_OCTAVES);
DetectDescribePoint<GrayF32, BrightFeature> surf = FactoryDetectDescribe.surfFast(config, null, null, GrayF32.class);
surf.detect(gray);
return surf;
}
示例8: gray
import boofcv.io.image.ConvertBufferedImage; //导入方法依赖的package包/类
public GrayImageProcessor gray() {
GrayU8 newImage = ConvertBufferedImage.convertFromSingle(image, null, GrayU8.class);
addImageToPanel(newImage, "Gray");
return new GrayImageProcessor(newImage);
}
示例9: runExtraction
import boofcv.io.image.ConvertBufferedImage; //导入方法依赖的package包/类
public static void runExtraction(BufferedImage bwImage, String path) throws IOException {
// load and convert the image into a usable format
// BufferedImage image = UtilImageIO.loadImage(UtilIO.pathExample("C:\\development\\readySET\\saved.png"));
GrayF32 input = ConvertBufferedImage.convertFromSingle(bwImage, null, GrayF32.class);
gui.addImage(bwImage, "Original");
// fitCannyEdges(input);
// fitCannyBinary(input);
List<Card> Cards = fitBinaryImage(input, path);
ShowImages.showWindow(gui, "Polygon from Contour", true);
// for (int a = 0; a < 3; a++) {
// for (int b = 0; b < 3; b++) {
// for (int c = 0; c < 3; c++) {
// for (int d = 0; d < 3; d++) {
//
// }
// }
// }
// }
for (int i = 0; i < Cards.size(); i++) {
File file = new File(i + ".png");
int[] colorinfo = new int[4];
colorinfo = colorFinder(file);
if ((colorinfo[0] > 140)) {
Cards.get(i).setColor(0);
} else if ((colorinfo[0] < 140) && (colorinfo[1] > 112)) {
Cards.get(i).setColor(1);
} else if ((colorinfo[0] < 140) && (colorinfo[1] <= 112)) {
Cards.get(i).setColor(2);
}
if (Cards.get(i).getFill() == 3)
if ((colorinfo[3] / (Cards.get(i).getNumber() + 1)) > 18000) {
Cards.get(i).setFill(2);
} else {
Cards.get(i).setFill(0);
}
}
List<int[]> sets = SetFinder(Cards);
System.out.println(sets.size() + " sets:");
System.out.println();
for(int i = 0; i < sets.size();i++){
System.out.println(i+1 +":");
System.out.println(sets.get(i)[0] +", " +sets.get(i)[1] +", " +sets.get(i)[2]);
System.out.println();
}
int[] mySet = sets.get(0);
try {
PrintWriter writer = new PrintWriter("index.html", "UTF-8");
writer.println("<!DOCTYPE html><html><head><meta http-equiv='refresh' content='10' /><title>another stupid</title></head>");
writer.print("<body onload='window.navigator.vibrate([");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < mySet[i]; j++) {
writer.print("200,75,");
}
writer.print("0, 325,");
}
writer.println("]);'>");
writer.println("</body></html>");
writer.close();
} catch (IOException e) {
System.out.print("oops");
}
}
示例10: main
import boofcv.io.image.ConvertBufferedImage; //导入方法依赖的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: main
import boofcv.io.image.ConvertBufferedImage; //导入方法依赖的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"));
GrayF32 input = ConvertBufferedImage.convertFromSingle(image, null, GrayF32.class);
GrayU8 binary = new GrayU8(input.width,input.height);
DecimalFormat fmt = new DecimalFormat("000");
for( int x = 0 ; x<100 ; x++ ) {
for( int y=0 ; y<100 ; y++ ) {
Float out = input.get(x, y) < 225 ? 0f : 1f;
System.out.print( out);
int binout = input.get(x, y) < 225 ? 0 : 1;
binary.set(x, y, binout );
//System.out.print( fmt.format(input.get(x, y)) + " " );
}
System.out.println("");
}
List<Contour> contours = BinaryImageOps.contour(binary, ConnectRule.EIGHT,null);
//
// // 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);
//
// for( int x = 0 ; x<100 ; x++ ) {
// for( int y=0 ; y<100 ; y++ ) {
// System.out.print(filtered.get(x, y) );
// }
// System.out.println("");
// }
//
//
// // Find the contour around the shapes
// List<Contour> contours2 = BinaryImageOps.contour(filtered, ConnectRule.EIGHT,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, false, null),"Binary",true);
ShowImages.showWindow(image,"Ellipses",true);
}
示例12: getHOGDescriptors
import boofcv.io.image.ConvertBufferedImage; //导入方法依赖的package包/类
/**
* Returns HOG descriptors for an image using the provided settings.
*
* @param image Image for which to obtain the HOG descriptors.
* @param config ConfigDenseHog object that specifies the parameters for the HOG algorithm.
* @return DescribeImageDense object containing the HOG descriptor.
*/
public static DescribeImageDense<GrayU8,TupleDesc_F64> getHOGDescriptors(BufferedImage image, ConfigDenseHoG config) {
GrayU8 gray = ConvertBufferedImage.convertFromSingle(image, null, GrayU8.class);
DescribeImageDense<GrayU8,TupleDesc_F64> desc = FactoryDescribeImageDense.hog(config, ImageType.single(GrayU8.class));
desc.process(gray);
return desc;
}