From: David Serby <dserby@vi...>  20020426 12:33:15

Hi, I tried to calculate the gradient in xdirection of a gray image with vil_convolve_1d_x. The output that I get is all over the place equal to zero (i.e. black image). The kernel that I use is [1, 0, 1]. If I use another kernel, like [1, 2, 1] (smoothing) I get the desired result. Why does it not work properly with the gradient kernel? Is the 1 a problem? In the file vil_convolve.h at line 55 there is the following remark: // *** may not work with kernels which take negative values but it seems to refer only to the vil_convolve_boundary_option=vil_convolve_trim, which I do not use. Here is my code, that is based on vxl/vil/examples/vil_convolve_1d.cxx: #include <vcl_iostream.h> #include <vul/vul_sprintf.h> #include <vil/vil_image.h> #include <vil/vil_load.h> #include <vil/vil_save.h> #include <vil/vil_image_as.h> #include <vil/vil_memory_image_of.h> #include <vil/vil_convolve.h> int main() { const int N = 1; float kernel[2*N+1] = {1, 2, 1}; vil_image I = vil_load("test.pgm"); vil_memory_image_of<float> bytes( vil_image_as_float(I) ); int w = bytes.width(); int h = bytes.height(); vil_memory_image_of<float> tmp (w, h); vil_convolve_signal_1d<float const> K(kernel, 0, N, 2*N+1); vil_convolve_1d_x(K, vil_convolve_signal_2d<const float> ( bytes.row_array(), 0, 0, w, 0, 0, h ), (float*)0, vil_convolve_signal_2d<float> ( tmp.row_array(), 0, 0, w, 0, 0, h ), vil_convolve_no_extend, vil_convolve_no_extend); vil_save(vil_image_as_byte(tmp), "out.pnm", "pnm"); return 0; } Does anybody has experience with vil_convolve or does anybody ever has computed an image gradient with vxl (i hope so) and can tell me how to do it? Regards, David 