Operations On Binary Images: Frithjof Kruggel, M.D
Operations On Binary Images: Frithjof Kruggel, M.D
Thresholding
Edge detection
Detection of connected components
Morphological operators
Skeletonization
Distance transformation
Let us define foreground as I(x, y) = 1 (printed black) and background as:
I(x, y) = 0 (printed white).
Connectivity
Discrete images have several definitions of neighboring voxels that depend
on the dimensionality. For 1D images, there is only N2 (the previous and
following voxel). For 2D images, we have N4 (edge-connected voxels) and
N8 (edge and corner-connected voxels). For 3D images, distinguish N6 , N18 ,
and N26 .
Compatible Neighborhoods
For a continuous image we expect that a closed curve separates an inner from
an outer region. This is different for digital (discrete) images. Adopting the
same connectivity for foreground and background leads to a paradoxon:
Thresholding
A simple technique for obtaining a binary image from a grey-level image is
thresholding:
(
1, f (i, j) T,
g(i, j) =
0, f (i, j) < T,
where T is denoted as threshold. If objects do not touch each other, and their
intensity is well discriminated from the background, thresholding is a good
segmentation technique.
The choice of a suitable threshold is critical. It may be derived from the
image histogram.
Thresholding - example
Thresholding for the test image, using T = 64 (middle) resp. T = 128
(right):
Edge Detection
Using the definition of connectivity, edge detection in binary images is
straightforward:
A pixel f (i, j) is called edge voxel if it belongs to the foreground and at least
one of its N4 neighbors belongs to the background.
for (int i = 1; i < N-1; i++) {
for (int j = 1; j < M-1; j++) {
if (f(i, j) == 0) continue;
// ignore background
if (f(i-1, j) == 0 || f(i+1, j) == 0 ||
f(i, j-1) == 0 || f(i, j+1) == 0) {
// a neighbor belongs to the background
// so mark current position as an edge pixel.
g(i, j) = 1; } }
Morphological Operators I
Mathematical morphology provides two basic operators, dilation and erosion), from which more complex operators are built.
Consider an n-dimensional binary image f () and s() a second, typically
smaller n-dimensional binary image. f () and s() are given in a set representation that contains all foreground pixels and their addresses.
Let us denote s() as structuring element. During dilation and erosion, this
structuring element is shifted over the whole image while performing an
operation on the set.
The structuring element is shifted over the image by a process called vector
translation. Addresses of all foreground pixels are shifted by a vector t:
f t = {p tkp f }.
Morphological Operators II
Dilation of a binary image f () with a structuring element s():
f s =
f + t = {p + tkp f ,t s}.
ts
f t = {zk(s + z) f }.
ts
Results of erosion or dilation depend obviously on the shape of the structuring element. Often, round or spherical elements
areNext
used.
First Prev
Last Go Back Full Screen Close Quit
Dilation - Implementation
Consider an image f and a structuring element s, given as a list of length K
and the coordinates of the foreground pixels. Dilation works like:
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (f(i, j) == 1) {
g(i, j) = 1; goto next; }
for (int k = 0; k < K; k++) {
ii = i + s[k].i;
if (ii < 0 || ii == N) continue;
jj = j + s[k].j;
if (jj < 0 || jj == M) continue;
if (f(ii, jj) == 1) {
g(ii, jj) = 1; goto next; } }
next: ; }
}
Dilation - Example
Original image (top left), dilation (3x3, top right), closing (3x3, below left),
closing (5x5, below right).
Erosion - implementation
Erosion works like:
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (f(i, j) == 0) {
g(i, j) = 0; goto next; }
for (int k = 0; k < K; k++) {
...
if (f(ii, jj) == 0) goto next; }
g(i, j) = 1;
next: ; }
}
Erosion - Example
Original image (top left), erosion (3x3, top right), opening (3x3, below left),
opening (5x5, below right).
Skeletonization
The skeleton of a region is obtained by repeated application of a pixelwise
thinning operation:
1. Denote f () a binary image, and p one of its a foreground pixels.
2. p is called a directed border pixel if one pixel in its N4 neighborhood
belongs to the background.
3. All directions (N, O, S, W) are stepped through sequentially.
4. All directed border pixel are candidates for removal, except their number
of foreground pixels in the N4 neighborhood is less than 2.
5. All deletable pixels in one direction are marked in one run and removed
in a second run.
6. This process is repeated until no removals are possible.
Skeletonization - Implementation
pixel R[N];
// contains pixels of the input image
do {
ndel = 0;
for (dir = 0; dir < 4; dir++) { // for all directions
switch (dir) {
case 0: di = 0; dj = 1; break;
case 1: di = 1; dj = 0; break;
case 2: di = 0; dj = -1; break;
case 3: di = -1; dj = 0; break; }
// mark all removable pixels
for (int n = 0; n < N; n++) {
if (g(R[n].i, R[n].j) == 1) continue;
if (g(R[n].i+di, R[n].j+dj) == 1) continue;
if (neighbors(g(R[n].i, R[n].j) < 2) continue;
R[n].mark = 1; }
// remove all marked pixels
for (int n = 0; n < N; n++) {
if (R[n].mark == 1) {
g(R[n].i, R[n].j) = 0;
R[n].mark = 0;
ndel++; } } } }
while (ndel != 0);
Skeletonization - Example
Intensity images (top row) and skeletons (below):
Distance Transformation
The distance transform is used to determine distances between objects. Consider the one-dimensional case. In this example, 0 corresponds to a foreground pixel from which distances are measured, and some distance to be
determined. Let us define a local distance mask [1 0 1]. This local mask is
added to pixels at a specific position. The minimum of all sums is addressed
to the pixel at this position. The process is repeated in a waveform fashion:
2
2
1
1
1
0
0
0
0
1
1
1
2
2
2
2
1
1
1
0
0
0
0
1
1
1
where:
b a b
f mask = a 0 0 ,
0 0 0
0 0 0
bmask = 0 0 a ,
b a b