34
31
<p>morphology — morphological operators, rank filters and related image
37
<td valign="top" align="right"></td>
34
<td class="gallery_image" valign="top" align="right"></td>
38
35
</tr></table></div>
39
36
<div class="refsect1">
40
37
<a name="libvips-morphology.stability-level"></a><h2>Stability Level</h2>
41
38
Stable, unless otherwise indicated
43
<div class="refsynopsisdiv">
44
<a name="libvips-morphology.synopsis"></a><h2>Synopsis</h2>
45
<pre class="synopsis">
46
#include <vips/vips.h>
48
enum <a class="link" href="libvips-morphology.html#VipsOperationMorphology" title="enum VipsOperationMorphology">VipsOperationMorphology</a>;
49
<span class="returnvalue">int</span> <a class="link" href="libvips-morphology.html#vips-morph" title="vips_morph ()">vips_morph</a> (<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> *in</code></em>,
50
<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> **out</code></em>,
51
<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> *mask</code></em>,
52
<em class="parameter"><code><a class="link" href="libvips-morphology.html#VipsOperationMorphology" title="enum VipsOperationMorphology"><span class="type">VipsOperationMorphology</span></a> morph</code></em>,
53
<em class="parameter"><code>...</code></em>);
54
<span class="returnvalue">int</span> <a class="link" href="libvips-morphology.html#vips-rank" title="vips_rank ()">vips_rank</a> (<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> *in</code></em>,
55
<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> **out</code></em>,
56
<em class="parameter"><code><span class="type">int</span> width</code></em>,
57
<em class="parameter"><code><span class="type">int</span> height</code></em>,
58
<em class="parameter"><code><span class="type">int</span> index</code></em>,
59
<em class="parameter"><code>...</code></em>);
60
<span class="returnvalue">int</span> <a class="link" href="libvips-morphology.html#vips-countlines" title="vips_countlines ()">vips_countlines</a> (<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> *in</code></em>,
61
<em class="parameter"><code><span class="type">double</span> *nolines</code></em>,
62
<em class="parameter"><code><a class="link" href="libvips-conversion.html#VipsDirection" title="enum VipsDirection"><span class="type">VipsDirection</span></a> direction</code></em>,
63
<em class="parameter"><code>...</code></em>);
64
<span class="returnvalue">int</span> <a class="link" href="libvips-morphology.html#vips-median" title="vips_median ()">vips_median</a> (<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> *in</code></em>,
65
<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> **out</code></em>,
66
<em class="parameter"><code><span class="type">int</span> size</code></em>,
67
<em class="parameter"><code>...</code></em>);
68
<span class="returnvalue">int</span> <a class="link" href="libvips-morphology.html#im-label-regions" title="im_label_regions ()">im_label_regions</a> (<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> *test</code></em>,
69
<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> *mask</code></em>,
70
<em class="parameter"><code><span class="type">int</span> *segments</code></em>);
40
<div class="refsect1">
41
<a name="libvips-morphology.functions"></a><h2>Functions</h2>
42
<div class="informaltable"><table width="100%" border="0">
44
<col width="150px" class="functions_return">
45
<col class="functions_name">
49
<td class="function_type">
50
<span class="returnvalue">int</span>
52
<td class="function_name">
53
<a class="link" href="libvips-morphology.html#vips-morph" title="vips_morph ()">vips_morph</a> <span class="c_punctuation">()</span>
57
<td class="function_type">
58
<span class="returnvalue">int</span>
60
<td class="function_name">
61
<a class="link" href="libvips-morphology.html#vips-rank" title="vips_rank ()">vips_rank</a> <span class="c_punctuation">()</span>
65
<td class="function_type">
66
<span class="returnvalue">int</span>
68
<td class="function_name">
69
<a class="link" href="libvips-morphology.html#vips-countlines" title="vips_countlines ()">vips_countlines</a> <span class="c_punctuation">()</span>
73
<td class="function_type">
74
<span class="returnvalue">int</span>
76
<td class="function_name">
77
<a class="link" href="libvips-morphology.html#vips-median" title="vips_median ()">vips_median</a> <span class="c_punctuation">()</span>
81
<td class="function_type">
82
<span class="returnvalue">int</span>
84
<td class="function_name">
85
<a class="link" href="libvips-morphology.html#im-label-regions" title="im_label_regions ()">im_label_regions</a> <span class="c_punctuation">()</span>
91
<div class="refsect1">
92
<a name="libvips-morphology.other"></a><h2>Types and Values</h2>
93
<div class="informaltable"><table width="100%" border="0">
95
<col width="150px" class="name">
96
<col class="description">
99
<td class="datatype_keyword">enum</td>
100
<td class="function_name"><a class="link" href="libvips-morphology.html#VipsOperationMorphology" title="enum VipsOperationMorphology">VipsOperationMorphology</a></td>
104
<div class="refsect1">
105
<a name="libvips-morphology.object-hierarchy"></a><h2>Object Hierarchy</h2>
109
<div class="refsect1">
110
<a name="libvips-morphology.includes"></a><h2>Includes</h2>
111
<pre class="synopsis">#include <vips/vips.h>
73
114
<div class="refsect1">
74
115
<a name="libvips-morphology.description"></a><h2>Description</h2>
76
The morphological functions search images
116
<p>The morphological functions search images
77
117
for particular patterns of pixels, specified with the mask argument,
78
118
either adding or removing pixels when they find a match. They are useful
79
119
for cleaning up images --- for example, you might threshold an image, and
80
120
then use one of the morphological functions to remove all single isolated
81
pixels from the result.
84
If you combine the morphological operators with the mask rotators
85
<a href="http://http://www.vips.ecs.soton.ac.uk/libvips-mask.html#im-rotate-imask45"><code class="function">im_rotate_imask45()</code></a>, for example) and apply them repeatedly, you
121
pixels from the result.</p>
122
<p>If you combine the morphological operators with the mask rotators
123
<code class="function">im_rotate_imask45()</code>, for example) and apply them repeatedly, you
86
124
can achieve very complicated effects: you can thin, prune, fill, open edges,
87
125
close gaps, and many others. For example, see `Fundamentals of Digital
88
126
Image Processing' by A. Jain, pp 384-388, Prentice-Hall, 1989 for more
92
Beware that VIPS reverses the usual image processing convention, by
128
<p>Beware that VIPS reverses the usual image processing convention, by
93
129
assuming white objects (non-zero pixels) on a black background (zero
97
The mask you give to the morphological functions should contain only the
131
<p>The mask you give to the morphological functions should contain only the
98
132
values 0 (for background), 128 (for don't care) and 255 (for object). The
99
133
mask must have odd length sides --- the origin of the mask is taken to be
100
the centre value. For example, the mask:
134
the centre value. For example, the mask:</p>
109
applied to an image with <a href="http://http://www.vips.ecs.soton.ac.uk/libvips-morphology.html#im-erode"><code class="function">im_erode()</code></a>, will find all black pixels
110
4-way connected with white pixels. Essentially, <a href="http://http://www.vips.ecs.soton.ac.uk/libvips-morphology.html#im-dilate"><code class="function">im_dilate()</code></a>
139
<p>applied to an image with <code class="function">im_erode()</code>, will find all black pixels
140
4-way connected with white pixels. Essentially, <code class="function">im_dilate()</code>
111
141
sets pixels in the output if any part of the mask matches, whereas
112
<a href="http://http://www.vips.ecs.soton.ac.uk/libvips-morphology.html#im-erode"><code class="function">im_erode()</code></a> sets pixels only if all of the mask matches.
115
See <code class="function">im_andimage()</code>, <code class="function">im_orimage()</code> and <code class="function">im_eorimage()</code>
116
for analogues of the usual set difference and set union operations.
142
<code class="function">im_erode()</code> sets pixels only if all of the mask matches.</p>
143
<p>See <code class="function">im_andimage()</code>, <code class="function">im_orimage()</code> and <code class="function">im_eorimage()</code>
144
for analogues of the usual set difference and set union operations.</p>
119
146
<div class="refsect1">
120
<a name="libvips-morphology.details"></a><h2>Details</h2>
121
<div class="refsect2">
122
<a name="VipsOperationMorphology"></a><h3>enum VipsOperationMorphology</h3>
123
<pre class="programlisting">typedef enum {
124
VIPS_OPERATION_MORPHOLOGY_ERODE,
125
VIPS_OPERATION_MORPHOLOGY_DILATE,
126
VIPS_OPERATION_MORPHOLOGY_LAST
127
} VipsOperationMorphology;
130
More like hit-miss, really.
133
See also: <a class="link" href="libvips-morphology.html#vips-morph" title="vips_morph ()"><code class="function">vips_morph()</code></a>.
135
<div class="variablelist"><table border="0" class="variablelist">
137
<col align="left" valign="top">
142
<td><p><a name="VIPS-OPERATION-MORPHOLOGY-ERODE:CAPS"></a><span class="term"><code class="literal">VIPS_OPERATION_MORPHOLOGY_ERODE</code></span></p></td>
147
<td><p><a name="VIPS-OPERATION-MORPHOLOGY-DILATE:CAPS"></a><span class="term"><code class="literal">VIPS_OPERATION_MORPHOLOGY_DILATE</code></span></p></td>
152
<td><p><a name="VIPS-OPERATION-MORPHOLOGY-LAST:CAPS"></a><span class="term"><code class="literal">VIPS_OPERATION_MORPHOLOGY_LAST</code></span></p></td>
160
<div class="refsect2">
161
<a name="vips-morph"></a><h3>vips_morph ()</h3>
162
<pre class="programlisting"><span class="returnvalue">int</span> vips_morph (<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> *in</code></em>,
163
<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> **out</code></em>,
164
<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> *mask</code></em>,
165
<em class="parameter"><code><a class="link" href="libvips-morphology.html#VipsOperationMorphology" title="enum VipsOperationMorphology"><span class="type">VipsOperationMorphology</span></a> morph</code></em>,
166
<em class="parameter"><code>...</code></em>);</pre>
168
Performs a morphological operation on <em class="parameter"><code>in</code></em> using <em class="parameter"><code>mask</code></em> as a
172
The image should have 0 (black) for no object and 255
147
<a name="libvips-morphology.functions_details"></a><h2>Functions</h2>
148
<div class="refsect2">
149
<a name="vips-morph"></a><h3>vips_morph ()</h3>
150
<pre class="programlisting"><span class="returnvalue">int</span>
151
vips_morph (<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> *in</code></em>,
152
<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> **out</code></em>,
153
<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> *mask</code></em>,
154
<em class="parameter"><code><a class="link" href="libvips-morphology.html#VipsOperationMorphology" title="enum VipsOperationMorphology"><span class="type">VipsOperationMorphology</span></a> morph</code></em>,
155
<em class="parameter"><code>...</code></em>);</pre>
156
<p>Performs a morphological operation on <em class="parameter"><code>in</code></em>
157
using <em class="parameter"><code>mask</code></em>
159
structuring element. </p>
160
<p>The image should have 0 (black) for no object and 255
173
161
(non-zero) for an object. Note that this is the reverse of the usual
174
162
convention for these operations, but more convenient when combined with the
175
163
boolean operators. The output image is the same
176
164
size as the input image: edge pxels are made by expanding the input image
180
Mask coefficients can be either 0 (for object) or 255 (for background)
166
<p>Mask coefficients can be either 0 (for object) or 255 (for background)
181
167
or 128 (for do not care). The origin of the mask is at location
182
168
(m.xsize / 2, m.ysize / 2), integer division. All algorithms have been
183
169
based on the book "Fundamentals of Digital Image Processing" by A. Jain,
184
pp 384-388, Prentice-Hall, 1989.
187
For <span class="type">VIPS_OPERATION_MOPHOLOGY_ERODE</span>,
170
pp 384-388, Prentice-Hall, 1989. </p>
171
<p>For <span class="type">VIPS_OPERATION_MOPHOLOGY_ERODE</span>,
188
172
the whole mask must match for the output pixel to be
189
set, that is, the result is the logical AND of the selected input pixels.
192
For <span class="type">VIPS_OPERATION_MOPHOLOGY_DILATE</span>,
173
set, that is, the result is the logical AND of the selected input pixels.</p>
174
<p>For <span class="type">VIPS_OPERATION_MOPHOLOGY_DILATE</span>,
193
175
the output pixel is set if any part of the mask
194
matches, that is, the result is the logical OR of the selected input pixels.
197
See the boolean operations <a class="link" href="libvips-arithmetic.html#vips-andimage" title="vips_andimage ()"><code class="function">vips_andimage()</code></a>, <a class="link" href="libvips-arithmetic.html#vips-orimage" title="vips_orimage ()"><code class="function">vips_orimage()</code></a> and
198
<a class="link" href="libvips-arithmetic.html#vips-eorimage" title="vips_eorimage ()"><code class="function">vips_eorimage()</code></a>
199
for analogues of the usual set difference and set union operations.
202
Operations are performed using the processor's vector unit,
203
if possible. Disable this with --vips-novector or IM_NOVECTOR.
205
<div class="variablelist"><table border="0" class="variablelist">
176
matches, that is, the result is the logical OR of the selected input pixels.</p>
177
<p>See the boolean operations <a class="link" href="libvips-arithmetic.html#vips-andimage" title="vips_andimage ()"><code class="function">vips_andimage()</code></a>, <a class="link" href="libvips-arithmetic.html#vips-orimage" title="vips_orimage ()"><code class="function">vips_orimage()</code></a> and
178
<a class="link" href="libvips-arithmetic.html#vips-eorimage" title="vips_eorimage ()"><code class="function">vips_eorimage()</code></a>
179
for analogues of the usual set difference and set union operations.</p>
180
<p>Operations are performed using the processor's vector unit,
181
if possible. Disable this with --vips-novector or IM_NOVECTOR.</p>
182
<div class="refsect3">
183
<a name="id-1.3.11.9.2.11"></a><h4>Parameters</h4>
184
<div class="informaltable"><table width="100%" border="0">
207
<col align="left" valign="top">
186
<col width="150px" class="parameters_name">
187
<col class="parameters_description">
188
<col width="200px" class="parameters_annotations">
212
<td><p><span class="term"><em class="parameter"><code>in</code></em> :</span></p></td>
216
<td><p><span class="term"><em class="parameter"><code>out</code></em> :</span></p></td>
217
<td>output image</td>
220
<td><p><span class="term"><em class="parameter"><code>mask</code></em> :</span></p></td>
221
<td>morphology with this mask</td>
224
<td><p><span class="term"><em class="parameter"><code>morph</code></em> :</span></p></td>
225
<td>operation to perform</td>
228
<td><p><span class="term"><em class="parameter"><code>...</code></em> :</span></p></td>
230
<code class="literal">NULL</code>-terminated list of optional named arguments</td>
233
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
234
<td>0 on success, -1 on error</td>
192
<td class="parameter_name"><p>in</p></td>
193
<td class="parameter_description"><p>input image</p></td>
194
<td class="parameter_annotations"> </td>
197
<td class="parameter_name"><p>out</p></td>
198
<td class="parameter_description"><p>output image</p></td>
199
<td class="parameter_annotations"> </td>
202
<td class="parameter_name"><p>mask</p></td>
203
<td class="parameter_description"><p>morphology with this mask</p></td>
204
<td class="parameter_annotations"> </td>
207
<td class="parameter_name"><p>morph</p></td>
208
<td class="parameter_description"><p>operation to perform</p></td>
209
<td class="parameter_annotations"> </td>
212
<td class="parameter_name"><p>...</p></td>
213
<td class="parameter_description"><p><a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>-terminated list of optional named arguments</p></td>
214
<td class="parameter_annotations"> </td>
219
<div class="refsect3">
220
<a name="id-1.3.11.9.2.12"></a><h4>Returns</h4>
221
<p> 0 on success, -1 on error</p>
240
226
<div class="refsect2">
241
<a name="vips-rank"></a><h3>vips_rank ()</h3>
242
<pre class="programlisting"><span class="returnvalue">int</span> vips_rank (<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> *in</code></em>,
243
<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> **out</code></em>,
244
<em class="parameter"><code><span class="type">int</span> width</code></em>,
245
<em class="parameter"><code><span class="type">int</span> height</code></em>,
246
<em class="parameter"><code><span class="type">int</span> index</code></em>,
247
<em class="parameter"><code>...</code></em>);</pre>
249
<a class="link" href="libvips-morphology.html#vips-rank" title="vips_rank ()"><code class="function">vips_rank()</code></a> does rank filtering on an image. A window of size <em class="parameter"><code>width</code></em> by
250
<em class="parameter"><code>height</code></em> is passed over the image. At each position, the pixels inside the
251
window are sorted into ascending order and the pixel at position <em class="parameter"><code>index</code></em> is
252
output. <em class="parameter"><code>index</code></em> numbers from 0.
255
It works for any non-complex image type, with any number of bands.
227
<a name="vips-rank"></a><h3>vips_rank ()</h3>
228
<pre class="programlisting"><span class="returnvalue">int</span>
229
vips_rank (<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> *in</code></em>,
230
<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> **out</code></em>,
231
<em class="parameter"><code><span class="type">int</span> width</code></em>,
232
<em class="parameter"><code><span class="type">int</span> height</code></em>,
233
<em class="parameter"><code><span class="type">int</span> index</code></em>,
234
<em class="parameter"><code>...</code></em>);</pre>
235
<p>vips_rank() does rank filtering on an image. A window of size <em class="parameter"><code>width</code></em>
237
<em class="parameter"><code>height</code></em>
238
is passed over the image. At each position, the pixels inside the
239
window are sorted into ascending order and the pixel at position <em class="parameter"><code>index</code></em>
241
output. <em class="parameter"><code>index</code></em>
243
<p>It works for any non-complex image type, with any number of bands.
256
244
The input is expanded by copying edge pixels before performing the
257
245
operation so that the output image has the same size as the input.
258
Edge pixels in the output image are therefore only approximate.
261
For a median filter with mask size m (3 for 3x3, 5 for 5x5, etc.) use
264
vips_rank( in, out, m, m, m * m / 2 );
267
The special cases n == 0 and n == m * m - 1 are useful dilate and
271
See also: <a class="link" href="libvips-convolution.html#vips-conv" title="vips_conv ()"><code class="function">vips_conv()</code></a>, <a class="link" href="libvips-morphology.html#vips-median" title="vips_median ()"><code class="function">vips_median()</code></a>, <code class="function">vips_spcor()</code>.
273
<div class="variablelist"><table border="0" class="variablelist">
246
Edge pixels in the output image are therefore only approximate.</p>
247
<p>For a median filter with mask size m (3 for 3x3, 5 for 5x5, etc.) use</p>
248
<p> vips_rank( in, out, m, m, m * m / 2 );</p>
249
<p>The special cases n == 0 and n == m * m - 1 are useful dilate and
250
expand operators.</p>
251
<p>See also: <a class="link" href="libvips-convolution.html#vips-conv" title="vips_conv ()"><code class="function">vips_conv()</code></a>, <a class="link" href="libvips-morphology.html#vips-median" title="vips_median ()"><code class="function">vips_median()</code></a>, <code class="function">vips_spcor()</code>.</p>
252
<div class="refsect3">
253
<a name="id-1.3.11.9.3.10"></a><h4>Parameters</h4>
254
<div class="informaltable"><table width="100%" border="0">
275
<col align="left" valign="top">
256
<col width="150px" class="parameters_name">
257
<col class="parameters_description">
258
<col width="200px" class="parameters_annotations">
280
<td><p><span class="term"><em class="parameter"><code>in</code></em> :</span></p></td>
284
<td><p><span class="term"><em class="parameter"><code>out</code></em> :</span></p></td>
285
<td>output image</td>
288
<td><p><span class="term"><em class="parameter"><code>width</code></em> :</span></p></td>
289
<td>width of region</td>
292
<td><p><span class="term"><em class="parameter"><code>height</code></em> :</span></p></td>
293
<td>height of region</td>
296
<td><p><span class="term"><em class="parameter"><code>index</code></em> :</span></p></td>
297
<td>select pixel</td>
300
<td><p><span class="term"><em class="parameter"><code>...</code></em> :</span></p></td>
302
<code class="literal">NULL</code>-terminated list of optional named arguments</td>
305
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
306
<td>0 on success, -1 on error</td>
262
<td class="parameter_name"><p>in</p></td>
263
<td class="parameter_description"><p>input image</p></td>
264
<td class="parameter_annotations"> </td>
267
<td class="parameter_name"><p>out</p></td>
268
<td class="parameter_description"><p>output image</p></td>
269
<td class="parameter_annotations"> </td>
272
<td class="parameter_name"><p>width</p></td>
273
<td class="parameter_description"><p>width of region</p></td>
274
<td class="parameter_annotations"> </td>
277
<td class="parameter_name"><p>height</p></td>
278
<td class="parameter_description"><p>height of region</p></td>
279
<td class="parameter_annotations"> </td>
282
<td class="parameter_name"><p>index</p></td>
283
<td class="parameter_description"><p>select pixel</p></td>
284
<td class="parameter_annotations"> </td>
287
<td class="parameter_name"><p>...</p></td>
288
<td class="parameter_description"><p><a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>-terminated list of optional named arguments</p></td>
289
<td class="parameter_annotations"> </td>
294
<div class="refsect3">
295
<a name="id-1.3.11.9.3.11"></a><h4>Returns</h4>
296
<p> 0 on success, -1 on error</p>
312
301
<div class="refsect2">
313
<a name="vips-countlines"></a><h3>vips_countlines ()</h3>
314
<pre class="programlisting"><span class="returnvalue">int</span> vips_countlines (<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> *in</code></em>,
315
<em class="parameter"><code><span class="type">double</span> *nolines</code></em>,
316
<em class="parameter"><code><a class="link" href="libvips-conversion.html#VipsDirection" title="enum VipsDirection"><span class="type">VipsDirection</span></a> direction</code></em>,
317
<em class="parameter"><code>...</code></em>);</pre>
319
Function which calculates the number of transitions
302
<a name="vips-countlines"></a><h3>vips_countlines ()</h3>
303
<pre class="programlisting"><span class="returnvalue">int</span>
304
vips_countlines (<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> *in</code></em>,
305
<em class="parameter"><code><span class="type">double</span> *nolines</code></em>,
306
<em class="parameter"><code><a class="link" href="libvips-conversion.html#VipsDirection" title="enum VipsDirection"><span class="type">VipsDirection</span></a> direction</code></em>,
307
<em class="parameter"><code>...</code></em>);</pre>
308
<p>Function which calculates the number of transitions
320
309
between black and white for the horizontal or the vertical
321
310
direction of an image. black<128 , white>=128
322
311
The function calculates the number of transitions for all
323
312
Xsize or Ysize and returns the mean of the result
324
Input should be one band, 8-bit.
327
See also: <a class="link" href="libvips-morphology.html#vips-morph" title="vips_morph ()"><code class="function">vips_morph()</code></a>, <code class="function">vips_zerox()</code>, <a class="link" href="libvips-convolution.html#vips-conv" title="vips_conv ()"><code class="function">vips_conv()</code></a>.
329
<div class="variablelist"><table border="0" class="variablelist">
331
<col align="left" valign="top">
336
<td><p><span class="term"><em class="parameter"><code>in</code></em> :</span></p></td>
340
<td><p><span class="term"><em class="parameter"><code>nolines</code></em> :</span></p></td>
341
<td>output average number of lines</td>
344
<td><p><span class="term"><em class="parameter"><code>direction</code></em> :</span></p></td>
345
<td>count lines horizontally or vertically</td>
348
<td><p><span class="term"><em class="parameter"><code>...</code></em> :</span></p></td>
350
<code class="literal">NULL</code>-terminated list of optional named arguments</td>
353
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
354
<td>0 on success, -1 on error.</td>
360
<div class="refsect2">
361
<a name="vips-median"></a><h3>vips_median ()</h3>
362
<pre class="programlisting"><span class="returnvalue">int</span> vips_median (<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> *in</code></em>,
363
<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> **out</code></em>,
364
<em class="parameter"><code><span class="type">int</span> size</code></em>,
365
<em class="parameter"><code>...</code></em>);</pre>
367
A convenience function equivalent to:
370
vips_rank( in, out, size, size, (size * size) / 2 );
373
See also: <a class="link" href="libvips-morphology.html#vips-rank" title="vips_rank ()"><code class="function">vips_rank()</code></a>.
375
<div class="variablelist"><table border="0" class="variablelist">
377
<col align="left" valign="top">
382
<td><p><span class="term"><em class="parameter"><code>in</code></em> :</span></p></td>
386
<td><p><span class="term"><em class="parameter"><code>out</code></em> :</span></p></td>
387
<td>output image</td>
390
<td><p><span class="term"><em class="parameter"><code>size</code></em> :</span></p></td>
391
<td>size of region</td>
394
<td><p><span class="term"><em class="parameter"><code>...</code></em> :</span></p></td>
396
<code class="literal">NULL</code>-terminated list of optional named arguments</td>
399
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
400
<td>0 on success, -1 on error</td>
406
<div class="refsect2">
407
<a name="im-label-regions"></a><h3>im_label_regions ()</h3>
408
<pre class="programlisting"><span class="returnvalue">int</span> im_label_regions (<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> *test</code></em>,
409
<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> *mask</code></em>,
410
<em class="parameter"><code><span class="type">int</span> *segments</code></em>);</pre>
412
<a class="link" href="libvips-morphology.html#im-label-regions" title="im_label_regions ()"><code class="function">im_label_regions()</code></a> repeatedly scans <em class="parameter"><code>test</code></em> for regions of 4-connected pixels
313
Input should be one band, 8-bit.</p>
314
<p>See also: <a class="link" href="libvips-morphology.html#vips-morph" title="vips_morph ()"><code class="function">vips_morph()</code></a>, <code class="function">vips_zerox()</code>, <a class="link" href="libvips-convolution.html#vips-conv" title="vips_conv ()"><code class="function">vips_conv()</code></a>.</p>
315
<div class="refsect3">
316
<a name="id-1.3.11.9.4.6"></a><h4>Parameters</h4>
317
<div class="informaltable"><table width="100%" border="0">
319
<col width="150px" class="parameters_name">
320
<col class="parameters_description">
321
<col width="200px" class="parameters_annotations">
325
<td class="parameter_name"><p>in</p></td>
326
<td class="parameter_description"><p>input image</p></td>
327
<td class="parameter_annotations"> </td>
330
<td class="parameter_name"><p>nolines</p></td>
331
<td class="parameter_description"><p>output average number of lines</p></td>
332
<td class="parameter_annotations"> </td>
335
<td class="parameter_name"><p>direction</p></td>
336
<td class="parameter_description"><p>count lines horizontally or vertically</p></td>
337
<td class="parameter_annotations"> </td>
340
<td class="parameter_name"><p>...</p></td>
341
<td class="parameter_description"><p><a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>-terminated list of optional named arguments</p></td>
342
<td class="parameter_annotations"> </td>
347
<div class="refsect3">
348
<a name="id-1.3.11.9.4.7"></a><h4>Returns</h4>
349
<p> 0 on success, -1 on error.</p>
354
<div class="refsect2">
355
<a name="vips-median"></a><h3>vips_median ()</h3>
356
<pre class="programlisting"><span class="returnvalue">int</span>
357
vips_median (<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> *in</code></em>,
358
<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> **out</code></em>,
359
<em class="parameter"><code><span class="type">int</span> size</code></em>,
360
<em class="parameter"><code>...</code></em>);</pre>
361
<p>A convenience function equivalent to:</p>
362
<p> vips_rank( in, out, size, size, (size * size) / 2 );</p>
363
<p>See also: <a class="link" href="libvips-morphology.html#vips-rank" title="vips_rank ()"><code class="function">vips_rank()</code></a>.</p>
364
<div class="refsect3">
365
<a name="id-1.3.11.9.5.7"></a><h4>Parameters</h4>
366
<div class="informaltable"><table width="100%" border="0">
368
<col width="150px" class="parameters_name">
369
<col class="parameters_description">
370
<col width="200px" class="parameters_annotations">
374
<td class="parameter_name"><p>in</p></td>
375
<td class="parameter_description"><p>input image</p></td>
376
<td class="parameter_annotations"> </td>
379
<td class="parameter_name"><p>out</p></td>
380
<td class="parameter_description"><p>output image</p></td>
381
<td class="parameter_annotations"> </td>
384
<td class="parameter_name"><p>size</p></td>
385
<td class="parameter_description"><p>size of region</p></td>
386
<td class="parameter_annotations"> </td>
389
<td class="parameter_name"><p>...</p></td>
390
<td class="parameter_description"><p><a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>-terminated list of optional named arguments</p></td>
391
<td class="parameter_annotations"> </td>
396
<div class="refsect3">
397
<a name="id-1.3.11.9.5.8"></a><h4>Returns</h4>
398
<p> 0 on success, -1 on error</p>
403
<div class="refsect2">
404
<a name="im-label-regions"></a><h3>im_label_regions ()</h3>
405
<pre class="programlisting"><span class="returnvalue">int</span>
406
im_label_regions (<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> *test</code></em>,
407
<em class="parameter"><code><a class="link" href="VipsImage.html" title="VipsImage"><span class="type">VipsImage</span></a> *mask</code></em>,
408
<em class="parameter"><code><span class="type">int</span> *segments</code></em>);</pre>
409
<p>im_label_regions() repeatedly scans <em class="parameter"><code>test</code></em>
410
for regions of 4-connected pixels
413
411
with the same pixel value. Every time a region is discovered, those
414
pixels are marked in <em class="parameter"><code>mask</code></em> with a unique serial number. Once all pixels
415
have been labelled, the operation returns, setting <em class="parameter"><code>segments</code></em> to the number
416
of discrete regions which were detected.
419
<em class="parameter"><code>mask</code></em> is always a 1-band <code class="literal">IM_BANDFMT_UINT</code> image of the same dimensions as
420
<em class="parameter"><code>test</code></em>.
423
This operation is useful for, for example, blob counting. You can use the
412
pixels are marked in <em class="parameter"><code>mask</code></em>
413
with a unique serial number. Once all pixels
414
have been labelled, the operation returns, setting <em class="parameter"><code>segments</code></em>
416
of discrete regions which were detected.</p>
417
<p><em class="parameter"><code>mask</code></em>
418
is always a 1-band <code class="literal">IM_BANDFMT_UINT</code> image of the same dimensions as
419
<em class="parameter"><code>test</code></em>
421
<p>This operation is useful for, for example, blob counting. You can use the
424
422
morphological operators to detect and isolate a series of objects, then use
425
<a class="link" href="libvips-morphology.html#im-label-regions" title="im_label_regions ()"><code class="function">im_label_regions()</code></a> to number them all.
428
Use <code class="function">im_histindexed()</code> to (for example) find blob coordinates.
431
See also: <code class="function">im_histindexed()</code>
433
<div class="variablelist"><table border="0" class="variablelist">
435
<col align="left" valign="top">
440
<td><p><span class="term"><em class="parameter"><code>test</code></em> :</span></p></td>
441
<td>image to test</td>
444
<td><p><span class="term"><em class="parameter"><code>mask</code></em> :</span></p></td>
445
<td>write labelled regions here</td>
448
<td><p><span class="term"><em class="parameter"><code>segments</code></em> :</span></p></td>
449
<td>return number of regions here</td>
452
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
453
<td>0 on success, -1 on error.</td>
423
<a class="link" href="libvips-morphology.html#im-label-regions" title="im_label_regions ()"><code class="function">im_label_regions()</code></a> to number them all.</p>
424
<p>Use <code class="function">im_histindexed()</code> to (for example) find blob coordinates.</p>
425
<p>See also: <code class="function">im_histindexed()</code></p>
426
<div class="refsect3">
427
<a name="id-1.3.11.9.6.9"></a><h4>Parameters</h4>
428
<div class="informaltable"><table width="100%" border="0">
430
<col width="150px" class="parameters_name">
431
<col class="parameters_description">
432
<col width="200px" class="parameters_annotations">
436
<td class="parameter_name"><p>test</p></td>
437
<td class="parameter_description"><p>image to test</p></td>
438
<td class="parameter_annotations"> </td>
441
<td class="parameter_name"><p>mask</p></td>
442
<td class="parameter_description"><p>write labelled regions here</p></td>
443
<td class="parameter_annotations"> </td>
446
<td class="parameter_name"><p>segments</p></td>
447
<td class="parameter_description"><p>return number of regions here</p></td>
448
<td class="parameter_annotations"> </td>
453
<div class="refsect3">
454
<a name="id-1.3.11.9.6.10"></a><h4>Returns</h4>
455
<p> 0 on success, -1 on error.</p>
460
<div class="refsect1">
461
<a name="libvips-morphology.other_details"></a><h2>Types and Values</h2>
462
<div class="refsect2">
463
<a name="VipsOperationMorphology"></a><h3>enum VipsOperationMorphology</h3>
464
<p>More like hit-miss, really. </p>
465
<p>See also: <a class="link" href="libvips-morphology.html#vips-morph" title="vips_morph ()"><code class="function">vips_morph()</code></a>.</p>
466
<div class="refsect3">
467
<a name="id-1.3.11.10.2.5"></a><h4>Members</h4>
468
<div class="informaltable"><table width="100%" border="0">
470
<col width="300px" class="enum_members_name">
471
<col class="enum_members_description">
472
<col width="200px" class="enum_members_annotations">
476
<td class="enum_member_name"><p><a name="VIPS-OPERATION-MORPHOLOGY-ERODE:CAPS"></a>VIPS_OPERATION_MORPHOLOGY_ERODE</p></td>
477
<td class="enum_member_description">
478
<p>true if all set</p>
480
<td class="enum_member_annotations"> </td>
483
<td class="enum_member_name"><p><a name="VIPS-OPERATION-MORPHOLOGY-DILATE:CAPS"></a>VIPS_OPERATION_MORPHOLOGY_DILATE</p></td>
484
<td class="enum_member_description">
485
<p>true if one set</p>
487
<td class="enum_member_annotations"> </td>
490
<td class="enum_member_name"><p><a name="VIPS-OPERATION-MORPHOLOGY-LAST:CAPS"></a>VIPS_OPERATION_MORPHOLOGY_LAST</p></td>
491
<td class="enum_member_description"> </td>
492
<td class="enum_member_annotations"> </td>
459
499
<div class="refsect1">