fix fastcor for non-uchar images
oops, forgot to scale lsk
This commit is contained in:
parent
59b47f3900
commit
dba587916e
@ -94,11 +94,13 @@ vips_correlation_build( VipsObject *object )
|
|||||||
correlation->in->Xsize + correlation->ref->Xsize - 1,
|
correlation->in->Xsize + correlation->ref->Xsize - 1,
|
||||||
correlation->in->Ysize + correlation->ref->Ysize - 1,
|
correlation->in->Ysize + correlation->ref->Ysize - 1,
|
||||||
"extend", VIPS_EXTEND_COPY,
|
"extend", VIPS_EXTEND_COPY,
|
||||||
NULL ) ||
|
NULL ) )
|
||||||
vips__formatalike( t[0], correlation->ref, &t[1], &t[2] ) ||
|
return( -1 );
|
||||||
|
if( vips__formatalike( t[0], correlation->ref, &t[1], &t[2] ) ||
|
||||||
vips__bandalike( class->nickname, t[1], t[2], &t[3], &t[4] ) ||
|
vips__bandalike( class->nickname, t[1], t[2], &t[3], &t[4] ) ||
|
||||||
vips_image_wio_input( t[4] ) )
|
vips_image_wio_input( t[4] ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
correlation->in_ready = t[3];
|
correlation->in_ready = t[3];
|
||||||
correlation->ref_ready = t[4];
|
correlation->ref_ready = t[4];
|
||||||
|
|
||||||
|
@ -108,8 +108,8 @@ G_DEFINE_TYPE( VipsFastcor, vips_fastcor, VIPS_TYPE_CORRELATION );
|
|||||||
\
|
\
|
||||||
for( x = 0; x < r->width; x++ ) \
|
for( x = 0; x < r->width; x++ ) \
|
||||||
for( b = 0; b < bands; b++ ) { \
|
for( b = 0; b < bands; b++ ) { \
|
||||||
TYPE *p1 = (TYPE *) ref->data; \
|
TYPE *p_ref = (TYPE *) ref->data; \
|
||||||
TYPE *p2 = (TYPE *) VIPS_REGION_ADDR( in, \
|
TYPE *p_in = (TYPE *) VIPS_REGION_ADDR( in, \
|
||||||
r->left + x, r->top + y ); \
|
r->left + x, r->top + y ); \
|
||||||
\
|
\
|
||||||
TYPE sum; \
|
TYPE sum; \
|
||||||
@ -117,13 +117,13 @@ G_DEFINE_TYPE( VipsFastcor, vips_fastcor, VIPS_TYPE_CORRELATION );
|
|||||||
sum = 0; \
|
sum = 0; \
|
||||||
for( j = 0; j < ref->Ysize; j++ ) { \
|
for( j = 0; j < ref->Ysize; j++ ) { \
|
||||||
for( i = b; i < sz; i += bands ) { \
|
for( i = b; i < sz; i += bands ) { \
|
||||||
TYPE t = p1[i] - p2[i]; \
|
TYPE dif = p_ref[i] - p_in[i]; \
|
||||||
\
|
\
|
||||||
sum += t * t; \
|
sum += dif * dif; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
p1 += sz; \
|
p_ref += sz; \
|
||||||
p2 += lsk; \
|
p_in += lsk; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
*q++ = sum; \
|
*q++ = sum; \
|
||||||
@ -140,7 +140,7 @@ vips_fastcor_correlation( VipsCorrelation *correlation,
|
|||||||
int bands = vips_band_format_iscomplex( ref->BandFmt ) ?
|
int bands = vips_band_format_iscomplex( ref->BandFmt ) ?
|
||||||
ref->Bands * 2 : ref->Bands;
|
ref->Bands * 2 : ref->Bands;
|
||||||
int sz = ref->Xsize * bands;
|
int sz = ref->Xsize * bands;
|
||||||
int lsk = VIPS_REGION_LSKIP( in );
|
int lsk = VIPS_REGION_LSKIP( in ) / VIPS_IMAGE_SIZEOF_ELEMENT( in->im );
|
||||||
|
|
||||||
int x, y, i, j, b;
|
int x, y, i, j, b;
|
||||||
|
|
||||||
|
@ -15,6 +15,20 @@ import math
|
|||||||
|
|
||||||
from gi.repository import Vips
|
from gi.repository import Vips
|
||||||
|
|
||||||
|
unsigned_formats = [Vips.BandFormat.UCHAR,
|
||||||
|
Vips.BandFormat.USHORT,
|
||||||
|
Vips.BandFormat.UINT]
|
||||||
|
signed_formats = [Vips.BandFormat.CHAR,
|
||||||
|
Vips.BandFormat.SHORT,
|
||||||
|
Vips.BandFormat.INT]
|
||||||
|
float_formats = [Vips.BandFormat.FLOAT,
|
||||||
|
Vips.BandFormat.DOUBLE]
|
||||||
|
complex_formats = [Vips.BandFormat.COMPLEX,
|
||||||
|
Vips.BandFormat.DPCOMPLEX]
|
||||||
|
int_formats = unsigned_formats + signed_formats
|
||||||
|
noncomplex_formats = int_formats + float_formats
|
||||||
|
all_formats = int_formats + float_formats + complex_formats
|
||||||
|
|
||||||
# an expanding zip ... if either of the args is a scalar or a one-element list,
|
# an expanding zip ... if either of the args is a scalar or a one-element list,
|
||||||
# duplicate it down the other side
|
# duplicate it down the other side
|
||||||
def zip_expand(x, y):
|
def zip_expand(x, y):
|
||||||
@ -145,12 +159,11 @@ class TestConvolution(unittest.TestCase):
|
|||||||
def test_convsep(self):
|
def test_convsep(self):
|
||||||
for im in self.all_images:
|
for im in self.all_images:
|
||||||
for prec in [Vips.Precision.INTEGER, Vips.Precision.FLOAT]:
|
for prec in [Vips.Precision.INTEGER, Vips.Precision.FLOAT]:
|
||||||
integer = prec == Vips.Precision.INTEGER
|
|
||||||
gmask = Vips.Image.gaussmat(2, 0.1,
|
gmask = Vips.Image.gaussmat(2, 0.1,
|
||||||
integer = integer)
|
precision = prec)
|
||||||
gmask_sep = Vips.Image.gaussmat(2, 0.1,
|
gmask_sep = Vips.Image.gaussmat(2, 0.1,
|
||||||
separable = True,
|
separable = True,
|
||||||
integer = integer)
|
precision = prec)
|
||||||
|
|
||||||
self.assertEqual(gmask.width, gmask.height)
|
self.assertEqual(gmask.width, gmask.height)
|
||||||
self.assertEqual(gmask_sep.width, gmask.width)
|
self.assertEqual(gmask_sep.width, gmask.width)
|
||||||
@ -164,5 +177,16 @@ class TestConvolution(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertAlmostEqualObjects(a_point, b_point, places = 1)
|
self.assertAlmostEqualObjects(a_point, b_point, places = 1)
|
||||||
|
|
||||||
|
def test_fastcor(self):
|
||||||
|
for im in self.all_images:
|
||||||
|
for fmt in noncomplex_formats:
|
||||||
|
small = im.crop(20, 45, 10, 10).cast(fmt)
|
||||||
|
cor = im.fastcor(small)
|
||||||
|
v, x, y = cor.minpos()
|
||||||
|
|
||||||
|
self.assertEqual(v, 0)
|
||||||
|
self.assertEqual(x, 25)
|
||||||
|
self.assertEqual(y, 50)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user