Difference between revisions of "Example Binary Image"
From BoofCV
Jump to navigationJump to searchm |
|||
Line 27: | Line 27: | ||
In this example a threshold is computed for the input image dynamically and the resulting binary image shown. | In this example a threshold is computed for the input image dynamically and the resulting binary image shown. | ||
< | <syntaxhighlight lang="java"> | ||
public static void binaryExample( BufferedImage image ) | public static void binaryExample( BufferedImage image ) | ||
{ | { | ||
Line 44: | Line 44: | ||
ShowImages.showWindow(visualBinary,"Binary Image"); | ShowImages.showWindow(visualBinary,"Binary Image"); | ||
} | } | ||
</ | </syntaxhighlight> | ||
= Labeled Example = | = Labeled Example = | ||
Here clustered of blobs are detected and arbitrarily assigned labels. Noise is reduced through morphological image operations. | Here clustered of blobs are detected and arbitrarily assigned labels. Noise is reduced through morphological image operations. | ||
< | <syntaxhighlight lang="java"> | ||
public static void labeledExample( BufferedImage image ) | public static void labeledExample( BufferedImage image ) | ||
{ | { | ||
Line 76: | Line 76: | ||
ShowImages.showWindow(visualized,"Labeled Image"); | ShowImages.showWindow(visualized,"Labeled Image"); | ||
} | } | ||
</ | </syntaxhighlight> |
Revision as of 12:20, 27 October 2011
Binary Image Processing
Binary images are images where each pixel can take on two values, typically represented by 0 or 1. Binary images are easy to compute and fast to process, which makes them popular in many applications.
Example File: BinaryImageExample.java
Concepts:
- Image Thresholding
- Morphological Operations
- Binary Labeling
- Pixel Math
- Image Rendering
Relevant Applets:
Basic Example
In this example a threshold is computed for the input image dynamically and the resulting binary image shown.
public static void binaryExample( BufferedImage image )
{
// convert into a usable format
ImageFloat32 input = ConvertBufferedImage.convertFrom(image,null,ImageFloat32.class);
ImageUInt8 binary = new ImageUInt8(input.width,input.height);
// the mean pixel value is often a reasonable threshold when creating a binary image
float mean = PixelMath.sum(input)/(input.width*input.height);
// create a binary image
ThresholdImageOps.threshold(input,binary,mean,true);
// Render the binary image for output and display it in a window
BufferedImage visualBinary = VisualizeBinaryData.renderBinary(binary,null);
ShowImages.showWindow(visualBinary,"Binary Image");
}
Labeled Example
Here clustered of blobs are detected and arbitrarily assigned labels. Noise is reduced through morphological image operations.
public static void labeledExample( BufferedImage image )
{
// convert into a usable format
ImageFloat32 input = ConvertBufferedImage.convertFrom(image,null,ImageFloat32.class);
ImageUInt8 binary = new ImageUInt8(input.width,input.height);
ImageSInt32 blobs = new ImageSInt32(input.width,input.height);
// the mean pixel value is often a reasonable threshold when creating a binary image
float mean = PixelMath.sum(input)/(input.width*input.height);
// create a binary image
ThresholdImageOps.threshold(input,binary,mean,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.
binary = BinaryImageOps.erode8(binary,null);
binary = BinaryImageOps.dilate8(binary, null);
// Detect blobs inside the binary image and assign labels to them
int numBlobs = BinaryImageOps.labelBlobs4(binary,blobs);
// Render the binary image for output and display it in a window
BufferedImage visualized = VisualizeBinaryData.renderLabeled(blobs, numBlobs, null);
ShowImages.showWindow(visualized,"Labeled Image");
}