You might be able to do better compression by traversing the pixels in Hilbert [1] order or Z [2] order, to take into account vertical neighbours as well as horizontal. It might cost time or space though, as you couldn't stream the pixels through it anymore - you'd need them all in memory.
[1] https://en.wikipedia.org/wiki/Hilbert_curve
[2] https://en.wikipedia.org/wiki/Z-order_curve