File: hough.c

package info (click to toggle)
vips 8.16.1-2
  • links: PTS
  • area: main
  • in suites: sid
  • size: 51,940 kB
  • sloc: ansic: 169,179; cpp: 11,890; python: 4,620; xml: 4,353; sh: 732; perl: 40; makefile: 19
file content (188 lines) | stat: -rw-r--r-- 4,365 bytes parent folder | download | duplicates (2)
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
/* hough transform
 *
 * 7/3/14
 * 	- from hist_find.c
 */

/*

	This file is part of VIPS.

	VIPS is free software; you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
	02110-1301  USA

 */

/*

	These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk

 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <glib/gi18n-lib.h>

#include <string.h>

#include <vips/vips.h>

#include "statistic.h"
#include "hough.h"

G_DEFINE_ABSTRACT_TYPE(VipsHough, vips_hough, VIPS_TYPE_STATISTIC);

static VipsImage *
vips_hough_new_accumulator(VipsHough *hough)
{
	VipsHoughClass *class = VIPS_HOUGH_GET_CLASS(hough);
	VipsStatistic *statistic = VIPS_STATISTIC(hough);

	VipsImage *accumulator;

	accumulator = vips_image_new_memory();

	if (vips_image_pipelinev(accumulator,
			VIPS_DEMAND_STYLE_ANY, statistic->ready, NULL) ||
		class->init_accumulator(hough, accumulator) ||
		vips_image_write_prepare(accumulator)) {
		g_object_unref(accumulator);
		return NULL;
	}

	return accumulator;
}

static int
vips_hough_build(VipsObject *object)
{
	VipsObjectClass *class = VIPS_OBJECT_GET_CLASS(object);
	VipsStatistic *statistic = VIPS_STATISTIC(object);
	VipsHough *hough = (VipsHough *) object;

	VipsImage *out;

	/* Mono only, we use the bands dimension of the output image for
	 * a parameter.
	 */
	if (statistic->in)
		if (vips_check_mono(class->nickname, statistic->in))
			return -1;

	if (!(out = vips_hough_new_accumulator(hough)))
		return -1;
	g_object_set(object,
		"out", out,
		NULL);

	if (VIPS_OBJECT_CLASS(vips_hough_parent_class)->build(object))
		return -1;

	return 0;
}

/* Build a new accumulator.
 */
static void *
vips_hough_start(VipsStatistic *statistic)
{
	VipsHough *hough = (VipsHough *) statistic;

	VipsImage *accumulator;

	if (!(accumulator = vips_hough_new_accumulator(hough)))
		return NULL;

	return (void *) accumulator;
}

/* Add our finished accumulator to the main area.
 */
static int
vips_hough_stop(VipsStatistic *statistic, void *seq)
{
	VipsImage *accumulator = (VipsImage *) seq;
	VipsHough *hough = (VipsHough *) statistic;

	if (vips_draw_image(hough->out, accumulator, 0, 0,
			"mode", VIPS_COMBINE_MODE_ADD,
			NULL)) {
		g_object_unref(accumulator);
		return -1;
	}

	g_object_unref(accumulator);

	return 0;
}

static int
vips_hough_scan(VipsStatistic *statistic,
	void *seq, int x, int y, void *in, int n)
{
	VipsHough *hough = (VipsHough *) statistic;
	VipsHoughClass *class = VIPS_HOUGH_GET_CLASS(hough);
	VipsImage *accumulator = (VipsImage *) seq;
	VipsPel *p = (VipsPel *) in;

	int i;

	for (i = 0; i < n; i++)
		if (p[i])
			class->vote(hough, accumulator, x + i, y);

	return 0;
}

#define UC VIPS_FORMAT_UCHAR

/* Input image is cast to this format.
 */
static const VipsBandFormat vips_hough_format_table[10] = {
	/* Band format:  UC  C   US  S   UI  I   F   X   D   DX */
	/* Promotion: */ UC, UC, UC, UC, UC, UC, UC, UC, UC, UC
};

static void
vips_hough_class_init(VipsHoughClass *class)
{
	GObjectClass *gobject_class = (GObjectClass *) class;
	VipsObjectClass *object_class = (VipsObjectClass *) class;
	VipsStatisticClass *sclass = VIPS_STATISTIC_CLASS(class);

	gobject_class->set_property = vips_object_set_property;
	gobject_class->get_property = vips_object_get_property;

	object_class->nickname = "hough";
	object_class->description = _("find hough transform");
	object_class->build = vips_hough_build;

	sclass->start = vips_hough_start;
	sclass->scan = vips_hough_scan;
	sclass->stop = vips_hough_stop;
	sclass->format_table = vips_hough_format_table;

	VIPS_ARG_IMAGE(class, "out", 100,
		_("Output"),
		_("Output image"),
		VIPS_ARGUMENT_REQUIRED_OUTPUT,
		G_STRUCT_OFFSET(VipsHough, out));
}

static void
vips_hough_init(VipsHough *hough)
{
}