use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.
the class ExampleWebcamGradient method main.
public static void main(String[] args) {
// Open a webcam at a resolution close to 640x480
Webcam webcam = UtilWebcamCapture.openDefault(640, 480);
// Create the panel used to display the image and
ImagePanel gui = new ImagePanel();
Dimension viewSize = webcam.getViewSize();
gui.setPreferredSize(viewSize);
// Predeclare storage for the gradient
GrayF32 derivX = new GrayF32((int) viewSize.getWidth(), (int) viewSize.getHeight());
GrayF32 derivY = new GrayF32((int) viewSize.getWidth(), (int) viewSize.getHeight());
ShowImages.showWindow(gui, "Gradient", true);
for (; ; ) {
BufferedImage image = webcam.getImage();
GrayF32 gray = ConvertBufferedImage.convertFrom(image, (GrayF32) null);
// compute the gradient
GImageDerivativeOps.gradient(DerivativeType.SOBEL, gray, derivX, derivY, BorderType.EXTENDED);
// visualize and display
BufferedImage visualized = VisualizeImageData.colorizeGradient(derivX, derivY, -1);
gui.setImageUI(visualized);
}
}
use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.
the class ExampleInterpolation method main.
public static void main(String[] args) {
String imagePath;
imagePath = "eye01.jpg";
// imagePath = "small_sunflower.jpg";
BufferedImage buffered = UtilImageIO.loadImage(UtilIO.pathExample(imagePath));
ListDisplayPanel gui = new ListDisplayPanel();
gui.addImage(buffered, "Original");
// For sake of simplicity assume it's a gray scale image. Interpolation functions exist for planar and
// interleaved color images too
GrayF32 input = ConvertBufferedImage.convertFrom(buffered, (GrayF32) null);
GrayF32 scaled = input.createNew(500, 500 * input.height / input.width);
for (InterpolationType type : InterpolationType.values()) {
// Create the single band (gray scale) interpolation function for the input image
InterpolatePixelS<GrayF32> interp = FactoryInterpolation.createPixelS(0, 255, type, BorderType.EXTENDED, input.getDataType());
// Tell it which image is being interpolated
interp.setImage(input);
// the same thing and is slightly more efficient
for (int y = 0; y < scaled.height; y++) {
// iterate using the 1D index for added performance. Altertively there is the set(x,y) operator
int indexScaled = scaled.startIndex + y * scaled.stride;
float origY = y * input.height / (float) scaled.height;
for (int x = 0; x < scaled.width; x++) {
float origX = x * input.width / (float) scaled.width;
scaled.data[indexScaled++] = interp.get(origX, origY);
}
}
// Add the results to the output
BufferedImage out = ConvertBufferedImage.convertTo(scaled, null, true);
gui.addImage(out, type.toString());
}
ShowImages.showWindow(gui, "Example Interpolation", true);
}
use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.
the class ExampleMorphologicalThinning method main.
public static void main(String[] args) {
String[] images = new String[] { "drawings/drawing_text.png", "standard/fingerprint.jpg", "drawings/drawing_face.png" };
ListDisplayPanel uberPanel = new ListDisplayPanel();
for (String path : images) {
// load and convert the image into a usable format
BufferedImage image = UtilImageIO.loadImage(UtilIO.pathExample(path));
// convert into a usable format
GrayF32 input = ConvertBufferedImage.convertFromSingle(image, null, GrayF32.class);
GrayU8 binary = new GrayU8(input.width, input.height);
// Fixed threshold is best for B&W images, but the adaptive would improve results for the finger print
GThresholdImageOps.threshold(input, binary, 120, true);
// GThresholdImageOps.adaptiveSquare(input, binary, 20,0,true,null,null);
// Tell it to thin the image until there are no more changes
GrayU8 thinned = BinaryImageOps.thin(binary, -1, null);
// display the results
BufferedImage visualBinary = VisualizeBinaryData.renderBinary(binary, false, null);
BufferedImage visualThinned = VisualizeBinaryData.renderBinary(thinned, false, null);
ListDisplayPanel panel = new ListDisplayPanel();
panel.addImage(visualThinned, "Thinned");
panel.addImage(visualBinary, "Binary");
panel.addImage(image, "Original");
uberPanel.addItem(panel, new File(path).getName());
}
ShowImages.showWindow(uberPanel, "Thinned/Skeletonalized Images", true);
}
use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.
the class ExamplePointDeformKeyPoints method main.
public static void main(String[] args) {
BufferedImage orig = UtilImageIO.loadImage(UtilIO.pathExample("standard/man_mls.jpg"));
BufferedImage bufferedOut = new BufferedImage(orig.getWidth(), orig.getHeight(), BufferedImage.TYPE_INT_RGB);
Planar<GrayF32> input = ConvertBufferedImage.convertFrom(orig, true, ImageType.pl(3, GrayF32.class));
Planar<GrayF32> output = input.createSameShape();
List<Point2D_F32> src = new ArrayList<>();
List<Point2D_F32> dst = new ArrayList<>();
src.add(new Point2D_F32(64, 241));
src.add(new Point2D_F32(266, 119));
src.add(new Point2D_F32(265, 240));
src.add(new Point2D_F32(208, 410));
src.add(new Point2D_F32(181, 536));
src.add(new Point2D_F32(335, 409));
src.add(new Point2D_F32(375, 531));
src.add(new Point2D_F32(473, 238));
for (Point2D_F32 p : src) {
dst.add(p.copy());
}
ConfigDeformPointMLS config = new ConfigDeformPointMLS();
PointDeformKeyPoints deform = FactoryDistort.deformMls(config);
deform.setImageShape(input.width, input.height);
ImageDistort<Planar<GrayF32>, Planar<GrayF32>> distorter = FactoryDistort.distort(true, InterpolationType.BILINEAR, BorderType.ZERO, input.getImageType(), input.getImageType());
deform.setImageShape(input.width, input.height);
deform.setSource(src);
deform.setDestination(dst);
ConvertBufferedImage.convertTo(output, bufferedOut, true);
ImagePanel panel = ShowImages.showWindow(bufferedOut, "Point Based Distortion Animation", true);
int count = 0;
while (true) {
// specify new locations of key points
double theta = count++ * Math.PI / 30;
// right arm
dst.get(7).y = (float) (238 + Math.sin(theta) * 30);
// left arm
dst.get(0).y = (float) (241 - Math.sin(theta * 2.0) * 20);
// head
dst.get(1).x = (float) (266 + Math.sin(theta * 0.25) * 10);
// tell the deformation algorithm that destination points have changed
deform.setDestination(dst);
// Tell the distorter that the model has changed. If cached is set to false you can ignore this step
distorter.setModel(new PointToPixelTransform_F32(deform));
// distort the image
distorter.apply(input, output);
// Show the results
ConvertBufferedImage.convertTo(output, bufferedOut, true);
panel.repaint();
BoofMiscOps.sleep(30);
}
}
use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.
the class ExamplePyramidFloat method main.
public static void main(String[] args) {
BufferedImage image = UtilImageIO.loadImage(UtilIO.pathExample("standard/barbara.jpg"));
ExamplePyramidFloat<GrayF32> app = new ExamplePyramidFloat<>(GrayF32.class);
// ExamplePyramidFloat<GrayU8> app = new ExamplePyramidFloat<>(GrayU8.class);
app.standard();
app.process(image);
}
Aggregations