filter function modified and tested

The former filter function works when apply filtering to an image, but
fails to work when InitNodeBuf calls it upon opening an image. Also, the
former function's computational complexity is high. This modification
has speeded up that process.