1Pambackground User Manual(0)                      Pambackground User Manual(0)
2
3
4

NAME

6       pambackground - create a mask of the background area of an image
7
8

SYNOPSIS

10       pambackground
11
12       [netpbmfile]
13
14       [-verbose]
15
16       Minimum  unique  abbreviations  of options are acceptable.  You may use
17       double hyphens instead of single hyphen to denote options.  You may use
18       white space in place of the equals sign to separate an option name from
19       its value.
20
21
22

DESCRIPTION

24       This program is part of Netpbm(1).
25
26       pambackground reads a PNM or PAM image as input.  It generates as  out‐
27       put  a  PAM  image  that identifies the background area of the image (a
28       mask).
29
30       To identify the background, pambackground assumes the image is a  fore‐
31       ground  image, smaller than the total image size, placed over a single-
32       color background.  It assumes that foreground image is solid -- it does
33       not  have  holes  through which the background can be seen.  So in spe‐
34       cific, pambackground first identifies the background color, then  finds
35       all contiguous pixels of that color in regions touching any edge of the
36       image.  Think of it as starting at each of the four  edges  and  moving
37       inward and spreading out as far as possible until it hits pixels of an‐
38       other color (the foreground image).
39
40       pambackground identifies the background color as follows: If any 3 cor‐
41       ners  of the image are the same color, that's the background color.  If
42       not, but 2 corners are the same color,  the  background  color  is  the
43       color  of a pair of identically colored corners in this priority order:
44       top, right, left, bottom.  If no two corners have the same  color,  the
45       background color is the color of the upper left corner.
46
47       In  a  typical  photograph,  the area that you would consider the back‐
48       ground is many shades of a color, so to pambackground  it  is  multiple
49       colors  and pambackground will not meaningfully identify the background
50       of your image.  To use pambackground in this case, you might  use  ppm‐
51       change  to  change all similar colors to a single one first.  For exam‐
52       ple, if the photograph is a building against a blue sky, where  nothing
53       remotely  sky-blue  appears in the building, you could use ppmchange to
54       change all pixels within 20% of "SkyBlue" to SkyBlue, then run pamback‐
55       ground on it.
56
57       You  might  even  extract  the argument for ppmchange from the image in
58       question, using pamgetcolor.  In the foregoing  example,  we  knew  the
59       background  was  approximately  SkyBlue, but if we didn't we could just
60       get the color of the top left pixel, in a form suitable for  the  color
61       arguments of ppmchange like this:
62
63           $ color=$(pamgetcolor 0,0 -infile=/tmp/bodyskl|cut --fields=2 -delim=' ')
64
65
66       A  more convenient means of dealing with a multi-shade background is to
67       use pnmquant to produce a version of the image with a very small number
68       of colors.  The background would likely then be all one color.
69
70       If  the  pnmquant and ppmchange methods above do not adequately distin‐
71       guish foreground colors from background colors,  you  can  try  a  more
72       elaborate  method using pnmremap.  If you can manually create a palette
73       with one color to which all the  background  pixels  are  similar,  and
74       other colors to which the foreground pixels are similar, you can use it
75       as input to pnmremap to create a smarter version of what you  get  with
76       the pnmquant or ppmchange methods, so that pambackground is more likely
77       to separate background from foreground as your eye does.
78
79       The PAM that pambackground creates has a single plane, with a maxval of
80       1.   The sample value 1 means background; 0 means foreground.  There is
81       no tuple type.  Some older programs (but none that are part of  Netpbm)
82       don't  know  what a PAM is and expect a mask to be in the form of a PGM
83       or PBM image.  To convert pambackground's output to PBM,  use  pamtopnm
84       -assume.  To convert to PGM, use pgmtopgm.
85
86       netpbmfile  is  the file specification of the input file, or - to indi‐
87       cate Standard Input.  The default is Standard Input.
88
89       A common use for a background mask is with pamcomp.  You could  replace
90       the  entire  background  (or  foreground)  of your image with something
91       else.
92
93       Another common use is to make an image with the background  transparent
94       (in some image format that has a concept of transparency) so that image
95       can be overlaid onto another image later.  Netpbm's converters to image
96       formats  that  have  transparency  (e.g. PNG) let you use the mask that
97       pambackground generates to identify the transparent areas for the  out‐
98       put.  You can create a PAM image with transparency with pamstack.
99
100       To  simply  make a mask of all the areas of a specified color, use ppm‐
101       colormask.  If you have a unique background color (one that doesn't oc‐
102       cur  in  the  foreground)  and know what it is, this can create a back‐
103       ground mask in cases that pambackground cannot: where  there  are  see-
104       through holes in the foreground image.
105
106
107

OPTIONS

109       In  addition  to  the options common to all programs based on libnetpbm
110       (most notably -quiet, see
111        Common Options ⟨index.html#commonoptions⟩ ), pambackground  recognizes
112       the following command line option:
113
114
115
116
117       -verbose
118              Tell interesting facts about the process.
119
120
121
122

EXAMPLES

124           $ pambackground test.ppm | pnminvert >/tmp/bgmask.pgm
125           $ pamcomp -alpha=bgmask.pgm test.ppm wallpaper.ppm >output.ppm
126
127           $ pnmquant 5 test.pgm | pambackground test.ppm >/tmp/bgmask.pam
128
129
130
131

SEE ALSO

133       ppmcolormask(1),  pamcomp(1),  ppmchange(1),  pnmquant(1), pnmremap(1),
134       pamtopnm(1),  pgmtopgm(1),  pamstack(1),  pamgetcolor(1),  pbmmaskd(1),
135       pnm(1), pam(1),
136
137

HISTORY

139       pambackground was new in Netpbm 10.37 (December 2006).
140

DOCUMENT SOURCE

142       This  manual  page was generated by the Netpbm tool 'makeman' from HTML
143       source.  The master documentation is at
144
145              http://netpbm.sourceforge.net/doc/pambackground.html
146
147netpbm documentation           24 November 2014   Pambackground User Manual(0)
Impressum