jennynotjen / threadPortraitAlgorithm

Making portraits from thread - creates computer simulations and outputs thread
25 stars 13 forks source link

Convert ref_arr to numpy array, avoid loop when getting best nail #1

Closed nickodell closed 3 years ago

nickodell commented 3 years ago

Really cool project and video!

This PR speeds up getting the pixels which a thread crosses. The PIL docs say that looping over pixels is likely to be slow, so I tried replacing the loop over pixels in the line with a numpy indexing operation. I adapted an example from the scikit-image documentation to do that.

I benchmarked this with the command time python3 main.py 800 1 1 300 1000. It seems to be about an 11x speedup.

Later, when doing the subtractLine part, I found that doing the subtractLine doesn't update the array. So, I changed it to update the numpy array instead.

jennynotjen commented 3 years ago

Nice!