Vectorising bitmaps - Page 1
Forum section: electronics / general

author: Howardlong
author_rank: Super Contributor
timestamp: September 24, 2019, 01:17:44 pm
content: I am looking for a known working workflow to take bitmaps and turn them into simple vectors for analogue scope display.From my past attempts, I split it into two parts, firstly generate a black and white bitmap, then run an edge detection on the bitmap, then convert to vectors. Unfortunately the results weren't very good.I'd be interested on others' experiences on doing this, as I feel I'm missing something.

author: kosine
author_rank: Regular Contributor
timestamp: September 24, 2019, 01:24:19 pm
content: Been a while since I used it, but CorelDraw's trace feature is pretty good at turning bitmaps into vectors.Not free, however.

author: metrologist
author_rank: Super Contributor
timestamp: September 24, 2019, 01:29:27 pm
content: Are you converting line art or something more complicated? What tool performs the edge detection?I've tried Adobe Illustrator image tracing feature and results depend a lot on the source image. I generally just recreate what I want manually.I've also tried using PhotoShop to create workpaths and export them. I am able to get actual rectangles, but a lot of objects get rendered as line segments.I'd like to find a more reliable and better solution too.

author: BravoV
author_rank: Super Contributor
timestamp: September 24, 2019, 01:29:41 pm
content: Have you try Potrace ? ->http://potrace.sourceforge.net/Its based on GNU General Public License.Example, before and after, make sure to check other more complex examples as well.

author: martin1454
author_rank: Regular Contributor
timestamp: September 24, 2019, 01:30:35 pm
content: https://oscilloscopemusic.com/can take 3D models and convert, mabye it can also take a 2d image?

author: coppice
author_rank: Super Contributor
timestamp: September 24, 2019, 01:56:25 pm
content: Quote from: BravoV on September 24, 2019, 01:29:41 pmpotrace is a vectorizing library that is used by a variety of software packages. You can find a number of these packages listed on the potrace project page.

author: Howardlong
author_rank: Super Contributor
timestamp: September 24, 2019, 02:10:10 pm
content: Quote from: BravoV on September 24, 2019, 01:29:41 pmThis misses the edge detection aspect. You can't really do filling in very well on a scope. I am looking for a means of performing the edge detection as well.

author: coppice
author_rank: Super Contributor
timestamp: September 24, 2019, 02:29:43 pm
content: Quote from: Howardlong on September 24, 2019, 02:10:10 pmCan you explain a little more what you mean. Edge detection is at the heart of what potrace does.

author: Howardlong
author_rank: Super Contributor
timestamp: September 24, 2019, 02:41:12 pm
content: Quote from: coppice on September 24, 2019, 02:29:43 pmThe key here is that I am looking to convert a monochrome bitmap to vectors for display on an analogue scope.Thus, filled in regions aren't really compatible, it's a series of lines in a line drawing.So, (i) take a red square in 24bpp RGB bitmap space. (ii) Convert to 1bpp black and white bitmap. (iii) Convert to edge.Then, (iv) take the edges and convert to vectors.Those vectors are then stored in an array and sent to the scope in XY mode.

author: Howardlong
author_rank: Super Contributor
timestamp: September 24, 2019, 02:43:54 pm
content: Quote from: metrologist on September 24, 2019, 01:29:27 pmSo I've tried a number of odd solutions (potrace was one, but I've also used others both online and offline) and none of them really do what I want, so yes, like you, I give up and do it manually, which is OK for a simple one off, but tiresome for much more!

author: coppice
author_rank: Super Contributor
timestamp: September 24, 2019, 02:55:15 pm
content: Quote from: Howardlong on September 24, 2019, 02:41:12 pmIts a long time since I looked at potrace, but I thought it spit out a series of vectors for the outline of an area, and what the filling should be. If you ignore the filling stuff you have the outline vectors.

author: Nominal Animal
author_rank: Super Contributor
timestamp: September 24, 2019, 03:21:07 pm
content: It's not just vectorizing bitmaps, but turning them tostrokes; also calledcenterline tracing.Tryautotrace. I compiled it, convertedhead-orig3.pngtoPGM, and ranautotrace -centerline head-orig3.pgm -outputfile head.svgand gotThere are various output formats and tunables you can use to make it do what you want; you can even add your own output format to make it easy for you to generate the waveform for your scope.

author: Howardlong
author_rank: Super Contributor
timestamp: September 24, 2019, 04:12:50 pm
content: Quote from: Nominal Animal on September 24, 2019, 03:21:07 pmOK, great, thank you. What platform and toolchain did you use? I assume it's some flavour of Linux and GCC?

author: Nominal Animal
author_rank: Super Contributor
timestamp: September 24, 2019, 05:07:01 pm
content: Yes, Ubuntu 18.04.3 LTS, on x86-64 (HP EliteBook 840 G4), using GCC 7.4.0. Only had to installlibpstoedit(using standard package management; I do have most development packages installed though), otherwise was a straight./autogen.sh && ./configure --prefix=/usr/local --includedir=/usr/include --libdir=/usr/lib --sysconfdir=/etc --datarootdir=/usr/share && maketo compile it; the./autotraceyou get is a wrapper script around.libs/autotracebinary for testing purposes. (I did not do amake installthough.)TheSourceForgepage also has Frontline, a Gtk+ GUI for AutoTrace, but I didn't compile it. TheGithubfork is newer, and maintained by other people. I believe the variousautotrace packagesuse the SourceForge sources. However, the Github fork didrelease binariesfrom the latest sources in June.TheFAQindicates you should be able to compile the command-line autotrace for Windows (as well as Mac and Linux), but I don't have any Windows machines, and cannot help with that; sorry. Perhaps you could try theGithub release binaries?

author: LaserSteve
author_rank: Super Contributor
timestamp: September 24, 2019, 05:32:56 pm
content: You might want to take a look at Inkscape… and SVG...Steve

author: Howardlong
author_rank: Super Contributor
timestamp: September 24, 2019, 05:59:34 pm
content: Quote from: Nominal Animal on September 24, 2019, 05:07:01 pmYeah, I already tried the Windows route, ended up in a bit of a rabbit hole, hence the question!

author: Howardlong
author_rank: Super Contributor
timestamp: September 24, 2019, 06:02:45 pm
content: Quote from: LaserSteve on September 24, 2019, 05:32:56 pmI already tried Inkscape.The problem is that all of the things I’ve already tried are trying way too hard.There’s also the problem that many of them generate .svg files which are a PITA to parse and convert. I don’t want splines! Again, a sledgehammer to crack a nut.

author: Nominal Animal
author_rank: Super Contributor
timestamp: September 24, 2019, 06:11:59 pm
content: autotrace supports HPGL output, and like I said, it isn't hard to add or modify it for a custom format. Look atsrc/output-plt.cto see the code for HPGL (.plt) output; it's just 232 lines of C code, and pretty obvious what it does.

author: CatalinaWOW
author_rank: Super Contributor
timestamp: September 24, 2019, 06:17:59 pm
content: I am not aware of a really good solution to this problem. I use Inkscape and good results require a lot of tweaking to the input image (among them resizing for higher pixel count, low pass filtering, thresholding or other edge erosion techniques, various edg enhancement filters) and then tweaking the conversion parameters in Inkscape (mostly preventing stacking of multiple passes and adjusting thresholds) followed by manual editing to get the results I want. Sometimes I have just given up on particular image because nothing seems to work. But the results more often than not are quite good.How many different images do you have to convert? If it is a dozen or less I would just grind through the above process. It will be less work than finding the perfect program (if it exists) or finding and tweaking a less than perfect program and then hand editing the results.

author: FreddieChopin
author_rank: Regular Contributor
timestamp: September 24, 2019, 06:39:34 pm
content: You should take a loo at algorithms used in GBA emulatorshttps://johanneskopf.de/publications/pixelart/supplementary/comparison_hq4x.html

author: metrologist
author_rank: Super Contributor
timestamp: September 24, 2019, 07:48:44 pm
content: Quote from: Howardlong on September 24, 2019, 02:43:54 pmI just thought of something else given your examples.https://www.scorchworks.com/can take images and create tool paths for CNC and laser engraving work. F-Engrave and dmap2gcode might get you somewhere, if you can process gcode to something useful.