Tutorial Quick Start

From BoofCV
Revision as of 06:57, 1 November 2011 by Peter (talk | contribs) (Created page with "= Quick Start Tutorial = The following is a quick tutorial on how to use BoofCV. A series of code sniplets is provided with a short description of what it does. = The Basics...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Quick Start Tutorial

The following is a quick tutorial on how to use BoofCV. A series of code sniplets is provided with a short description of what it does.

The Basics

ImageUInt8 image = new ImageUInt8 (100,150);

Creating an unsigned 8-bit integer single band image with width=100 and height=150.

ImageFloat32 image = new ImageFloat32(100,150);

Creating a floating point single band image with width=100 and height=150.

ImageFloat32 image = UtilImageIO.loadImage("test.png",ImageFloat32.class);

Loads an image of type ImageFloat32 from a file.

public static <T extends ImageBase> T generic( Class<T> imageType ) {
	T image = UtilImageIO.loadImage("test.png",imageType);

Loads an image with the specified type using Java generics.

BufferedImage out = ConvertBufferedImage.convertTo(image,null);

Converts an image into a BufferedImage to provide better integration with Java2D (display/saving). Pixel values must be in the range of 0 to 255.

BufferedImage out = VisualizeImageData.grayMagnitude(derivX,null,-1);

Renders a signed single band image into a gray intensity image.

BufferedImage out = VisualizeImageData.colorizeSign(derivX,null,-1);

Renders a signed single band image into a color intensity image.

BufferedImage out = ConvertBufferedImage.convertTo(image,null);
ShowImages.showWindow(out,"Output");

Displays an image in a window using Java swing.

Filters

public static void procedural( ImageUInt8 input )
{
	ImageUInt8 blurred = new ImageUInt8(input.width,input.height);
	BlurImageOps.gaussian(input,blurred,-1,blurRadius,null);

Applies Gaussian blur to an image using a type specific procedural interface.

public static <T extends ImageBase, D extends ImageBase>
void generalized( T input )
{
	Class<T> inputType = (Class<T>)input.getClass();

	T blurred = GeneralizedImageOps.createImage(inputType,input.width, input.height);
	GBlurImageOps.gaussian(input, blurred, -1, blurRadius, null);

Applies Gaussian blur to an image using an abstracted procedural interface. Note the G in front of BlurImageOps that indicates it contains generic functions.

public static <T extends ImageBase, D extends ImageBase>
void filter( T input )
{
	Class<T> inputType = (Class<T>)input.getClass();
	T blurred = GeneralizedImageOps.createImage(inputType, input.width, input.height);
	BlurFilter<T> filterBlur = FactoryBlurFilter.gaussian(inputType, -1, blurRadius);
	filterBlur.process(input,blurred);

Creates an image filter class for computing the Gaussian blur. Provides greater abstraction.

// type specific sobel
GradientSobel.process(blurred, derivX, derivY, FactoryImageBorder.extend(input));
// generic
GImageDerivativeOps.sobel(blurred, derivX, derivY, BorderType.EXTENDED);
// filter
ImageGradient<T,D> gradient = FactoryDerivative.sobel(inputType, derivType);
gradient.process(blurred,derivX,derivY);

Three ways to compute the image gradient using a Sobel kernel.

public static <T extends ImageBase, D extends ImageBase>
void example( T input , Class<D> derivType ) {
	AnyImageDerivative<T,D> deriv = GImageDerivativeOps.createDerivatives((Class<T>)input.getClass(),derivType);

	deriv.setInput(input);
	D derivX = deriv.getDerivative(true);
	D derivXXY = deriv.getDerivative(true,true,false);

Useful class for computing arbitrary image derivatives. Computes 1st order x-derive and then 3rd order xxy derivative.

Binary Images

ThresholdImageOps.threshold(image, binary, 23, true);

Creates a binary image by thresholding the input image. Binary must be of type ImageUInt8.

binary = BinaryImageOps.erode8(binary,null);

Apply an erode operation on the binary image, writing over the original image reference.

BinaryImageOps.erode8(binary,output);

Apply an erode operation on the binary image, saving results to the output binary image.

BinaryImageOps.erode4(binary,output);

Apply an erode operation with a 4-connect rule.

int numBlobs = BinaryImageOps.labelBlobs4(binary,blobs);

Detect and label blobs in the binary image using a 4-connect rule. blobs is an image of type ImageSInt32.

BufferedImage visualized = VisualizeBinaryData.renderLabeled(blobs, numBlobs, null);

Renders the detected blobs in a colored image.

BufferedImage visualized = VisualizeBinaryData.renderBinary(binary,null);

Renders the binary image as a black white image.