1 /* @(#) Functions which takes an initial estimate of deltax, deltay
2 * @(#) between reference and secondary images (probably from the scanner),
3 * @(#) and looks in three areas of the overlapping part of the reference image
4 * @(#) corresponding to reference and secondary. For every other halfreasize
5 * @(#) point of the three areas of the reference image
6 * @(#) the contrast is calculated
7 * @(#) an area 2*halfcorsize+1 centered at this point
8 * @(#) Results are saved in the structure points
9 * @(#) The function expects the following valid data in points:
10 * @(#) deltax, deltay, nopoints, halfcorsize, halfareasize
11 * @(#) and fills in the memebers:
12 * @(#) x, y_reference[], contrast and x,y_secondary[],
13 * @(#) based on deltax and deltay
14 * @(#) Input image should are either memory mapped or in a buffer.
15 * @(#) To make the calculation faster set FACTOR to 1, 2 or 3
16 * @(#) Calculations are based on bandno only.
17 * @(#) The function uses functions vips__find_best_contrast()
18 * @(#) which is in vips_lrcalcon()
19 * @(#)
20 * @(#) int vips_tbcalcon( ref, sec, bandno, points )
21 * @(#) VipsImage *ref, *sec;
22 * @(#) int bandno;
23 * @(#) TiePoints *points; see mosaic.h
24 * @(#)
25 * @(#) Returns 0 on success and -1 on error.
26 *
27 * Copyright: 1990, N. Dessipris.
28 *
29 * Author: Nicos Dessipris
30 * Written on: 20/12/1990
31 * Modified on : 18/04/1991
32 * 8/7/93 JC
33 * - allow IM_CODING_LABQ coding
34 * - now calls im_incheck()
35 * 12/7/95 JC
36 * - reworked
37 * - what a lot of horrible old code there was too
38 * 18/6/20 kleisauke
39 * - convert to vips8
40 */
41
42 /*
43
44 This file is part of VIPS.
45
46 VIPS is free software; you can redistribute it and/or modify
47 it under the terms of the GNU Lesser General Public License as published by
48 the Free Software Foundation; either version 2 of the License, or
49 (at your option) any later version.
50
51 This program is distributed in the hope that it will be useful,
52 but WITHOUT ANY WARRANTY; without even the implied warranty of
53 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
54 GNU Lesser General Public License for more details.
55
56 You should have received a copy of the GNU Lesser General Public License
57 along with this program; if not, write to the Free Software
58 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
59 02110-1301 USA
60
61 */
62
63 /*
64
65 These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
66
67 */
68
69 #ifdef HAVE_CONFIG_H
70 #include <config.h>
71 #endif /*HAVE_CONFIG_H*/
72 #include <vips/intl.h>
73
74 #include <stdio.h>
75 #include <math.h>
76
77 #include <vips/vips.h>
78 #include <vips/internal.h>
79
80 #include "pmosaicing.h"
81
82 int
vips__tbcalcon(VipsImage * ref,TiePoints * points)83 vips__tbcalcon( VipsImage *ref, TiePoints *points )
84 {
85 /* Geometry: border we must leave around each area.
86 */
87 const int border = points->halfareasize;
88
89 /* Width of an area.
90 */
91 const int awidth = ref->Xsize / AREAS;
92
93 /* Number of points we find in each area.
94 */
95 const int len = points->nopoints / AREAS;
96
97 int i;
98 VipsRect area;
99
100 /* Make sure we can read image.
101 */
102 if( vips_image_wio_input( ref ) )
103 return( -1 );
104 if( ref->Bands != 1 || ref->BandFmt != VIPS_FORMAT_UCHAR ) {
105 vips_error( "vips__tbcalcon", "%s", _( "help!" ) );
106 return( -1 );
107 }
108
109 /* Define bits to search for high-contrast areas.
110 */
111 area.width = awidth;
112 area.height = ref->Ysize;
113 area.left = 0;
114 area.top = 0;
115 vips_rect_marginadjust( &area, -border );
116 area.width--;
117 area.height--;
118 if( area.width < 0 || area.height < 0 ) {
119 vips_error( "vips__tbcalcon", "%s", _( "overlap too small" ) );
120 return( -1 );
121 }
122
123 /* Loop over areas, finding points.
124 */
125 for( i = 0; area.left < ref->Xsize; area.left += awidth, i++ )
126 if( vips__find_best_contrast( ref,
127 area.left, area.top, area.width, area.height,
128 points->x_reference + i * len,
129 points->y_reference + i * len,
130 points->contrast + i * len,
131 len,
132 points->halfcorsize ) )
133 return( -1 );
134
135 return( 0 );
136 }
137