1.. index:: ! grdmix
2.. include:: module_core_purpose.rst_
3
4******
5grdmix
6******
7
8|grdmix_purpose|
9
10Synopsis
11--------
12
13.. include:: common_SYN_OPTs.rst_
14
15**gmt grdmix**
16*raster1* [ *raster2* [ *raster3*]]
17|-G|\ *outfile*
18[ |-A|\ *alpha* ]
19[ |-C| ]
20[ |-D| ]
21[ |-I|\ *intensity* ]
22[ |-M| ]
23[ |-N|\ [**i**\|\ **o**][*divisor*] ]
24[ |-Q| ]
25[ |SYN_OPT-R| ]
26[ |SYN_OPT-V| ]
27[ |-W|\ *weights* ]
28[ |SYN_OPT-f| ]
29[ |SYN_OPT--| ]
30
31|No-spaces|
32
33Description
34-----------
35
36**grdmix** will perform various operations involving images and grids.
37We either use an *alpha* grid, image, or constant to add a new alpha
38(transparency) layer to the image given as *raster1*, or we will blend
39the two *raster1* and *raster2* (grids or images) using the *weights* for
40*raster1* and the complementary *1 - weights* for *raster2* and save to
41*outfile*. Alternatively, we will deconstruct an image into its component
42(red, green, blue or gray) grid layers or we construct an image from its
43normalized component grids.
44All operations support adjusting the final color image via an *intensity*
45grid, converting a color image to monochrome, or strip off the alpha layer.
46All *raster?*, *alpha*, *intensity* and *weights* files must have the same
47dimensions. The optional *alpha*, *intensity* and *weights* files may be
48replaced by constant values instead.
49
50Required Arguments
51------------------
52
53*raster?*
54    If only one is given and **-C** is not set then *raster1* must be an image.
55    If two are given then *raster1* and *raster2* must both be either
56    images or grids.  If three are given then they must all be grids and
57    **-C** must be set.
58
59.. _-G:
60
61**-G**\ *outfile*
62    The name for the output raster.  For images, use one of these extensions:
63    tif (GeoTIFF), gif, png, jpg, bmp, or ppm. For grids, see
64    :ref:`Grid File Formats <grd_inout_full>`.
65
66Optional Arguments
67------------------
68
69.. _-A:
70
71**-A**\ *alpha*
72    Get a constant alpha (0-1), or a grid (0-1) or image (0-255) with alphas.
73    The final image will have a transparency layer add based on these values.
74
75.. _-C:
76
77**-C**
78    **C**\ onstruct an output image from one or three normalized input grids;
79    these grids must all have values in the 0-1 range only (see **-Ni** if they don't).
80    Optionally, use **-A** to add transparency and **-I** to add intensity
81    to the colors before writing the image. For three layers the input order must
82    be red grid first, then the green grid, and finally the blue grid.
83
84.. _-D:
85
86**-D**
87    **D**\ econstruct a single image into one or three output grids.
88    An extra grid will be written if the image contains an alpha (transparency layer).
89    All grids written will reflect the original image values in the 0-255 range exclusively;
90    however, you can use **-No** to normalize the values to the 0-1 range.
91    The output names uses the name template given by **-G** which must contain the
92    C-format string "%c".  This code is replaced by the codes R, G, B and A for color
93    images and g, A for gray-scale images.
94
95.. _-I:
96
97**-I**\ *intensity*
98    A constant intensity or grid (-1 to +1 range) to modify final output image colors.
99
100.. _-M:
101
102**-M**
103    Force conversion to monochrome image using the (television) YIQ
104    transformation.
105
106.. _-N:
107
108**-N**\ [**i**\|\ **o**][*divisor*]
109    Normalize all input grids from 0-255 to 0-1 and all output grids from 0-1 to 0-255.
110    To only turn on normalization for input *or* output, use **-Ni** or **-No** instead.
111    To divide by another value than 255, append an optional *divisor*.
112
113.. _-Q:
114
115**-Q**
116    Make the final image opaque by removing the alpha layer (if present).
117
118.. |Add_-R| replace:: |Add_-R_links|
119.. include:: explain_-R.rst_
120    :start-after: **Syntax**
121    :end-before: **Description**
122
123.. |Add_-V| replace:: |Add_-V_links|
124.. include:: explain_-V.rst_
125    :start-after: **Syntax**
126    :end-before: **Description**
127
128.. _-W:
129
130**-W**\ *weights*
131    A constant weight (0-1), or a grid (0-1) or image (0-255) with weights.
132    When two input rasters are given, the weights are applied to *raster1* and
133    (*1-weights*) are applied to *raster2*, then the products are summed.
134
135.. |Add_-f| unicode:: 0x20 .. just an invisible code
136.. include:: explain_-f.rst_
137
138.. include:: explain_help.rst_
139
140Examples
141--------
142
143.. include:: explain_example.rst_
144
145To blend the night and day views of the Earth using a weight image computed for
146a particular day/night terminus, try::
147
148    gmt grdmix @earth_day_06m @earth_night_06m -W@weight.png -Gnewmap.png
149
150Suppose map1.png and map2.png are overlapping maps of different quantities, but we wish
151to use the image visible.png to blend them into a single image: Where visible.png has
152values close to 255 we will see predominantly the map1.png contents while for values
153closer to zero we will mostly see map2.png - values in between these extremes will
154lead to a weighted average.  We try::
155
156    gmt grdmix map1.png map2.png -Wvisible.png -Gnewmap.png -V
157
158To insert the values from the grid transparency.grd into the image gravity.tif as an alpha
159(transparency) layer, and write out a transparent PNG image, try::
160
161    gmt grdmix gravity.tif -Atransparency.grd -Gmap.png
162
163To break the color image layers.png into separate, normalized red, green, and blue grids (and possibly an alpha grid),
164we run::
165
166    gmt grdmix layers.png -D -Glayer_%c.grd -No
167
168To recombine the three normalized grids red.grd, green.grd, and blue.grd into a TIFF file, but
169applying intensities from intens.grd and add transparency from transp.grd grids, try::
170
171    gmt grdmix red.grd green.grd and blue.grd -Glayer.tif -Atransp.grd -Iintens.grd
172
173
174See Also
175--------
176
177:doc:`gmt`, :doc:`grdblend`,
178:doc:`grdclip`,
179:doc:`grdcut`,
180:doc:`grdinfo`,
181:doc:`grdsample`
182