Seam carving (aka liquid rescale) in pure Java