summary refs log tree commit diff
path: root/pamditherbw.html
blob: fb206a8931e21c8fd112c671e85ca2e6f7125f94 (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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.3//EN">
<html><head><title>Pamditherbw User Manual</title></head>
<body>
<h1>pamditherbw</h1>
Updated: 10 May 2010
<br>
<a href="#index">Table Of Contents</a>

<h2>NAME</h2>

pamditherbw - dither grayscale image to black and white

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

<b>pamditherbw</b>

[<b>-floyd</b> | <b>-fs</b>
| <b>-atkinson</b>
| <b>-threshold</b>
| <b>-hilbert</b>
| <b>-dither8</b> | <b>-d8</b> | <b>-cluster3</b>
| <b>-c3</b> | <b>-cluster4</b> | <b>-c4</b>
| <b>-cluster8</b> | <b>-c8</b>]

[<b>-value</b> <i>val</i>]

[<b>-clump</b> <i>size</i>]

[<b>-randomseed=</b><i>integer</i>]

[<i>pamfile</i>]

<p>All options can be abbreviated to their shortest unique prefix.

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

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

<p><b>pamditherbw</b> dithers a grayscale image.  Dithering means turning
each shade of gray into a pattern of black and white pixels that, from
a distance, look the same as the gray.

<p>The input should be a PGM image or a PAM image of tuple type
GRAYSCALE.  However, <b>pamditherbw</b> doesn't check, so if you feed
it e.g. a PPM image, it will produce arbitrary results (actually, it
just takes the first channel of whatever you give it and treats it as
if it represented gray levels).

<p>The output is a PAM with tuple type BLACKANDWHITE.  You can turn
this into a PBM (if you need to use it with an older program that doesn't
understand PAM) with <b>pamtopnm</b>.

<p>To do the opposite of dithering, you can usually just scale the image
down and then back up again with <b>pamscale</b>, possibly smoothing or
blurring the result with <b>pnmsmooth</b> or <b>pnmconvol</b>.  Or use
the special case program <b>pbmtopgm</b>.

<p>To dither a color image (to reduce the number of pixel colors),
use <b>ppmdither</b>.

<p>Another way to convert a grayscale image to a black and white image
is thresholding.  Thresholding is simply replacing each grayscale pixel
with a black or white pixel depending on whether its brightness is above or
below a threshold.  That threshold might vary.  Simple thresholding is a
degenerate case of dithering, so <b>pamditherbw</b> does very simple
thresholding with its <b>-threshold</b> option.  But <b>pamthreshold</b>
does more sophisticated thresholding.

<p>If all you want is to change a PGM image with maxval 1 to a PBM image,
<b>pamtopnm</b> will do that.


<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>pamditherbw</b> recognizes the following
command line options:

<h3 id="quantmethod">Quantization Method</h3>

<p>The default quantization method is boustrophedonic Floyd-Steinberg
error diffusion (<b>-floyd</b> or <b>-fs</b>).

<p>Also available are simple thresholding (<b>-threshold</b>); Bayer's
ordered dither (<b>-dither8</b>) with a 16x16 matrix;
<a href="http://www.tinrocket.com/projects/programming/graphics/00158/">
Atkinson</a>; and three different sizes of 45-degree clustered-dot
dither (<b>-cluster3</b>, <b>-cluster4</b>, <b>-cluster8</b>).

<p>A space filling curve halftoning method using the Hilbert curve is
also available (<b>-hilbert</b>).

<p>Floyd-Steinberg or Atkinson will almost always give the best
looking results; however, looking good is not always what you want.
For instance, you can use thresholding in a pipeline with the
<b>pnmconvol</b>, for tasks such as edge and peak detection.  And
clustered-dot dithering gives a newspaper-ish look, a useful special
effect.

<p>Floyd-Steinberg is by far the more traditional, but
<a href="http://www.tinrocket.com/projects/programming/graphics/00158/">
some claim</a> Atkinson works better.

<p>The Hilbert curve method is useful for processing images before
display on devices that do not render individual pixels distinctly
(like laser printers).  This dithering method can give better results
than the dithering usually done by the laser printers themselves.  The
<b>-clump</b> option alters the number of pixels in a clump.  Typically a PGM
image will have to be scaled to fit on a laser printer page (2400 x 3000
pixels for an A4 300 dpi page), and then dithered to a PBM image before being
converted to a postscript file.  A printing pipeline might look something
like:

<pre>
    pamscale -xysize 2400 3000 image.pgm | pamditherbw -hilbert |  \
      pamtopnm | pnmtops -scale 0.25 &gt; image.ps 
</pre>

<h3 id="otheropts">Other Options</h3>

<dl>

<dt><b>-value</b>

<dd>This option alters the thresholding value for Floyd-Steinberg,
Atkinson, and simple thresholding.  It should be a real number between
0 and 1.  Above 0.5 means darker images; below 0.5 means lighter.

<dt><b>-clump</b>
<dd>This option alters the number of pixels in a clump when the
Hilbert curve method is used.  This is usually an integer between 2
and 100 (default 5).  Smaller clump sizes smear the image less and are
less grainy, but seem to lose some grey scale linearity.

<dt><b>-randomseed=</b><i>integer</i>

<dd>The Floyd-Steiberg and Atkinson methods use random numbers to
diffuse the error.  This is the seed for the random number generator.
The other methods do not employ random numbers and ignore this option.

<p>Use this to ensure you get the same image on separate invocations.

<p>By default, <b>pamditherbw</b> uses a seed derived from the time of day
and process ID, which gives you fairly uncorrelated results in multiple
invocations.

<p>This option was new in Netpbm 10.45 (December 2008).

</dl>


<h2 id="references">REFERENCES</h2>

<p>The only reference you need for this stuff is "Digital
Halftoning" by Robert Ulichney, MIT Press, ISBN 0-262-21009-6.

<p>The Hilbert curve space filling method is taken from "Digital
Halftoning with Space Filling Curves" by Luiz Velho, Computer
Graphics Volume 25, Number 4, proceedings of SIGRAPH '91, page
81. ISBN 0-89791-436-8

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

<a href="pamtopnm.html">pamtopnm</a>,
<a href="pgmtopgm.html">pgmtopgm</a>,
<a href="pbmtopgm.html">pbmtopgm</a>,
<a href="pamthreshold.html">pamthreshold</a>,
<a href="pbmreduce.html">pbmreduce</a>,
<a href="pnmconvol.html">pnmconvol</a>,
<a href="pamscale.html">pamscale</a>,
<a href="pam.html">pam</a>,
<a href="pnm.html">pnm</a>,

<h2 id="history">HISTORY</h2>

<p><b>pamditherbw</b> was new in Netpbm 10.23 (July 2004), but is
essentially the same program as <b>pgmtopbm</b> that has existed
practically since the beginning.  <b>pamditherbw</b> differs from its
predecessor in that it properly adds brightnesses (using gamma
transformations; <b>pgmtopbm</b> just adds them linearly) and that it
accepts PAM input in addition to PGM and PBM and produces PAM output.

<p><b>pamditherbw</b> obsoletes <b>pgmtopbm</b>.

<p><b>-atkinson</b> was new in Netpbm 10.38 (March 2007).

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

Copyright (C) 1989 by Jef Poskanzer.

<hr>
<h2 id="index">Table Of Contents</h2>
<ul>
<li><a href="#synopsis">SYNOPSIS</a>
<li><a href="#description">DESCRIPTION</a>
<li><a href="#options">OPTIONS</a>
  <ul>
  <li><a href="#quantmethod">Quantization Method</a>
  <li><a href="#otheropts">Other Options</a>
  </ul>
<li><a href="#references">REFERENCES</a>
<li><a href="#seealso">SEE ALSO</a>
<li><a href="#history">HISTORY</a>
<li><a href="#author">AUTHOR</a>
</ul>
</body>
</html>