Skip to content

SVG preprocessing does not extract fill colors and replaces all stroke colors with 'black' #9

@L483

Description

@L483

The "Recognizing Vector Graphics without Rasterization" paper says:

For a point p, the attributes x of the corresponding node include the coordinates of the point, the RGB color value c and stroke width w

The "Hierarchically Recognizing Vector Graphics and A New Chart-Based Vector Graphics Dataset" paper says:

For a point p, the attributes x of the corresponding node include the coordinates of the point (px, py), the RGB color of fill cf and stroke cs, stroke width w and the primitive type t

The node features of the super node consist of the spatial features, chromatic features (the RGB color of the fill and strode), stroke width, and primitive type.

However, when parsing an SVG file, the following code is eventually called:

p = SVGParser(filepath)
type_dict = split_cross(p.get_all_shape())
width, height = p.get_image_size()
paths = shape2Path(type_dict) # get Bezier curve
node_dict = graph_builder.bezierPath2Graph(paths, 
    {'width':width, 
    'height':height, 
    'stroke':'black', 
    'stroke-width': 6}
)

split_cross extracts all and only shape-defining parameters of lines, circles, and arcs and splits circles crossed by lines and lines crossed by lines. It does not return any color information.
shape2Path converts all shapes received from split_cross and turns them into Bézier-curves without any color information.
bezierPath2Graph now builds the graph. It gets called with a hard-coded value black for stroke.

 def bezierPath2Graph(self, path, attrs):
        edges = []
        edge_attrs = []
        edges_control = []
        poss = []
        colors = []
        stroke_widths = []
        is_control = []

        width = float(attrs['width'])
        height = float(attrs['height'])
        def _buildNode(point):
            pos = [point.real / width, point.imag / height]
            
            if attrs['stroke'] in self.colors:
                color = self.colors[attrs['stroke']]
            else:
                print('unsuported stroke color!')
                raise SystemExit

            stroke_width = (float(attrs['stroke-width']) - 3) / 3.0
            #print(pos, color, stroke_width)
            return pos, color, stroke_width       

        idx = 0
        for element in path:
            pos_start, color, stroke_width = _buildNode(element.start)
            poss.append(pos_start)
            colors.append(color)
            stroke_widths.append(stroke_width)
            is_control.append(0)

            pos_c0, color, stroke_width = _buildNode(element.control1)
            idx_control1 = idx + 1
            poss.append(pos_c0)
            colors.append(color)
            stroke_widths.append(stroke_width)
            is_control.append(1)

            pos_c1, color, stroke_width = _buildNode(element.control2)
            idx_control2 = idx + 2
            poss.append(pos_c1)
            colors.append(color)
            stroke_widths.append(stroke_width)
            is_control.append(1)

            pos_end, color, stroke_width = _buildNode(element.end)
            idx_end = idx + 3
            poss.append(pos_end)
            colors.append(color)
            stroke_widths.append(stroke_width)
            is_control.append(0)

In here, for every component of every Bezier-curve _buildNode is called. Inside there, it sets the color of every node to the value of attrs['stroke'], which is always the hard-coded value black. It is also weird, that the code won't allow to pass other values than black, red, green, and blue.

So all parsed contents receive the same single hard-coded value, and allowed options are restricted to these four colors. If everything has the same color value, the model can not extract any usable information here.

I already verified this behavior by setting the color of individual elements in a SVG to 'yellow', to rgb(225, 114, 46), and to #27a081 (just used random values), and dumped the resulting node_dict into a human-readable file. All saved colors are [0.0, 0.0, 0.0].

As far as I see it, the code lacks the capability to parse hexadecimal colors or 'rgb(x, x, x)' colors entirely.

And I could not find the corresponding code to these lines from "Hierarchically Recognizing Vector Graphics and A New Chart-Based Vector Graphics Dataset":

For a point p, the attributes x of the corresponding node include the coordinates of the point (px, py), the RGB color of fill cf and stroke cs, stroke width w and the primitive type t:
x = concat (px, py, cf , cs, w, t) , p ∈ P ,

There is no code that builds nodes with the fill color, and also no code that builds nodes and saves their node type. Does this repository not contain the 'YOLaT++' model code?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions