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
|
/* im_compass
*
* Author: N. Dessipris (Copyright, N. Dessipris 1991)
* Written on: 08/05/1991
* Modified on:
* 11/3/01 JC
* - rewritten, calling im_conv() and im_maxvalue()
* 3/2/10
* - gtkdoc
*/
/*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 <vips/intl.h>
#include <vips/vips.h>
/**
* im_compass:
* @in: input image
* @out: output image
* @mask: convolution mask
*
* @in is convolved 8 times with @mask, each time @mask is rotated by 45
* degrees. Each output pixel is the largest absolute value of the 8
* convolutions.
*
* See also: im_lindetect(), im_gradient(), im_conv().
*
* Returns: 0 on success, -1 on error
*/
int
im_compass( IMAGE *in, IMAGE *out, INTMASK *mask )
{
IMAGE *filtered[8];
IMAGE *absed[8];
int i;
if( im_open_local_array( out, filtered, 8, "im_compass:1", "p" ) ||
im_open_local_array( out, absed, 8, "im_compass:2", "p" ) )
return( -1 );
for( i = 0; i < 8; i++ ) {
if( im_conv( in, filtered[i], mask ) ||
!(mask = im_local_imask( out,
im_rotate_imask45( mask, mask->filename ) )) )
return( -1 );
}
for( i = 0; i < 8; i++ )
if( im_abs( filtered[i], absed[i] ) )
return( -1 );
return( im_maxvalue( absed, out, 8 ) );
}
/**
* im_lindetect:
* @in: input image
* @out: output image
* @mask: convolution mask
*
* @in is convolved four times with @mask, each time @mask is rotated by 45
* degrees. Each output pixel is the largest absolute value of the four
* convolutions.
*
* See also: im_compass(), im_gradient(), im_conv().
*
* Returns: 0 on success, -1 on error
*/
int
im_lindetect( IMAGE *in, IMAGE *out, INTMASK *mask )
{
IMAGE *filtered[4];
IMAGE *absed[4];
int i;
if( im_open_local_array( out, filtered, 4, "im_lindetect:1", "p" ) ||
im_open_local_array( out, absed, 4, "im_lindetect:2", "p" ) )
return( -1 );
for( i = 0; i < 4; i++ ) {
if( im_conv( in, filtered[i], mask ) ||
!(mask = im_local_imask( out,
im_rotate_imask45( mask, mask->filename ) )) )
return( -1 );
}
for( i = 0; i < 4; i++ )
if( im_abs( filtered[i], absed[i] ) )
return( -1 );
return( im_maxvalue( absed, out, 4 ) );
}
/**
* im_gradient:
* @in: input image
* @out: output image
* @mask: convolution mask
*
* @in is convolved with @mask and with @mask after a 90 degree rotation. The
* result is the sum of the absolute value of the two convolutions.
*
* See also: im_lindetect(), im_gradient(), im_conv().
*
* Returns: 0 on success, -1 on error
*/
int
im_gradient( IMAGE *in, IMAGE *out, INTMASK *mask )
{
IMAGE *t[4];
INTMASK *rmask;
if( im_open_local_array( out, t, 4, "im_gradient", "p" ) )
return( -1 );
if( !(rmask = im_local_imask( out,
im_rotate_imask90( mask, mask->filename ) )) )
return( -1 );
if( im_conv( in, t[0], mask ) ||
im_conv( in, t[1], rmask ) ||
im_abs( t[0], t[2] ) ||
im_abs( t[1], t[3] ) ||
im_add( t[2], t[3], out ) )
return( -1 );
return( 0 );
}
|