BachiLi / diffvg

Differentiable Vector Graphics Rasterization
https://people.csail.mit.edu/tzumao/diffvg/
Apache License 2.0
923 stars 155 forks source link

Shrink color space #23

Open AntonBiryukovUofC opened 3 years ago

AntonBiryukovUofC commented 3 years ago

Hello @BachiLi , thanks for this awesome contribution!

I was wondering if you could give me a hint how to modify your code a bit. I was hoping to try out you painterly rendering app for sketching applications, and am not sure how to modify it to incorporate few things:

a) Remove the opacity before loss calculation / as a parameter. Sketching is done often with one pencil whose alpha is pretty much always 1. b) An artist doing sketching usually has a constrained discrete palette to operate with (often with just black pencil / pen). It would be lovely to know how to constrain stroke colors to a specific palette (or rgb subspace)

I think I solved a) via:

         for group in shape_groups:
                group.stroke_color.data.clamp_(0.0, 1.0)
                #Limit the opactiy
                group.stroke_color.data[3].clamp_(1.0, 1.0))

Thanks in advance,

Anton.

AntonBiryukovUofC commented 3 years ago

Here's the desired outcome example: https://openprocessing.org/sketch/486307/

AntonBiryukovUofC commented 3 years ago

image

dribnet commented 3 years ago

I'm also interested in color constraints. Specifically, I currently would like to setup a system using indexed color and then allow the system to optimise both the palette and with the color assignments of individual elements. Conceptually this seems possible through optimisation using an embedding or even just argmax across multiple scalar tensors each representing possible indexes into color table - but I haven't been able to code this up successfully thus far and would be interested in sharing notes.