Difference between revisions of "Example Binary Image"
From BoofCV
Jump to navigationJump to searchm  | 
				m  | 
				||
| Line 1: | Line 1: | ||
= Binary Image Processing =  | = Binary Image Processing =  | ||
<center>  | |||
<gallery caption="Example input and output Images" heights=200 widths=200 >  | |||
Image:particles01.jpg|Input TEM particle image.  | |||
Image:example_binary.png|Thresholded Binary Image.  | |||
Image:example_binary_labeled.png|Labeled Binary Image  | |||
</gallery>  | |||
</center>  | |||
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.  | 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.  | ||
| Line 41: | Line 49: | ||
= Labeled Example =  | = Labeled Example =  | ||
Here clustered of blobs are detected and arbitrarily assigned labels.  | Here clustered of blobs are detected and arbitrarily assigned labels.  Noise is reduced through morphological image operations.  | ||
[[image:example_binary_labeled.png|thumb|Output of binary label example.]]  | [[image:example_binary_labeled.png|thumb|Output of binary label example.]]  | ||
Revision as of 12:37, 18 October 2011
Binary Image Processing
- Example input and output Images
 
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");
	}