本文整理汇总了Java中boofcv.struct.image.GrayU8.set方法的典型用法代码示例。如果您正苦于以下问题:Java GrayU8.set方法的具体用法?Java GrayU8.set怎么用?Java GrayU8.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boofcv.struct.image.GrayU8
的用法示例。
在下文中一共展示了GrayU8.set方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: countPills
import boofcv.struct.image.GrayU8; //导入方法依赖的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;
}
示例2: binaryToDrawable
import boofcv.struct.image.GrayU8; //导入方法依赖的package包/类
public static GrayU8 binaryToDrawable(GrayU8 image) {
GrayU8 drawable = new GrayU8(image.width,image.height);
for (int y=0;y<image.getHeight();y++) {
for (int x = 0; x < image.getWidth(); x++) {
if (image.get(x, y) > 0) {
drawable.set(x, y, BLACK);
} else {
drawable.set(x, y, WHITE);
}
}
}
return drawable;
}
示例3: removeIsolatedPoints
import boofcv.struct.image.GrayU8; //导入方法依赖的package包/类
private GrayU8 removeIsolatedPoints(Map<Point, Boolean> pointsWithStrongDerivates, int width, int height) {
GrayU8 pointsToKeep = new GrayU8(width, height);
int exploreRadius = 5;
int exploreTh = 20;
for (int y=0; y<height; y++) {
int minY = Math.max(0, y - exploreRadius);
int maxY = Math.min(height, y + exploreRadius + 1);
int minX = 0;
int maxX = Math.min(width, exploreRadius + 1);
int total = countAllIn(pointsWithStrongDerivates, minY, maxY, minX, maxX);
if (total < exploreTh) {
pointsToKeep.set(0, y, WHITE);
} else {
pointsToKeep.set(0, y, BLACK);
}
for (int x = 1; x < width; x++) {
// As we move on the right we should consider one more column on the right and one less on the left
int newMinX = Math.max(0, x - exploreRadius);
int newMaxX = Math.min(width, x + exploreRadius + 1);
if (newMinX != minX) {
total -= countAllIn(pointsWithStrongDerivates, minY, maxY, minX, newMinX);
minX = newMinX;
}
if (newMaxX != maxX) {
total += countAllIn(pointsWithStrongDerivates, minY, maxY, maxX, newMaxX);
maxX = newMaxX;
}
if (total < exploreTh) {
pointsToKeep.set(x, y, WHITE);
} else {
pointsToKeep.set(x, y, BLACK);
}
}
}
return pointsToKeep;
}
示例4: generateScaledMasksFromPath
import boofcv.struct.image.GrayU8; //导入方法依赖的package包/类
public static ArrayList<GrayU8> generateScaledMasksFromPath(List<VideoFrame> videoFrames,
List<Pair<Integer, LinkedList<Point2D_F32>>> foregroundPaths) {
if (videoFrames == null || videoFrames.isEmpty() || foregroundPaths == null) {
return null;
}
ArrayList<GrayU8> masks = new ArrayList<GrayU8>();
int width = videoFrames.get(0).getImage().getBufferedImage().getWidth();
int height = videoFrames.get(0).getImage().getBufferedImage().getHeight();
ListIterator<Pair<Integer, LinkedList<Point2D_F32>>> fgPathItor = foregroundPaths.listIterator();
int cnt = 0;
for (int frameIdx = 0; frameIdx < videoFrames.size(); ++frameIdx) {
if (cnt >= PathList.frameInterval) {
cnt = 0;
continue;
}
cnt += 1;
GrayU8 mask = new GrayU8(width / PathList.samplingInterval, height / PathList.samplingInterval);
while (fgPathItor.hasNext()) {
Pair<Integer, LinkedList<Point2D_F32>> pair = fgPathItor.next();
if (pair.first > frameIdx) {
break;
}
Point2D_F32 p1 = pair.second.getFirst();
int x = (int) (p1.x * width / PathList.samplingInterval);
int y = (int) (p1.y * height / PathList.samplingInterval);
if (mask.isInBounds(x, y)) {
mask.set(x, y, 1);
}
}
//showBineryImage(mask);
masks.add(mask);
}
return masks;
}
示例5: main
import boofcv.struct.image.GrayU8; //导入方法依赖的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);
}