Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: support transform #11

Open
naoto0804 opened this issue Oct 6, 2020 · 5 comments
Open

Feature request: support transform #11

naoto0804 opened this issue Oct 6, 2020 · 5 comments

Comments

@naoto0804
Copy link
Contributor

naoto0804 commented Oct 6, 2020

SVG files use usually contain transform tags like the following, but the current library does not seem to support it (as long as I see in svg.py).

<g transform="rotate(-10 50 100) translate(-36 45.5) skewX(40) scale(1 0.5)">

Is there any plan to support?

@tsaxena
Copy link

tsaxena commented Dec 20, 2020

I also looked around and could not find support for groups in general. @alexandre01 Do we have to turn groups into simple paths for using the network?

@pwichmann
Copy link

As a workaround, you could create a script to automate Inkscape and apply it to your SVG input folder as a preprocessing step.
https://github.com/Klowner/inkscape-applytransforms

Have not tried it myself though.

@tsaxena
Copy link

tsaxena commented Dec 21, 2020

Thanks @pwichmann . I will try that out.

For now, I figured out that the problem is NOT groups. I loaded an svg with groups and the current code base did load the svg correctly, except that I had to add "fill = "none" to each path in the group, otherwise when it draws its all black.
I am now trying to see if in that case the conversion to tensor is right. Is there a way of converting an tensor back to svg to make sure its working correctly?

@alexandre01
Copy link
Owner

Hello @tsaxena,

I recently added a Dataloader which can directly handle SVG icons as input. You can first pre-process the entire dataset using the https://github.com/alexandre01/deepsvg/blob/master/dataset/preprocess.py script or load https://github.com/alexandre01/deepsvg/blob/master/deepsvg/svg_dataset.py with already_preprocessed=False to perform preprocessing on the fly.

The preprocessing does the following:

svg.fill_(False)
svg.normalize().zoom(0.9)
svg.canonicalize()
svg = svg.simplify_heuristic()

Indeed, if you want to train a model for strokes only (without taking filling into account), you can set fill to False.

@alexandre01
Copy link
Owner

alexandre01 commented Dec 28, 2020

Let me just give some clarification regarding filling. Let's take the example of a filled "donut" shape: a filled circle with a "hole" inside. This is done in SVG by drawing in the same < path > a circular shape followed by another smaller circle drawn in the opposite direction (counter-clockwise). This is the even-odd rule.

DeepSVG however draws every path separately, and would generate in this case two paths. But how to apply the correct filling? The approach we propose is to predict a fill parameter which can take one of three values: Filling.OUTLINE (for stroke only), Filling.FILL (to fill the path) and Filling.ERASE (to "unfill" that area).

During preprocessing, paths are separated but the correct "fill" parameter is memorized. However, when visualising it, all filled shapes appear black.

The SVG.group_overlapping_paths method tackles this issue and re-maps the generated outputs to a valid SVG with even-odd fill rule. It does so by analysing overlaps between shapes and their fill parameters to group them together in a common path. This is a hack though, as this approach won't work for more complex cases.

It's therefore better to stick with strokes for the moment. Hope this helped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants