Improved function for extracting y coordinates from a graph of line traces