summary refs log tree commit diff
path: root/extendedopacity.html
blob: 32dbe1506c7b73fbe8c6bc80491313cb4228597c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.3//EN">
<html><head><title>Image Processing By Interp and Extrapolation</title>
<meta name="manual_section" content="5">
</head>
<body>
<h1>extendedopacity</h1>
Created: 17 April 2003
<br>
<?makeman .SH NAME ?>
<?makeman extendedopacity - theory of netpbm interpolation and extrapolation ?>
<?makeman .SH DESCRIPTION ?>

<p>This page is a copy of http://www.sgi.com/misc/grafica/interp/ on
April 17, 2003, with some slight formatting changes, included in the
Netpbm documentation for convenience.  Since at least June 11, 2005,
the source page has been missing.

<h2>Image Processing By Interpolation and Extrapolation</h2>
<i>Paul Haeberli and Douglas Voorhies</i>

<h3>Introduction</h3>
<p>
Interpolation and extrapolation between two images offers a general,
unifying approach to many common point and area image
processing operations.  Brightness, contrast, saturation, tint, and
sharpness can all be controlled with one formula, separately or
simultaneously.  In several cases, there are also performance benefits.
<p>
Linear interpolation is often used to blend two images.
Blend fractions (alpha) and (1 - alpha) are used in a weighted average
of each component of each pixel:

<pre>
      out = (1 - alpha)*in0 + alpha*in1
</pre>

<p>
Typically alpha is a number in the range 0.0 to 1.0.  This is
commonly used to linearly interpolate two images.
What is less often considered is that alpha may range beyond the
interval 0.0 to 1.0.
Values above one subtract a portion of in0 while scaling in1.  Values
below 0.0 have the opposite effect.
<p>
Extrapolation is particularly useful if a degenerate version of the
image is used as the image to get "away from."  Extrapolating away from
a black-and-white image increases saturation.  Extrapolating away from a
blurred image increases sharpness.  The interpolation/extrapolation
formula offers one-parameter control, making display of a series of
images, each differing in brightness, contrast, sharpness, color, or
saturation, particularly easy to compute, and inviting hardware acceleration.
<p>
In the following examples, a single alpha value is used per image.
However other processing is possible, for example where alpha is a function
of X and Y, or where a brush footprint controls alpha near the cursor.

<h3>Changing Brightness</h3>

<p>
To control image brightness, we use pure black as the degenerate (zero
alpha) image.  Interpolation darkens the image, and extrapolation
brightens it.  In both cases, brighter pixels are affected more.

<img src="blend1.gif" alt="brightness" width="469" height="154">

<h3>Changing Contrast</h3>
<p>
Contrast can be controlled using a constant gray image with the average image
luminance.  Interpolation reduces contrast and extrapolation boosts it.
Negative alpha generates inverted images with varying contrast.  In
all cases, the average image luminance is constant.

<img src="blend3.gif" alt="contrast" width="469" height="154">
<p>
If middle gray or the average pixel color is used instead, contrast is
again altered, but with middle gray or the average color left unaffected.
Shades and colors far away from the chosen value are most affected.

<h3>Changing Saturation</h3>
<p>
To alter saturation, pixel components must move towards or away from the
pixel's luminance value. By using a black-and-white image as the
degenerate version, saturation can be decreased using interpolation, and
increased using extrapolation.  This avoids computationally more
expensive conversions to and from HSV space.  Repeated update in
an interactive application is especially fast, since the luminance
of each pixel need not be recomputed.  Negative alpha preserves luminance
but inverts the hue of the input image.

<img src="blend4.gif" alt="saturation" width="469" height="154">

<h3>Sharpening an Image</h3>
<p>
Any convolution, such as sharpening or blurring, can be adjusted by
this approach.
If a blurred image is used as the degenerate image,
interpolation attenuates high frequencies to varying degrees, and
extrapolation boosts them, sharpening the image by unsharp masking.
Varying alpha acts as a kernel scale factor, so a series of
convolutions differing only in scale can be done easily, independent of
the size of the kernel.  Since blurring, unlike sharpening, is often a
separable operation, sharpening by extrapolation may be far more
efficient for large kernels.

<img src="blend6.gif" alt="sharpening" width="469" height="154">
<p>
Note that global contrast control, local contrast control, and
sharpening form a continuum.
Global contrast pushes pixel components
towards or away from the average image luminance.  Local contrast is
similar, but uses local area luminance.  Unsharp masking is the extreme
case, using only the color of nearby pixels.

<h3>Combined Processing</h3>

<p>
An unusual property of this interpolation/extrapolation approach is that
all of these image parameters may be altered simultaneously.  Here
sharpness, tint, and saturation are all altered.

<img src="blend7.gif" alt="combined" width="469" height="154">

<h3>Conclusion</h3>
<p>
Image applications frequently need to produce multiple degrees of
manipulation interactively.
Image applications frequently need to interactively manipulate
an image by continuously changing a single parameter.
The best hardware mechanisms employ a
single "inner loop" to achieve a wide variety of effects.  Interpolation
and extrapolation of images can be a unifying approach, providing a single
function that can do many common image processing operations.
<p>
Since a degenerate image is sometimes easier to calculate, extrapolation
may offer a more efficient method to achieve effects such as sharpening
or saturation.  Blending is a linear operation, and so it must be
performed in linear, not gamma-warped space.  Component range must also be
monitored, since clamping, especially of the degenerate image, causes
inaccuracy.
<p>
These image manipulation techniques can be used in paint programs to
easily implement brushes that saturate, sharpen, lighten, darken,
or modify contrast and color.  The only major change needed is to work with
alpha values outside the range 0.0 to 1.0.
<p>
It is surprising and unfortunate how many graphics software packages
needlessly limit interpolant values to the range 0.0 to 1.0.  Application
developers should allow users to extrapolate parameters when practical.
<h3>References</h3>
<p>
For a slightly extended version of this article, see:<br>
P. Haeberli and D. Voorhies. <cite>Image Processing by Linear 
Interpolation and Extrapolation</cite>. 
IRIS Universe Magazine No. 28, Silicon Graphics, Aug, 1994.

<p>
<img src="gobot.gif" alt="" width="564" height="25" border="0">

</body>
</html>