On the bilateral filter and ways to improve it