Curves and grains extraction from labeled pixel images