diff --git a/README.md b/README.md index ebe8af4b..47a2f0f0 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ Small input images should be used (like 256x256px). You don't need the detail an | `s` | 1024 | output image size | | `a` | 128 | color alpha (use `0` to let the algorithm choose alpha for each shape) | | `bg` | avg | starting background color (hex) | +| `blur` | 0 | making SVG blured, adds blur filter witn N deviation. 0 - disabled. | | `j` | 0 | number of parallel workers (default uses all cores) | | `v` | off | verbose output | | `vv` | off | very verbose output | diff --git a/main.go b/main.go index 75d776c2..57fae4cf 100644 --- a/main.go +++ b/main.go @@ -12,13 +12,14 @@ import ( "strings" "time" - "github.com/fogleman/primitive/primitive" + "github.com/ramainen/primitive/primitive" "github.com/nfnt/resize" ) var ( Input string Outputs flagArray + BlurFilter int Background string Configs shapeConfigArray Alpha int @@ -65,6 +66,7 @@ func init() { flag.StringVar(&Input, "i", "", "input image path") flag.Var(&Outputs, "o", "output image path") flag.Var(&Configs, "n", "number of primitives") + flag.IntVar(&BlurFilter, "blur", 0, "make N blur (for svg, 0 - disabled)") flag.StringVar(&Background, "bg", "", "background color (hex)") flag.IntVar(&Alpha, "a", 128, "alpha value") flag.IntVar(&InputSize, "r", 256, "resize large input images to this size") @@ -153,7 +155,7 @@ func main() { } // run algorithm - model := primitive.NewModel(input, bg, OutputSize, Workers) + model := primitive.NewModel(input, bg, OutputSize, Workers, BlurFilter) primitive.Log(1, "%d: t=%.3f, score=%.6f\n", 0, 0.0, model.Score) start := time.Now() frame := 0 diff --git a/primitive/model.go b/primitive/model.go index 80f49ae8..b078e627 100644 --- a/primitive/model.go +++ b/primitive/model.go @@ -12,6 +12,7 @@ type Model struct { Sw, Sh int Scale float64 Background Color + BlurFilter int Target *image.RGBA Current *image.RGBA Context *gg.Context @@ -22,7 +23,7 @@ type Model struct { Workers []*Worker } -func NewModel(target image.Image, background Color, size, numWorkers int) *Model { +func NewModel(target image.Image, background Color, size, numWorkers int, blurFilter int) *Model { w := target.Bounds().Size().X h := target.Bounds().Size().Y aspect := float64(w) / float64(h) @@ -43,6 +44,7 @@ func NewModel(target image.Image, background Color, size, numWorkers int) *Model model.Sh = sh model.Scale = scale model.Background = background + model.BlurFilter = blurFilter model.Target = imageToRGBA(target) model.Current = uniformRGBA(target.Bounds(), background.NRGBA()) model.Score = differenceFull(model.Target, model.Current) @@ -87,8 +89,16 @@ func (model *Model) SVG() string { bg := model.Background var lines []string lines = append(lines, fmt.Sprintf("", model.Sw, model.Sh)) + if model.BlurFilter != 0 { + lines = append(lines, fmt.Sprintf("", model.BlurFilter)) + } lines = append(lines, fmt.Sprintf("", model.Sw, model.Sh, bg.R, bg.G, bg.B)) - lines = append(lines, fmt.Sprintf("", model.Scale)) + if model.BlurFilter != 0 { + lines = append(lines, fmt.Sprintf("", model.Scale)) + } else { + lines = append(lines, fmt.Sprintf("", model.Scale)) + } + for i, shape := range model.Shapes { c := model.Colors[i] attrs := "fill=\"#%02x%02x%02x\" fill-opacity=\"%f\""