summary refs log tree commit diff
path: root/ppmhist.html
blob: f8674d30cd036b34ca044a51b25add6845ba48f6 (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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.3//EN">
<html><head><title>Ppmhist User Manual</title></head>
<body>
<h1>ppmhist</h1>
Updated: 24 August 2019
<br>
<a href="#index">Table Of Contents</a>

<h2>NAME</h2>
ppmhist - print a histogram of the colors in a PPM image

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

<b>ppmhist</b>
[<b>-hexcolor</b> | <b>-float</b> | <b>-colorname</b> | <b>-map</b>]
[<b>-nomap</b>]
[<b>-noheader</b>]
[<b>-sort=</b>{<b>frequency</b>,<b>rgb</b>}]
[<b>-forensic</b>]
[<i>ppmfile</i>]

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

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

<p><b>ppmhist</b> reads a PPM image as input and generates a histogram
of the colors in the image, i.e. a list of all the colors and how many
pixels of each color are in the image.

<h3 id="output">Output Format</h3>

<p>The output is in one of two basic formats:  a report for humans
and a PPM image for use by programs.  The PPM image is actually quite
readable by humans too.

<h4>Human Report</h4>

<p>You get this format by specifying (or defaulting to) the
<b>-nomap</b> option.

<p>The format is one line for each color in the input image.

<p>By default, there are two lines of column header and a summary at the top.
Use the <b>-noheader</b> option to suppress those lines.

<p>The summary tells you whether black or white are present and how many
shades of gray and color are present.  The summary was new in Netpbm 10.82
(March 2018).
  
<p>In each line, <b>ppmhist</b> identifies the color by red, green,
and blue components.  By default, it lists each of these in decimal,
using the exact values that are in the PPM input.  So if the image has
a maxval of 255, the numbers in the listing range from 0 to 255.  With
the <b>-hexcolor</b> option, you can change these numbers to
hexadecimal.  With the <b>-float</b> option, the numbers are
fractional, adjusted to a maxval of 1.

<p>Each line lists the luminosity of the color.  It is in decimal
on the same scale as the rgb values (see above).

<p>Each line lists the number of pixels in the image that have the color.
This is in decimal.


<h4>PPM Output</h4>

<p>You get this format with the <b>-map</b> option.

<p>The output file is a genuine PPM image, but it is PPM Plain format
and contains comments so that it is not a lot different from the
human report described above.

<p>As a PPM image, it can be useful as input to other programs that
need some kind of palette.  The image is a single row with one
column for each distinct color in the image.

<p>The function of PPM output is essentially the same as the output of
<b>pnmcolormap all</b>.  <b>ppmhist</b> is much older than <b>pnmcolormap</b>.


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

<dl compact>

<dt><b>-sort=</b>{<b>frequency</b>,<b>rgb</b>}

<dd>The <b>-sort</b> option determines the order in which the colors are
listed in the output.  <b>rgb</b> means to sort them first by the intensity of
the red component of the color, then of the green, then of the blue, with the
least intense first.  <b>frequency</b> means to list them in order of how many
pixels in the input image have the color, with the most represented colors
first.  Among colors with the same frequency, the order is the same as with
<b>rgb</b>.

<p>The default is <b>frequency</b>.

<p>Before Netpbm 10.88 (September 2019), with <b>-sort=frequency</b>, the
order of colors that have the same frequency is arbitrary.
  
<dt><b>-hexcolor</b>

<dd>Print the color components in hexadecimal.  See <a href="#output">output
format</a>.

<p>You may not specify this option along with <b>-float</b> or <b>map</b>.

<dt><b>-float</b>

<dd>Print the color components and the luminosity as floating point
numbers in the range [0,1].  See <a href="#output">output format</a>.

<p>You may not specify this option along with <b>-hexcolor</b> or <b>map</b>.

<p>This option was added in Netpbm 10.19 (November 2003).

<dt><b>-map</b>

<dd>Generates a PPM file of the colormap for the image, with the
color histogram as comments.  See <a href="#output">output format</a>.

<p>You may not specify this option along with <b>-float</b> or <b>hexcolor</b>.

<dt><b>-nomap</b>

<dd>
Generates the histogram for human reading.  This is the default.

<dt><b>-colorname</b>

<dd>Add the color name to the output.  This is the name from
the <a href="libppm.html#dictionary">system color dictionary</a>.  If the
exact color is not in the color dictionary, it is an asterisk followed by the
name of the closest color that is in the dictionary.  If you don't have a
system color dictionary, the program fails.

<p>This option was added in Netpbm 10.10 (October 2002).

<dt><b>-noheader</b>

<dd>Do not print the column headings.

<dt><b>-forensic</b><dd>

<p>With this option, <b>ppmhist</b> works on images that contain invalid sample
values.  Normally, like most Netpbm programs, <b>ppmhist</b> fails if it
encounters a sample value greater than the maxval that the image declares.  The
presence of such a value means the image is invalid, so the pixels have no
meaning.  But with <b>-forensic</b>, <b>ppmhist</b> produces a histogram
of the actual sample values without regard to maxval.  It issues messages
summarizing the invalid pixels if there are any.

<p>One use for this is to diagnose the problem that caused the invalid Netpbm
image to exist.

<p>There is a small exception to the ability of <b>ppmhist</b> to process
invalid pixels even with <b>-forensic</b>: it can never process a sample value
greater than 65535.  Note that in the rarely used Plain PPM format, it is
possible for a number greater than that to appear where a sample value
belongs.

<p>This option was new in Netpbm 10.66 (March 2014).  But Netpbm older than
10.66 does not properly reject invalid sample values, so the effect is very
similar to <b>-forensic</b>.

</dl>

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

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

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

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

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

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

<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>
  <ul>
  <li><a href="#output">Output Format</a>
  </ul>
<li><a href="#options">OPTIONS</a>
<li><a href="#seealso">SEE ALSO</a>
<li><a href="#author">AUTHOR</a>
</ul>
</body>
</html>