Optimizing the MAC layer in real-time visual sensor networks applications using stencils