Author Topic: Vectorising bitmaps  (Read 1638 times)

0 Members and 1 Guest are viewing this topic.

Offline HowardlongTopic starter

  • Super Contributor
  • ***
  • Posts: 5317
  • Country: gb
Vectorising bitmaps
« on: September 24, 2019, 01:17:44 pm »
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.
 

Offline kosine

  • Regular Contributor
  • *
  • Posts: 158
  • Country: gb
Re: Vectorising bitmaps
« Reply #1 on: September 24, 2019, 01:24:19 pm »
Been a while since I used it, but CorelDraw's trace feature is pretty good at turning bitmaps into vectors.

Not free, however.
 

Offline metrologist

  • Super Contributor
  • ***
  • Posts: 2199
  • Country: 00
Re: Vectorising bitmaps
« Reply #2 on: September 24, 2019, 01:29:27 pm »
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.
 

Offline BravoV

  • Super Contributor
  • ***
  • Posts: 7547
  • Country: 00
  • +++ ATH1
Re: Vectorising bitmaps
« Reply #3 on: September 24, 2019, 01:29:41 pm »
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.

Offline martin1454

  • Regular Contributor
  • *
  • Posts: 95
  • Country: dk
Re: Vectorising bitmaps
« Reply #4 on: September 24, 2019, 01:30:35 pm »
https://oscilloscopemusic.com/ can take 3D models and convert, mabye it can also take a 2d image?
 

Offline coppice

  • Super Contributor
  • ***
  • Posts: 8637
  • Country: gb
Re: Vectorising bitmaps
« Reply #5 on: September 24, 2019, 01:56:25 pm »
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.

potrace 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.
 

Offline HowardlongTopic starter

  • Super Contributor
  • ***
  • Posts: 5317
  • Country: gb
Re: Vectorising bitmaps
« Reply #6 on: September 24, 2019, 02:10:10 pm »
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.


This 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.
 

Offline coppice

  • Super Contributor
  • ***
  • Posts: 8637
  • Country: gb
Re: Vectorising bitmaps
« Reply #7 on: September 24, 2019, 02:29:43 pm »
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.


This 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.
Can you explain a little more what you mean. Edge detection is at the heart of what potrace does.
 

Offline HowardlongTopic starter

  • Super Contributor
  • ***
  • Posts: 5317
  • Country: gb
Re: Vectorising bitmaps
« Reply #8 on: September 24, 2019, 02:41:12 pm »
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.


This 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.
Can you explain a little more what you mean. Edge detection is at the heart of what potrace does.

The 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.

 

Offline HowardlongTopic starter

  • Super Contributor
  • ***
  • Posts: 5317
  • Country: gb
Re: Vectorising bitmaps
« Reply #9 on: September 24, 2019, 02:43:54 pm »
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.

So 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!
 

Offline coppice

  • Super Contributor
  • ***
  • Posts: 8637
  • Country: gb
Re: Vectorising bitmaps
« Reply #10 on: September 24, 2019, 02:55:15 pm »
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.


This 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.
Can you explain a little more what you mean. Edge detection is at the heart of what potrace does.

The 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.

(Attachment Link)

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.
Its 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.
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6242
  • Country: fi
    • My home page and email address
Re: Vectorising bitmaps
« Reply #11 on: September 24, 2019, 03:21:07 pm »
It's not just vectorizing bitmaps, but turning them to strokes; also called centerline tracing.

Try autotrace.  I compiled it, converted head-orig3.png to PGM, and ran
  autotrace -centerline head-orig3.pgm -outputfile head.svg
and got
   

There 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.
 
The following users thanked this post: BravoV

Offline HowardlongTopic starter

  • Super Contributor
  • ***
  • Posts: 5317
  • Country: gb
Re: Vectorising bitmaps
« Reply #12 on: September 24, 2019, 04:12:50 pm »
It's not just vectorizing bitmaps, but turning them to strokes; also called centerline tracing.

Try autotrace.  I compiled it, converted head-orig3.png to PGM, and ran
  autotrace -centerline head-orig3.pgm -outputfile head.svg



OK, great, thank you. What platform and toolchain did you use? I assume it's some flavour of Linux and GCC?
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6242
  • Country: fi
    • My home page and email address
Re: Vectorising bitmaps
« Reply #13 on: September 24, 2019, 05:07:01 pm »
Yes, Ubuntu 18.04.3 LTS, on x86-64 (HP EliteBook 840 G4), using GCC 7.4.0.  Only had to install libpstoedit (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 && make to compile it; the ./autotrace you get is a wrapper script around .libs/autotrace binary for testing purposes.  (I did not do a make install though.)

The SourceForge page also has Frontline, a Gtk+ GUI for AutoTrace, but I didn't compile it.  The Github fork is newer, and maintained by other people.  I believe the various autotrace packages use the SourceForge sources.  However, the Github fork did release binaries from the latest sources in June.

The FAQ indicates 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 the Github release binaries?
 

Online LaserSteve

  • Super Contributor
  • ***
  • Posts: 1281
  • Country: us
Re: Vectorising bitmaps
« Reply #14 on: September 24, 2019, 05:32:56 pm »
You might want to take a look at Inkscape… and SVG...


Steve
"What the devil kind of Engineer are thou, that canst not slay a hedgehog with your naked arse?"
 

Offline HowardlongTopic starter

  • Super Contributor
  • ***
  • Posts: 5317
  • Country: gb
Re: Vectorising bitmaps
« Reply #15 on: September 24, 2019, 05:59:34 pm »
Yes, Ubuntu 18.04.3 LTS, on x86-64 (HP EliteBook 840 G4), using GCC 7.4.0.  Only had to install libpstoedit (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 && make to compile it; the ./autotrace you get is a wrapper script around .libs/autotrace binary for testing purposes.  (I did not do a make install though.)

The SourceForge page also has Frontline, a Gtk+ GUI for AutoTrace, but I didn't compile it.  The Github fork is newer, and maintained by other people.  I believe the various autotrace packages use the SourceForge sources.  However, the Github fork did release binaries from the latest sources in June.

The FAQ indicates 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 the Github release binaries?

Yeah, I already tried the Windows route, ended up in a bit of a rabbit hole, hence the question!
 

Offline HowardlongTopic starter

  • Super Contributor
  • ***
  • Posts: 5317
  • Country: gb
Re: Vectorising bitmaps
« Reply #16 on: September 24, 2019, 06:02:45 pm »
You might want to take a look at Inkscape… and SVG...


Steve

I 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.
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6242
  • Country: fi
    • My home page and email address
Re: Vectorising bitmaps
« Reply #17 on: September 24, 2019, 06:11:59 pm »
autotrace supports HPGL output, and like I said, it isn't hard to add or modify it for a custom format.  Look at src/output-plt.c to see the code for HPGL (.plt) output; it's just 232 lines of C code, and pretty obvious what it does.
 

Offline CatalinaWOW

  • Super Contributor
  • ***
  • Posts: 5226
  • Country: us
Re: Vectorising bitmaps
« Reply #18 on: September 24, 2019, 06:17:59 pm »
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.
 

Offline FreddieChopin

  • Regular Contributor
  • *
  • !
  • Posts: 102
  • Country: ua
Re: Vectorising bitmaps
« Reply #19 on: September 24, 2019, 06:39:34 pm »
You should take a loo at algorithms used in GBA emulators
https://johanneskopf.de/publications/pixelart/supplementary/comparison_hq4x.html
 

Offline metrologist

  • Super Contributor
  • ***
  • Posts: 2199
  • Country: 00
Re: Vectorising bitmaps
« Reply #20 on: September 24, 2019, 07:48:44 pm »
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.

So 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!

I 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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf