On Tue, Oct 10, 2006 at 11:49:09AM -0500, [EMAIL PROTECTED] wrote:
> This patch is paticularly for david's eyes, as it gets rid of an ugliness in
> the code.
>
> It takes memory clearing responsibilities out of gabor.c, and does them all
> at once in extract_block_features.c.
>
> 3% speed improvement.
>
> My next patch should be my last straight up speed optimization (good for
> another 8%!), but it renames a variable to a macro all *over* the place,
> so I havent submitted it yet.
>
> Machine: opteron 246HE
> Mainline speed: 1.0
> CVS speed, with this patch: .44
>
> Other people are welcome to criticize as well. ;)
>
> Julia Longtin <[EMAIL PROTECTED]>
>
you know, it really helps to attatch patches to these mails. :)
Julia Longtin <[EMAIL PROTECTED]>
--- ../../dev2/gift/ChangeLog 2006-10-08 18:51:32.000000000 -0500
+++ ChangeLog 2006-10-10 11:32:21.000000000 -0500
@@ -1,3 +1,13 @@
+2006-10-10 <[EMAIL PROTECTED]>
+
+ * FeatureExtraction/gabor.c
+ comment cleanups.
+ stop handling memory zeroing.
+ * FeatureExtraction/extract_block_features.c
+ comment cleanups.
+ handle zeroing memory for gabor_filter.
+ allocate conv, conv2, and filtered_image in one sweep. also memset them
at the same time.
+
2006-10-05 <[EMAIL PROTECTED]>
* FeatureExtraction/gabor.c
--- ../../dev2/gift/FeatureExtraction/gabor.c 2006-10-08 18:51:38.000000000
-0500
+++ FeatureExtraction/gabor.c 2006-10-10 11:27:00.000000000 -0500
@@ -9,9 +9,6 @@
#include "gabor.h"
-/* for MAX_WIDTH and MAX_HEIGHT */
-#include "gift_features.h"
-
/* for uint32_t */
#include <stdint.h>
@@ -59,7 +56,7 @@
int32_t x, x_c; /* ints to force type promotion later */
double u0, u, v, sigma, theta;
- /* now set the values of the kernels */
+ /* set the values of the kernels */
u0 = u00;
for (i = 0; i < num_gabor_scales; i++) {
sigma = sigma_m(u0);
@@ -83,19 +80,17 @@
}
}
-void gabor_filter(double *image, int width, int height, int filter_scale, int
orientation, double **kernelsxy, double *output) {
+/* conv, conv2, and output need to be cleared before feeding them to this
function. */
+/* conv and conv2 are just temporary space, for juggling image data between
filters */
+void gabor_filter(double *image, int width, int height, int filter_scale, int
orientation, double **kernelsxy, double *conv, double *conv2, double *output) {
uint32_t x, y;
uint32_t k;
double * target_kernal;
- double conv[MAX_WIDTH*MAX_HEIGHT]; /* take advantage of our fixed image
size. */
double * target_conv;
double * target_image;
double temparray[kernal_size[2]];
- memset(&conv, 0, MAX_WIDTH*MAX_HEIGHT*sizeof(double));
- memset(output, 0, MAX_WIDTH*MAX_HEIGHT*sizeof(double));
-
/* first convolution */
target_kernal=kernelsxy[filter_scale*num_gabors_per_scale+orientation];
for (x = 0; x < width; x++) {
@@ -144,8 +139,6 @@
}
}
- memset(&conv, 0, MAX_WIDTH*MAX_HEIGHT*sizeof(double));
-
/* third convolution */
target_kernal=&target_kernal[kernal_size[filter_scale]];
for (x = 0; x < width; x++) {
@@ -156,13 +149,13 @@
for (k = 0; k < kernal_size[filter_scale]; k++)
temparray[k]= target_kernal[k]*target_image[k];
for (k = 0; k < kernal_size[filter_scale]; k++)
- conv[((width*height)-1)-(x*height+y)] += temparray[k];
+ conv2[((width*height)-1)-(x*height+y)] += temparray[k];
}
else
{
for (k=0; k < kernal_size[filter_scale]; k++) {
if ((x+kernal_size[filter_scale]/2 >= k) &&
(x+kernal_size[filter_scale]/2 < width+k)) {
- conv[((width*height)-1)-(x*height+y)] +=
+ conv2[((width*height)-1)-(x*height+y)] +=
target_kernal[k]*target_image[k];
}
}
@@ -174,7 +167,7 @@
target_kernal=&target_kernal[kernal_size[filter_scale]];
for (x = 0; x < width; x++) {
for (y = 0; y < height; y++) {
-
target_conv=&conv[((width*height)-1)-(x*height+y+(kernal_size[filter_scale]/2))];
+
target_conv=&conv2[((width*height)-1)-(x*height+y+(kernal_size[filter_scale]/2))];
if (((y>=kernal_size[filter_scale]/2)) &&
((y+kernal_size[filter_scale]/2)<height))
{
/* first do the matrix multiply, then do the summation, so
the matrix multiply can be vectored. */
--- ../../dev2/gift/FeatureExtraction/extract_block_features.c 2006-09-15
15:12:44.000000000 -0500
+++ FeatureExtraction/extract_block_features.c 2006-10-10 11:26:32.000000000
-0500
@@ -130,6 +130,8 @@
int energy_class;
PPM *value_plane;
double *value_image_dbl, *filtered_image;
+ double *conv;
+ double *conv2;
double gabor_mean;
double * kernelsxy[num_gabor_scales*num_gabors_per_scale];
@@ -142,7 +144,10 @@
"array" gabor_ranges[]
*/
- filtered_image = (double
*)malloc(im_hsv->width*im_hsv->height*sizeof(double));
+ /* this is all created with one malloc, so that it can be cleared in
one memset() call */
+ filtered_image = (double
*)malloc(im_hsv->width*im_hsv->height*sizeof(double)*3);
+ conv=&filtered_image[im_hsv->width*im_hsv->height];
+ conv2=&conv[im_hsv->width*im_hsv->height];
create_filter_kernels(kernelsxy);
@@ -150,8 +155,11 @@
for (scale = 0; scale < num_gabor_scales; scale++) {
for (orientation = 0; orientation < num_gabors_per_scale;
orientation++) {
+ /* this clears conv, conv2, and filtered_image in one
call. */
+ memset(filtered_image, 0,
MAX_WIDTH*MAX_HEIGHT*sizeof(double)*3);
+
/* filter the image */
- gabor_filter(im_hsv->value_plane_double_reversed,
im_hsv->width, im_hsv->height, scale, orientation, kernelsxy, filtered_image);
+ gabor_filter(im_hsv->value_plane_double_reversed,
im_hsv->width, im_hsv->height, scale, orientation, kernelsxy, conv, conv2,
filtered_image);
/* extract the rms energy for each block */
k = 0; /* block counter */
_______________________________________________
help-GIFT mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-gift