Outils pour utilisateurs

Outils du site


issue80:tuto_-_inkscape_-_p.20

Ceci est une ancienne révision du document !


In this instalment I'll be continuing to look at the Trace Bitmap dialog. Previously I covered the Single Scan algorithms that are used to create a single path from a bitmap image, and which tend to work best on simple line art. This time it's the turn of the Multiple Scans section of the dialog, which creates more than one path, and can often be a better option when dealing with colored images and logos. You may recall from last time that the Potrace code within Inkscape only traces a simple black and white image. The three Single Scan algorithms represent different ways to reduce an image down to a single collection of black and white pixels. The Multiple Scans option, on the other hand, creates a collection of different black and white images, and then passes each of them to the Potrace algorithm individually. The multiple paths that are created are then assembled into a single group before being inserted into your Inkscape document.

This part of the dialog has radio buttons for selecting one of three algorithms. Based on the top half of the dialog, you would be forgiven for thinking that the Scans spinbox applied to only the Brightness Steps algorithm, but it actually sets the number of paths that will be created regardless of which algorithm you choose. Similarly, the checkboxes at the bottom apply to all three algorithms.

Let's begin by tracing the Full Circle Magazine logo. For this example, I'll use the “Colours” algorithm, with 8 scans and the “Smooth” and “Stack scans” checkboxes enabled – I'll explain all these options a little later. Selecting the logo and clicking the Update button suggests that the final result will be okay, so I can go ahead and click on the OK button to perform the trace. The result looks like this, with the original PNG image on the left and the traced version on the right.

It's not a perfect trace – though that was never to be expected, given that we've reduced it to 8 colors. But it's not too bad, and does represent the original image quite well. By ungrouping the 8 paths and separating them out against a gray background we can get a clearer view of the paths that have been created.

There are a couple of things to note about these paths. The first is that there's a square path which is used as the background for the final trace. This obviously results in our round logo becoming square, even though the original image was a PNG with transparent corners. The second observation is that the paths stack up on top of each other: each scan sits on top of the one before it, obscuring the lower one and just letting it show through where holes have been left – the final image is created by successively hiding parts of the lower objects.

Consider the three white circles in the final logo. As you can see, there is no single trace that contains three white circles. What you see in the final trace is the white background showing through the holes that have been left in each subsequent layer in the stack. Suppose you wanted to tidy up those circles a little. You would potentially have to modify seven of the eight paths!

And what of the square background? You can remove it by checking the “Remove Background” option in the Trace Bitmap dialog, but that just creates 7 paths rather than 8. You get all the same paths as before, but the background path is removed. However, because the three white circles are the result of the background path showing through, we actually end up with three holes in the traced image instead.

In this case, it's not too tricky to fix up the results, regardless of whether you've chosen to automatically remove the background or not. As a general rule, if you're tracing a rectangular image with no transparency then there's little to be gained from removing the background. However, for tracing images where transparency is important, it's usually best to either check that box, or to manually remove the background layer afterwards. Be aware that you might have some fixing up to do, though. The way in which the paths sit on top of each other, with later paths obscuring those below, tends to give the best visual results. But not all Inkscape users are using it for artistic reasons; there's a vibrant community of people who use it to create files for vinyl cutters, plotters and laser cutters. For these users the stacked traces would result in some lines being cut and re-cut up to eight times. In the previous example the circular outline of the FCM logo is repeated across most of the paths. Not only is this inefficient, but it could also result in damage to the work being produced, or even to the machine itself. By un-checking the “Stack Scans” option, you will end up with a series of paths that fit inside each other without overlapping.

There's no hiding of lower paths by those further up the z-index. In fact you could re-order the z-indexes and still get the same visual result. The circular outline of our logo now appears only twice – once as an interior path of the background trace, and once as the outside of the large orange path.

For some tasks – even those that don't involve blades or lasers – a trace made in this way can be easier to edit than one made with “Stack Scans” enabled. As always, the only way to know for sure is to try both approaches and see which works best with your particular source image. Be aware, however, that disabling this option can leave small gaps, blobs and other artefacts between the traced paths. A close up of one of the white circles in the FCM logo reveals this issue all too clearly (the gray part is the background color showing through gaps between the paths).

The last of the three checkboxes, “Smooth”, specifies whether the bitmap image is traced in its original form, or after slightly blurring it. The purpose of blurring it is to smooth out some of the minor color changes that often appear in an image, usually resulting in a trace that is less broken up and has fewer nodes. Because the Potrace algorithm produces only monochrome paths, the resultant trace will still be crisp and sharp, even with this option enabled. Usually I find it's better to leave this checked and benefit from simpler paths, but, if you want to preserve the fidelity of the original image as much as possible, then you may prefer to uncheck it.

Now that I've explained the options, it's time to take a look at the other two algorithms. All the examples so far have used the “Colours” algorithm. The “Greys” algorithm is a trivial one to explain: it's exactly the same as the “Colours” algorithm except that the resultant paths are converted to shades of gray.

The “Brightness steps” algorithm separates the bitmap image based on the brightness of each pixel, and produces a group of grayscale paths. The number of paths created is always one more than the “Scans” value, giving you a minimum of three paths. I've found this algorithm to be more problematic than the other two: on my machine it will create a preview for the FCM logo, but won't actually trace it at all! Fortunately it seems happy to trace renaissance paintings, so I've used an image of the Mona Lisa to create a sample grid of the same image traced using each of the three algorithms, with three different values for the “Scans” spinbox. I've only gone as far as 32 scans here – larger values will give more accurate traces but can take a long time to complete and result in a lot of paths and nodes to deal with.

There are some other options in the Trace Bitmap dialog that apply to all the tracing algorithms, whether they are of the Single Scan or Multiple Scan variety. These are gathered together into their own tab in the dialog.

Each can be enabled or disabled using the checkboxes to the left, and each also takes a single parameter which is set in the corresponding spinbox to the right. I tend to leave these all enabled with the default settings, however you may wish to disable or edit them for particular traces.

“Suppress speckles” removes all paths with a size that is less than the number specified. Turning this off can lead to some very long tracing times. Setting it to a higher value can speed up tracing, but lose fine detail in the process.

“Smooth corners” creates paths with rounded corners. Disabling this, or setting the threshold to 0 results in sharp corners instead. The threshold value determines the amount of rounding that is allowed. The effect of this option is most visible on images with sharp corners – if you want to trace a pixel image or a QR code and preserve the individual squares then you may want to disable this option.

“Optimise paths” allows Inksape to reduce the number of nodes by simplifying the traced paths in a similar manner to the Ctrl-L shortcut. The resultant paths aren't a precise match for the original, but are usually close enough for artistic purposes. The Tolerance spinbox sets the amount of variation from the original path that is allowed, with higher values allowing more variation and resulting in fewer nodes.

There's one final option in the Trace Bitmap dialog that sits on its own in the top-right corner: “SIOX foreground selection”. This uses the Simple Interactive Object eXtraction algorithm (http://www.siox.org/) to separate a foreground object from the background prior to tracing. With this enabled, the dialog requires two objects to be selected: the image to be traced, and a filled path that roughly covers the foreground object to be extracted. You can see the effect with this trace of a picture of Horatio Nelson's statue on top of his eponymous column in London.

Although this mode might appear useful, in practice it can be difficult to get a good result. The previous example only worked well when I reduced the original high-resolution image down to something with fewer pixels. In my experience, you would be better off separating out the foreground using The GIMP (which has its own, more interactive, implementation of the SIOX algorithm) and then tracing the result.

Automatic tracing of images is no magic bullet. It's not a practical way to convert a bitmap to an infinitely scalable vector unless you're also prepared to accept a loss of color depth and fine detail. And whilst it can be useful for tracing logos and line art, the resultant paths are likely to still require additional editing. Often the time spent trying to tidy up the results of an automatic trace would have been better spent manually tracing instead: it's better to manually trace a round logo as a circle than to automatically trace it and end up with an approximately circular path, for example. Don't rule out the possibility of mixing both methods, though. As always, you really need to experiment with your own images in order to decide which approach works best for you.

Image Credits “La Gioconda” (aka “Mona Lisa”) by Leonardo da Vinci http://en.wikipedia.org/wiki/File:Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg

Statue of Admiral Nelson, at the top of Nelson's Column, London. http://commons.wikimedia.org/wiki/File:Admiral_Horatio_Nelson,_Nelson%27s_Column,_Trafalgar_Square,_London.JPG

issue80/tuto_-_inkscape_-_p.20.1390403688.txt.gz · Dernière modification : 2014/01/22 16:14 de andre_domenech