Docsity

Parallel Programming: Techniques & Applications with Networked Workstations, Study notes of Computer Science

Toggle sidebar
bg1
Page 271
Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers
Barry Wilkinson and Michael Allen Prentice Hall, 1999. All rights reserved.
Chapter 11 Image Processing
Figure 11.1 Pixmap.
j
i
Origin (0, 0)
p(i, j)
Picture element
(pixel)
Low-level Image Processing
Operates directly on a stored image to improve or enhance it. Stored image consists of
a two-dimensional array of pixels (picture elements):
Many low-level image-processing operations assume monochrome images and refer to
pixels as having gray level values or intensities.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24

Partial preview of the text

Download Parallel Programming: Techniques & Applications with Networked Workstations and more Study notes Computer Science in PDF only on Docsity!

Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen  Prentice Hall, 1999. All rights reserved.

Chapter 11 Image Processing

Figure 11.1 Pixmap.

j

i

Origin (0, 0)

Picture element p ( i , j ) (pixel)

Low-level Image Processing

Operates directly on a stored image to improve or enhance it. Stored image consists of a two-dimensional array of pixels (picture elements):

Many low-level image-processing operations assume monochrome images and refer to pixels as having gray level values or intensities.

Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen  Prentice Hall, 1999. All rights reserved.

Computational Requirements

Suppose a pixmap has 1024 × 1024 pixels and 8-bit pixels.

Storage requirement is 2^20 bytes (1 Mbytes) Suppose each pixel must be operated upon just once.

Then 2^20 operations are needed in the time of one frame.

At 10-8^ second/operation (10ns/operation), this would take 10 ms. In real-time applications, the speed of computation must be at the frame rate (typically 60–85 frames/second). All pixels in the image must be processed in the time of one frame; that is, in 12–16 ms. Typically, many high-complexity operations must be performed, not just one operation.

Point Processing

Operations that produce an output based upon the value of a single pixel.

Thresholding

Pixels with values above a predetermined threshold value are kept and others below the threshold are reduced to 0. Given a pixel, xi , the operation on each pixel is

if ( xi < threshold) xi = 0; else xi = 1;

Contrast Stretching

Range of gray level values extended to make details more visible. Given pixel of value xi within range xl and xh , the contrast stretched to the range xH to xL by multiplying xi by

Gray Level Reduction

Number of bits used to represent the gray level reduced. Simple method would be to truncate the lesser significant bits.

xi ( xi – xl )

xH – xL xh – xl

=  ------------------^ + xL

Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen  Prentice Hall, 1999. All rights reserved.

Smoothing, Sharpening, and Noise Reduction

Smoothing suppresses large fluctuations in intensity over the image area and can be achieved by reducing the high-frequency content.

Sharpening accentuates the transitions, enhancing the detail, and can be achieved by two ways.

Noise reduction suppresses a noise signal present in the image.

x 1 x
x 4 x

x 1 x 2

x 6 x

Figure 11.3 Pixel values for a 3 × 3 group.

Often requires a local operation with access to a group of pixels around the pixel to be updated. A common group size is 3 × 3:

Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen  Prentice Hall, 1999. All rights reserved.

Mean

A simple smoothing technique is to take the mean or average of a group of pixels as the new value of the central pixel.

Given a 3 × 3 group, the computation is

where is the new value for x 4.

Sequential Code

Nine steps to compute the average for each pixel, or 9 n for n pixels. A sequential time complexity of Ο( n ).

x 3 + x 4 + x

x 0 + x 1 + x 2 + x 3 + x 4 + x 5 + x 6 + x 7 +x 8 9

= ---------------------------------------------------------------------------------------------------

x 4 '

Parallel Code

Number of steps can be reduced by separating the computation into four data transfer steps in lock-step fashion.

Step 1 Each pixel adds pixel from left

Step 2 Each pixel adds pixel from right

Step 3 Each pixel adds pixel from above

Step 4 Each pixel adds pixel from below

Figure 11.4 Four-step data transfer for the computation of mean.

Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen  Prentice Hall, 1999. All rights reserved.

Median

Sequential Code

Median can be found by ordering the pixel values from smallest to largest and choosing the center pixel value (assuming an odd number of pixels).

With a 3 × 3 group, suppose the values in ascending order are y 0 , y 1 , y 2 , y 3 , y 4 , y 5 , y 6 , y 7 , and y 8. The median is y 4.

Suggests that all the values in the group must first be sorted, and then the fifth element taken to replace the original value of the pixel.

Using bubble sort, in which the lesser values are found first in order, sorting could, in fact, be terminated after the fifth lowest value is obtained.

Number of steps for finding each median is given by 8 + 7 + 6 + 5 + 4 = 30 steps, or 30 n for n pixels.

Parallel Code

An Approximate Sorting Algorithm

First, a compare-and-exchange operationperformed on each of the rows, requiring three steps. For the i th row, we have

pi , j − 1 ↔ pi , j pi , j ↔ pi , j + 1 pi , j − 1 ↔ pi , j

where ↔ means “compare and exchange if left gray level greater than right gray level”.

Then the columns sorted using three compare-and-exchange operations:

pi −1, j ↔ pi , j pi , j ↔ pi +1, j pi −1, j ↔ pi , j

The value in pi , j is taken to be the fifth largest pixel value. Does not always select fifth largest value.Reasonable approximation. Only requires six steps.

Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen  Prentice Hall, 1999. All rights reserved.

Largest (^) Next largest

Next largest

in row (^) in row

in column

Figure 11.6 Approximate median algorithm requiring six steps.

Weighted Masks

The mean method could be described by a weighted 3 × 3 mask.

Suppose the weights are w 0 , w 1 , w 2 , w 3 , w 4 , w 5 , w 6 , w 7 , and w 8 , and pixel values are x 0 , x 1 , x 2 , x 3 , x 4 , x 5 , x 6 , x 7 , and x 8.

The new center pixel value, , is given by

The scale factor, 1/ k , is set to maintain the correct grayscale balance in the image after the operation. Often, k is given by w 0 + w 1 + w 2 + w 3 + w 4 + w 5 + w 6 + w 7.

The summation of products, wixi , from two functions w and x is the (discrete) cross-cor- relation of f with w (written as f ⊗ w ).

x 4 '

x 4 '

w 0 x 0 + w 1 x 1 + w 2 x 2 + w 3 x 3 + w 4 x 4 + w 5 x 5 + w 6 x 6 + w 7 x 7 + w 8 x 8 k

= ----------------------------------------------------------------------------------------------------------------------------------------------------------------

Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen  Prentice Hall, 1999. All rights reserved.

1

1 8 1

1 1

1 1 1

Figure 11.9 A noise reduction mask.

1 16

k =

Figure 11.10 High-pass sharpening filter mask.

1 9

k =

The computation done with this mask is

x 4 '

8 x 4 – x 0 – x 1 – x 2 – x 3 – x 5 – x 6 – x 7 – x 8 9

= ---------------------------------------------------------------------------------------------------

Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen  Prentice Hall, 1999. All rights reserved.

Edge Detection

Highlighting edges of object where an edge is a significant change in gray level intensity.

Gradient and Magnitude

Let us first consider a one-dimension gray level function, f ( x ) (say along a row).

If the function, f ( x ), were differentiated, the first derivative, ∂ f /∂ x , measures the gradient of the transition and would be a positive-going or negative-going spike at a transition.

The direction of the transition (either increasing or decreasing) can be identified by the polarity of the first derivative.

Intensity transition

First derivative

Figure 11.11 Edge detection using differentiation.

Second derivative

Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen  Prentice Hall, 1999. All rights reserved.

Edge Detection Masks

For discrete functions, the derivatives are approximated by differences.

The term ∂ f /∂ x is the difference in the x -direction and ∂ f /∂ y is the difference in the y - direction.

We might consider computing the approximate gradient using pixel values x 5 and x 3 (to get ∂ f /∂ x ) and x 7 and x 1 (to get ∂ f /∂ y ); i.e.,

so that

Two masks are needed, one to obtain x 7 − x 1 and one to obtain x 5 − x 3.

The absolute values of the results of each mask are added together.

∂ f ∂ x

------ ≈ x 5 – x 3

∂ f ∂ y

------ ≈ x 7 – x 1

∇ f ≈x 7 – x 1 + x 5 – x 3

Prewitt Operator

The approximate gradient obtained from

Then

which requires using the two 3 × 3 masks.

∂ f ∂ y

------ (^) ≈( x 6 – x 0 ) + ( x 7 – x 1 ) +( x 8 – x 2 )

∂ f ∂ x

------ ≈( x 2 – x 0 ) + ( x 5 – x 3 ) +( x 8 – x 6 )

∇ f ≈ x 6 – x 0 + x 7 – x 1 + x 8 – x 2 + x 2 – x 0 + x 5 – x 3 + x 8 – x 6

Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen  Prentice Hall, 1999. All rights reserved.

0

1

0

1

− 1

0

1

− 1 − 1

− 1

1

0

0

1

1

− 1

− 1 0

Figure 11.13 Prewitt operator.

Sobel Operator

Derivatives are approximated to

Operators implementing first derivatives will tend to enhance noise.

However, the Sobel operator also has a smoothing action.

∂ f ∂ y

------ (^) ≈( x 6 + 2 x 7 + x 8 ) – ( x 0 + 2 x 1 + x 2 )

∂ f ∂ x

------ ≈( x 2 + 2 x 5 + x 8 ) – ( x 0 + 2 x 3 + x 6 )

Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen  Prentice Hall, 1999. All rights reserved.

Laplace Operator

The Laplace second-order derivative is defined as

approximated to

which can be obtained with the single mask:

∇^2 f f

2 ∂

x

x

x

x

2 ∂

-------- f

2 ∂ y 2 ∂

= + --------

∇^2 f = 4 x 4 – ( x 1 + x 3 + x 5 + x 7 )

− 1

0

4

− 1

0

− 1

0

0 − 1

Figure 11.16 Laplace operator.

x 1

x 5

x 7

x 3 x 4

Left pixel Right pixel

Upper pixel

Lower pixel

Figure 11.17 Pixels used in Laplace operator.

Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen  Prentice Hall, 1999. All rights reserved.

Figure 11.18 Effect of Laplace operator.

The Hough Transform

Purpose is to find the parameters of equations of lines that most likely fit sets of pixels in an image.

A line is described by the equation y = ax + b where the parameters, a and b , uniquely describe the particular line, a the slope and b the intercept on the y -axis.

A search for those lines with the most pixels mapped onto them would be computation- ally prohibitively expensive [an Ο( n^3 ) algorithm].

Suppose the equation of the line is rearranged as: b = − xa + y Every point that lies on a specific line in the x - y space will map into same point in the a- b space (parameter space).

Therefore, we can find the number of points on each possible line in the x - y space by simply counting when a mapping maps into a point in the a - b space.

Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen  Prentice Hall, 1999. All rights reserved.

r = x cos θ + y sin θ

r

θ

Figure 11.20 Mapping a line into ( r , θ) space.

r

θ

(a) ( x , y ) plane (b) ( r , θ) plane

y = ax + b

y

x

( r , θ)

Method will fail for vertical lines and with lines that approach this extreme.

To avoid the problem, line equationrearranged to polar coordinates: r = x cos θ + y sin θ where r is the perpendicular distance to the origin in the original ( x , y ) coordinate system and θ is the angle between r and the x -axis.

The θ value will be in degrees and very conveniently will also be the gradient angle of the line (with respect to the x -axis).

Each line will map to a single point in the ( r , θ) space.

A vertical line will simply map into a point where θ = 0° if a positive intercept with the x -axis, or θ = 180° if a negative intercept with the x -axis.

A horizontal line has θ = 90°.

Each point in the x - y space will map into a curve in the ( r , θ) space; i.e., ( x 1 , y 1 ) maps

into r = x 1 cos θ + y 1 sin θ

Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen  Prentice Hall, 1999. All rights reserved.

r

y

x

Figure 11.21 Normal representation using image coordinate system.

Implementation

Assume origin at the top left corner.

The parameter space is divided into small rectangular regions. One accumulator is provided for each region.

Accumulators of those regions that a pixel maps into are incremented. This process must be done for all the pixels in the image.

If all values of θ were tried (i.e., incrementing θ through all its values), the computational effort would be given by the number of discrete values of θ, say k intervals. With n pixels the complexity is Ο( kn ).

The computational effort can be reduced significantly by limiting the range of lines for individual pixels using some criteria. A single value of θ could be selected based upon the gradient of the line.