1 /* base class for all morphological operations
2 *
3 * properties:
4 * - one input image
5 */
6
7 /*
8
9 Copyright (C) 1991-2005 The National Gallery
10
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Lesser General Public
13 License as published by the Free Software Foundation; either
14 version 2.1 of the License, or (at your option) any later version.
15
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
20
21 You should have received a copy of the GNU Lesser General Public
22 License along with this library; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 02110-1301 USA
25
26 */
27
28 /*
29
30 These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
31
32 */
33
34 /*
35 #define DEBUG
36 */
37
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif /*HAVE_CONFIG_H*/
41 #include <vips/intl.h>
42
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <math.h>
46
47 #include <vips/vips.h>
48 #include <vips/internal.h>
49
50 #include "pmorphology.h"
51
52 /**
53 * SECTION: morphology
54 * @short_description: morphological operators, rank filters and related image
55 * analysis
56 * @see_also: <link linkend="libvips-arithmetic">arithmetic</link>
57 * @stability: Stable
58 * @include: vips/vips.h
59 *
60 * The morphological functions search images
61 * for particular patterns of pixels, specified with the mask argument,
62 * either adding or removing pixels when they find a match. They are useful
63 * for cleaning up images --- for example, you might threshold an image, and
64 * then use one of the morphological functions to remove all single isolated
65 * pixels from the result.
66 *
67 * If you combine the morphological operators with the mask rotators
68 * (vips_rot45(), for example) and apply them repeatedly, you
69 * can achieve very complicated effects: you can thin, prune, fill, open edges,
70 * close gaps, and many others. For example, see `Fundamentals of Digital
71 * Image Processing' by A. Jain, pp 384-388, Prentice-Hall, 1989 for more
72 * ideas.
73 *
74 * Beware that VIPS reverses the usual image processing convention, by
75 * assuming white objects (non-zero pixels) on a black background (zero
76 * pixels).
77 *
78 * The mask you give to the morphological functions should contain only the
79 * values 0 (for background), 128 (for don't care) and 255 (for object). The
80 * mask must have odd length sides --- the origin of the mask is taken to be
81 * the centre value. For example, the mask:
82 *
83 * 3 3
84 * 128 255 128
85 * 255 0 255
86 * 128 255 128
87 *
88 * applied to an image with vips_morph() #VIPS_OPERATION_MORPHOLOGY_ERODE, will
89 * find all black pixels
90 * 4-way connected with white pixels. Essentially, dilate
91 * sets pixels in the output if any part of the mask matches, whereas
92 * erode sets pixels only if all of the mask matches.
93 *
94 * See vips_andimage(), vips_orimage() and vips_eorimage()
95 * for analogues of the usual set difference and set union operations.
96 */
97
98 G_DEFINE_ABSTRACT_TYPE( VipsMorphology, vips_morphology,
99 VIPS_TYPE_OPERATION );
100
101 static void
vips_morphology_class_init(VipsMorphologyClass * class)102 vips_morphology_class_init( VipsMorphologyClass *class )
103 {
104 GObjectClass *gobject_class = G_OBJECT_CLASS( class );
105 VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class );
106
107 gobject_class->set_property = vips_object_set_property;
108 gobject_class->get_property = vips_object_get_property;
109
110 vobject_class->nickname = "morphology";
111 vobject_class->description = _( "morphological operations" );
112
113 /* Inputs set by subclassess.
114 */
115
116 VIPS_ARG_IMAGE( class, "in", 0,
117 _( "Input" ),
118 _( "Input image argument" ),
119 VIPS_ARGUMENT_REQUIRED_INPUT,
120 G_STRUCT_OFFSET( VipsMorphology, in ) );
121
122 }
123
124 static void
vips_morphology_init(VipsMorphology * morphology)125 vips_morphology_init( VipsMorphology *morphology )
126 {
127 }
128
129 /* Called from iofuncs to init all operations in this dir. Use a plugin system
130 * instead?
131 */
132 void
vips_morphology_operation_init(void)133 vips_morphology_operation_init( void )
134 {
135 extern GType vips_morph_get_type( void );
136 extern GType vips_rank_get_type( void );
137 extern GType vips_countlines_get_type( void );
138 extern GType vips_labelregions_get_type( void );
139 extern GType vips_fill_nearest_get_type( void );
140
141 vips_morph_get_type();
142 vips_rank_get_type();
143 vips_countlines_get_type();
144 vips_labelregions_get_type();
145 vips_fill_nearest_get_type();
146 }
147