summary refs log tree commit diff
path: root/ppmchange.html
blob: 10d50edfec5c0fdaaa118da215c93967e1837118 (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
161
162
163
164
165
166
167
168
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.3//EN">
<html><head><title>Ppmchange User Manual</title></head>
<body>
<h1>ppmchange</h1>
Updated: December 2016
<br>
<a href="#index">Table Of Contents</a>

<h2>NAME</h2>
ppmchange - change all pixels of one color to another in a PPM image

<h2 id="synopsis">SYNOPSIS</h2>

<b>ppmchange</b>

[<b>-closeness=</b><i>closeness_percent</i>]
[<b>-remainder=</b><i>remainder_color</i>]
[<b>-closeok</b>]
[<i>oldcolor newcolor</i>] ...
[<i>ppmfile</i>]

<h2 id="examples">EXAMPLES</h2>

<pre>
<b>ppmchange red blue redimage.ppm &gt;blueimage.ppm</b>

<b>ppmchange red red -remainder=black myimage.ppm &gt;redblack.ppm</b>

<b>ppmchange -closeness=10 white white black black</b>

</pre>

<h2 id="description">DESCRIPTION</h2>

<p>This program is part of <a href="index.html">Netpbm</a>.

<p><b>ppmchange</b> reads a PPM image as input and changes all pixels of
color <i>oldcolor</i> to color <i>newcolor</i>.

You may specify up to 256 oldcolor/newcolor pairs on the command line.
<b>ppmchange</b> leaves all colors not mentioned unchanged, unless you
specify the <b>-remainder</b> option, in which case they are all
changed to the single specified color.

<p>You can specify that colors similar, but not identical, to the ones
you specify get replaced by specifying a "closeness" factor.

<p>Specify the colors as described for the <a
href="libnetpbm_image.html#colorname">argument of the <b>pnm_parsecolor()</b>
library routine</a>.

<p>If a pixel matches two different <i>oldcolor</i>s, <b>ppmchange</b>
replaces it with the <i>newcolor</i> of the leftmost specified one.

<p>The maxval of the output image is the same as that of the input
image.  If a <i>newcolor</i> you specify cannot be exactly represented
in that maxval, <b>ppmchange</b> assumes a color that is as close as
possible to what you specified but can be represented with your
maxval.  Unless you specify the <b>-closeok</b> option,
<b>ppmchange</b> issues a warning that it is using an approximation.

<p>A common way that you can have this maxval problem, where the color
you specify cannot be represented with your maxval, is that your input
is a PBM (black and white) image that you are colorizing.  The maxval
in this case is 1, which severely limits the colors to which you can
change.  To avoid this problem, use <b>pamdepth</b> to make the maxval
of your input something consistent with your colors.  255 is usually a
good choice.

<p>Before Netpbm 10.22 (April 2004), <b>ppmchange</b> always behaved as
if the user specified <b>-closeok</b>, and there was no <b>-closeok</b>
option.


<h2 id="options">OPTIONS</h2>

<p>In addition to the options common to all programs based on libnetpbm
(most notably <b>-quiet</b>, see <a href="index.html#commonoptions">
Common Options</a>), <b>ppmchange</b> recognizes the following
command line options:

<dl compact>
<dt><b>-closeness </b><i>closeness_percent</i>

<dd><i>closeness</i> is a percentage indicating how close to the color you
specified a pixel must be to get replaced.  By default, it is 0, which means
the pixel must be the exact color you specified.

<p>A pixel gets replaced if the distance in color between it and the
color you specified is less than or equal to <i>closeness</i> per cent
of the maxval.

<p>The "distance" in color is defined as the Cartesian sum of the
individual differences in red, green, and blue intensities between the
two pixels, normalized so that the difference between black and white
is 100%.

<p>This is probably simpler than what you want most the time.  You
probably would like to change colors that have similar chrominance,
regardless of their intensity.  So if there's a red barn that is
variously shadowed, you want the entire barn changed.  But because the
shadowing significantly changes the color according to
<b>ppmchange</b>'s distance formula, parts of the barn are probably
about as distant in color from other parts of the barn as they are
from green grass next to the barn.

<p>Maybe <b>ppmchange</b> will be enhanced some day to do chrominance
analysis.

<p>This option was new in Netpbm 9.8 (September 2000).

<dt><b>-closeok</b>

<dd>This option affects how <b>ppmchange</b> interprets a color you
specify in the arguments.  When you specify this option, <b>ppmchange</b>
may use a color close to, but not the same as what you specify.  See
<a href="#description">the description section</a> for details.

<p>This option was new in Netpbm 10.22 (April 2004).  Before that,
<b>ppmchange</b> always behaved as if you specified this option.
     
<dt><b>-remainder </b><i>color</i>

<dd><b>ppmchange</b> changes all pixels which are not of a color for
which you specify an explicit replacement color on the command line to
color <i>color</i>.

<p>An example application of this is

<pre>
<b>ppmchange -remainder=black red red</b>
</pre>

to lift only the red portions from an image, or
<pre>
<b>ppmchange -remainder=black red white | ppmtopgm</b>
</pre>

to create a mask file for the red portions of the image.

</dl>

<h2 id="seealso">SEE ALSO</h2>

<b><a href="pgmtoppm.html">pgmtoppm</a></b>,

<b><a href="ppmcolormask.html">ppmcolormask</a></b>,

<b><a href="ppm.html">ppm</a></b>

<h2 id="author">AUTHOR</h2>

Wilson H. Bent. Jr. (<a href="mailto:whb@usc.edu">whb@usc.edu</a>)
with modifications by Alberto Accomazzi (<a
href="mailto:alberto@cfa.harvard.edu">alberto@cfa.harvard.edu</a>)

<hr>
<h2 id="index">Table Of Contents</h2>
<ul>
<li><a href="#synopsis">SYNOPSIS</a>
<li><a href="#examples">EXAMPLES</a>
<li><a href="#description">DESCRIPTION</a>
<li><a href="#options">OPTIONS</a>
<li><a href="#seealso">SEE ALSO</a>
<li><a href="#author">AUTHOR</a>
</ul>
</body>
</html>