20.8.3 Image Binary


A binary image is a digital image that has only two gray scale values, usually 0 and 255, responding to white and black color in the image. It is a common way to convert a color image into binary to simplify the processing, and binary may also be the result of some operations such as thresholding.

In a binary image, the pixel whose gray scale = 0 (white) is considered the foreground, and the pixel with gray scale = 1 (black) the background.

Origin provides multiple tools to convert an image to binary and deal with the binary image.

Convert to Mask

To convert an image to binary mask

With image window active, select Image: Binary: Convert to Mask to open the CvMask dialog.

You may notice there is one other tool that can also generate a black and white image: Conversion: Convert to Binary. The difference is the gray scale of the bi-level they generate. Binary contains gray scales 0 and 255, but mask 0 and 1.

Binary mask is more commonly used to prepare a mask for the follow-up processing, such as masking out non-interested objects.

Morphology

Morphology is widely used in edge detection.

To remove pixels from the edges of foreground
  1. With image window active, select Image: Binary: Morphology to open the cvMorph dialog.
  2. Select Erode for Type to perform a gray scale erosion operation.
To add pixels to the edges of foreground
  1. With image window active, select Image: Binary: Morphology to open the cvMorph dialog.
  2. Select Dilate for Type to perform a gray scale dilation operation.
To perform an erosion on the binary, followed by dilation
  1. With image window active, select Image: Binary: Morphology to open the cvMorph dialog.
  2. Select Open for Type.
To perform an dilation on the binary, followed by erosion
  1. With image window active, select Image: Binary: Morphology to open the cvMorph dialog.
  2. Select Close for Type.

What's the difference between Erode and Open/Dilate and Close?

Erosion and Dilation are two fundamental operations in morphology. Opening and closing are derived from them. The goal of an opening is similar to erosion in that it tends to remove isolated pixels from the edges of foreground and smooth the edges. However, it is less destructive than erosion in general. That is, erosion erodes all regions indiscriminately, so the foreground size shrinks and the holes inside foreground enlarges. Opening on the other hand, tries to preserve the boundaries by performing both an erosion and a dilation. So as closing and dilation. Below illustrates the effects of these operations. And you can see more examples here, even they are done by Maximum/Minimum filter[1].

Original Image Erosion Dilation Opening Closing
Morpholoy original.png Morphology erosion.png Morphology dilation.png Morphology open.png Morphology close.png
To find the difference between a binary and its opening
  1. With image window active, select Image: Binary: Morphology to open the cvMorph dialog.
  2. Select Top Hat for Type.
To find the difference between a binary and its closing
  1. With image window active, select Image: Binary: Morphology to open the cvMorph dialog.
  2. Select Black Hat for Type.
Original Image Top Hat Black Hat
Morpholoy original.png Morpholoy tophat.png Morpholoy blackhat.png
[1]

You may notice that Maximum/Minimum filter can also perform erosion, dilation, opening and closing. It does the similar things as Morphology and Morphology has the direct options.

To find the outline of the foreground
  1. With image window active, select Image: Binary: Morphology to open the cvMorph dialog.
  2. Select Gradient for Type.

Gradient finds the difference between the dilation and the erosion of a binary image and thus outlines the foreground.

Original Image Gradient
Morpholoy original.png Morpholoy gradient.png

Contour Fill

To Fill regions and holes inside a binary object

With image window active, select Image: Binary: Contour Fill to open the cvContourFill dialog.

Distance Map

To generate a Euclidian Distance Map

With image window active, select Image: Binary: Distance Map to open the cvDistMap dialog.

Distance Map generates a Euclidian Distance Map (EDM) from a binary. Each foreground pixel in the binary is replaced with a gray scale value equal to the distance between that pixel and its nearest background pixel. For background pixels the EDM is 0.

Original Image Distance Map
Illustration of
how gray scale transforms
Distmap 01.png
Distmap 02.png
Example File:Distmap 03.png File:Distmap 04.png

Pyramid

To generate images with different resolutions

With the image window active, select Image: Binary: Pyramid to open the cvPyramid dialog.

Pyramid, known as Gaussian Pyramid, is useful in mining image images of all sizes and resolutions. Below is an example of images with different resolutions generated by Pyramid.

Pyramid 01.png

Watershed

To separate objects that touch

With the image window active, select Image: Binary: Pyramid to open the cvWatershed dialog.

Watershed is based on Distance Map. It first calculates the distance map and finds the ultimate eroded points (UEPs). It then dilates each of the UEPs (the peaks or local maxima of the EDM) as far as possible — either until the edge of the particle is reached, or the edge touches a region of another UEP. It works best for smooth convex objects that don’t overlap too much.