Menu

Convert color image to PNG after vectorization

Help
milad
2018-04-23
2018-04-24
  • milad

    milad - 2018-04-23

    I have color images with low number of distinct colors (8 to 20) and I'd like to first vectorize it with Potrace and then convert the result to PNG with a given dimension.
    I was able to do it with the following technique but it's very slow specially with images that have more distinct colors:
    1. For each distinct colors in the image create a BMP file showing pixels that are in that color.
    2. Convert each BMP file to SVG using Potrace.
    3. Create one final SVG by getting each SVG file created by Potrace and merging them with their appropriate colors.
    4. Convert the SVG file to PDF using rsvg-convert. (antialias off)
    5. Convert the PDF file to PNG using ImageMagick. (antialias off).
    Is there a faster way to do this in Potrace? Can it accept multiple BMP file or one BMP file showing different layers (for each distinct color) to create a color SVG?

     
  • Peter Selinger

    Peter Selinger - 2018-04-23

    Hi Milad,

    you can't automate this process within Potrace, but Inkscape has the ability to automatically convert color images by the process you describe (and using Potrace internally on each color), and you can save the result directly as a PDF or PNG.

    I hope this helps, -- Peter

     
    • milad

      milad - 2018-04-24

      Thank you far your answer and thank you so much for creating Potrace. Great work.

      Yes, I'm aware of color vectorization in Inkscape but good for them they use Potrace iternally. I've included the Potrace API in my C++ project but I just didn't know how to use it. There was a help about it on your website but as it said, it didn't explain the whole API, like how to read a BMP file and how to get the SVG result as string to work with it. How should people learn the API? By looking at the source code?!

       
  • Peter Selinger

    Peter Selinger - 2018-04-24

    Hi Milad,

    the Potrace API is only for tracing. It doesn't deal with reading BMP files or writing SVG. You could use other existing libraries for these tasks (libbmp for reading BMP files? Cairo for outputting graphics?). Or you could somehow repurpose the code in bitmap_io.c and backend_svg.c. It's not designed as a library though, and it uses global variables, e.g., the info structure defined in main. It would require a bit of refactoring.

     

Log in to post a comment.