fogleman / primitive

Reproducing images with geometric primitives.
https://primitive.lol/
MIT License
12.35k stars 608 forks source link

Performance #12

Closed jyounus closed 7 years ago

jyounus commented 7 years ago

Hey there,

First of all, thanks for making this available open source! :D

I'm working on a side project. It's a mobile app with a backend. It has user profiles and user uploaded photos. I came across this repo today and I really, really, really want to use this for my project. It's such a beautiful effect.

I've played around with it a bit on my laptop using different parameters and a bunch of different images of people. For me, the best result is when I use 200 iterations and the default resize option of 256. The problem is, this takes around 50+ seconds (with -v enabled). And this is on my rMBP (top of the range a couple of years ago, so the specs are decent).

If I did this on a backend server, it would probably take even longer, since the server I could afford wouldn't be a beast.

This is probably a really stupid question, I know, but is there any way the code could be further optimised to increase the overall performance of it?

I was going to use this together with my NodeJS backend and somehow make it work. But knowing that it might add ~1 minute of extra processing time per image upload, I'm not too sure anymore.

Do you have any recommendations? I tried playing around with the resize parameter, but setting it to 64 or even 128 is too low for my liking. The effect just isn't as good as 256. Same with the iteration count. Anything lower than 200 just isn't as beautiful.

Thanks

fogleman commented 7 years ago

I just committed some significant performance improvements, try it out.

You can also try tweaking the hard-coded parameters in Model.Step: https://github.com/fogleman/primitive/blob/master/primitive/model.go#L124-L125

You can probably get decent results much faster by doing that. The shapes won't be as optimal but it may not matter much.

jyounus commented 7 years ago

I just downloaded your latest commit and tested it out on 3 different images. It went from ~50+ seconds down to about ~15-20 seconds! This is much much better! :D

I'll play around with the Model.Step function and see if I can squeeze out some more performance for myself.

Once again, thank you very much for this awesome lib!