From 235eb87aa5d20c2badc4af15559a9f6031db6076 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 15 Jul 2014 09:05:00 +0100 Subject: [PATCH] sort out sense of fourier filter masks --- TODO | 70 +++++++++++++++++++++++++++++++ libvips/create/mask_gaussian.c | 2 +- libvips/create/mask_ideal.c | 2 +- libvips/create/mask_ideal_band.c | 2 +- libvips/deprecated/im_freq_mask.c | 6 +-- 5 files changed, 76 insertions(+), 6 deletions(-) diff --git a/TODO b/TODO index deae2057..35baacb2 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,73 @@ +- butterworth highpass is wrong! actually makes a lowpass filter + + $ ~/vips-7.26/bin/vips-7.26 vips im_create_fmask x2.v 32 32 2 42 0.5 0.5 0 0 + + is correct: a black circle on a white bg, with a white dot top left + + 2 because we have + + vips7compat.h: IM_MASK_BUTTERWORTH_HIGHPASS = 2, + + in vip8 this is + + $ vips mask_butterworth x.v 32 32 42 0.5 0.5 + + generates a highpass filter, or + + $ vips mask_butterworth x.v 32 32 42 0.5 0.5 --reject + + for a lowpass filter + + doesn't match ideal! there we have --reject to make a highpass filter + + +im_freq_mask has: + + IM_MASK_IDEAL_HIGHPASS: 0 + if( vips_mask_ideal( + IM_MASK_IDEAL_LOWPASS: 1 + if( vips_mask_ideal( "reject", TRUE, + IM_MASK_BUTTERWORTH_HIGHPASS: 2 + if( vips_mask_butterworth( + IM_MASK_BUTTERWORTH_LOWPASS: 3 + if( vips_mask_butterworth( "reject", TRUE, + IM_MASK_GAUSS_HIGHPASS: 4 + if( vips_mask_gaussian( + IM_MASK_GAUSS_LOWPASS: 5 + if( vips_mask_gaussian( "reject", TRUE, + + IM_MASK_IDEAL_RINGPASS: 6 + if( vips_mask_ideal_ring( + IM_MASK_IDEAL_RINGREJECT: 7 + if( vips_mask_ideal_ring( "reject", TRUE, + IM_MASK_BUTTERWORTH_RINGPASS: 8 + if( vips_mask_butterworth_ring( + IM_MASK_BUTTERWORTH_RINGREJECT: 9 + if( vips_mask_butterworth_ring( "reject", TRUE, + IM_MASK_GAUSS_RINGPASS: 10 + if( vips_mask_gaussian_ring( + IM_MASK_GAUSS_RINGREJECT: 11 + if( vips_mask_gaussian_ring( "reject", TRUE, + + IM_MASK_IDEAL_BANDPASS: 12 + if( vips_mask_ideal_ring( + IM_MASK_IDEAL_BANDREJECT: 13 + if( vips_mask_ideal_ring( "reject", TRUE, + IM_MASK_BUTTERWORTH_BANDPASS: 14 + if( vips_mask_butterworth_ring( + IM_MASK_BUTTERWORTH_BANDREJECT: 15 + if( vips_mask_butterworth_ring( "reject", TRUE, + IM_MASK_GAUSS_BANDPASS: 16 + if( vips_mask_gaussian_ring( + IM_MASK_GAUSS_BANDREJECT: 17 + if( vips_mask_gaussian_ring( "reject", TRUE, + + IM_MASK_FRACTAL_FLT: 18 + // not implemented + + + + - maxpos_avg seems to give variable results diff --git a/libvips/create/mask_gaussian.c b/libvips/create/mask_gaussian.c index ecf268d8..d59f5fc8 100644 --- a/libvips/create/mask_gaussian.c +++ b/libvips/create/mask_gaussian.c @@ -64,7 +64,7 @@ vips_mask_gaussian_point( VipsMask *mask, double dx, double dy ) double fc2 = fc * fc; double dist2 = (dx * dx + dy * dy) / fc2; - return( exp( cnst * dist2 ) ); + return( 1.0 - exp( cnst * dist2 ) ); } static void diff --git a/libvips/create/mask_ideal.c b/libvips/create/mask_ideal.c index 6336b657..54625e75 100644 --- a/libvips/create/mask_ideal.c +++ b/libvips/create/mask_ideal.c @@ -62,7 +62,7 @@ vips_mask_ideal_point( VipsMask *mask, double dx, double dy ) double dist2 = dx * dx + dy * dy; double fc2 = fc * fc; - return( dist2 <= fc2 ? 1.0 : 0.0 ); + return( dist2 <= fc2 ? 0.0 : 1.0 ); } static void diff --git a/libvips/create/mask_ideal_band.c b/libvips/create/mask_ideal_band.c index 17a2c80d..0718c2a5 100644 --- a/libvips/create/mask_ideal_band.c +++ b/libvips/create/mask_ideal_band.c @@ -76,7 +76,7 @@ vips_mask_ideal_band_point( VipsMask *mask, double dx, double dy ) double d1 = (dx - fcx) * (dx - fcx) + (dy - fcy) * (dy - fcy); double d2 = (dx + fcx) * (dx + fcx) + (dy + fcy) * (dy + fcy); - return( d1 < r2 || d2 < r2 ? 1.0 : 0.0 ); + return( (d1 < r2 || d2 < r2) ? 1.0 : 0.0 ); } static void diff --git a/libvips/deprecated/im_freq_mask.c b/libvips/deprecated/im_freq_mask.c index a1218b81..129eefff 100644 --- a/libvips/deprecated/im_freq_mask.c +++ b/libvips/deprecated/im_freq_mask.c @@ -67,39 +67,39 @@ build_freq_mask( IMAGE *out, int xs, int ys, ImMaskType flag, va_list ap ) switch( flag ) { case IM_MASK_IDEAL_HIGHPASS: if( vips_mask_ideal( &t, xs, ys, p0, - "reject", TRUE, NULL ) ) return( -1 ); break; case IM_MASK_IDEAL_LOWPASS: if( vips_mask_ideal( &t, xs, ys, p0, + "reject", TRUE, NULL ) ) return( -1 ); break; case IM_MASK_BUTTERWORTH_HIGHPASS: if( vips_mask_butterworth( &t, xs, ys, p0, p1, p2, - "reject", TRUE, NULL ) ) return( -1 ); break; case IM_MASK_BUTTERWORTH_LOWPASS: if( vips_mask_butterworth( &t, xs, ys, p0, p1, p2, + "reject", TRUE, NULL ) ) return( -1 ); break; case IM_MASK_GAUSS_HIGHPASS: if( vips_mask_gaussian( &t, xs, ys, p0, p1, - "reject", TRUE, NULL ) ) return( -1 ); break; case IM_MASK_GAUSS_LOWPASS: if( vips_mask_gaussian( &t, xs, ys, p0, p1, + "reject", TRUE, NULL ) ) return( -1 ); break;