3 ms·
Matrix of shape (rows, columns, 3). Average the last dim for each point and change it to [0,0,0] if average less than a value, [255,255,255] if greater. A brigh
by ksm1717 6y ago
Matrix of shape (rows, columns, 3). Average the last dim for each point and change it to [0,0,0] if average less than a value, [255,255,255] if greater. A brightness threshold. May be remembering the speed up factor wrong so take it with a grain of salt - fact of the matter is it was very impressive.
I’m checking out that post later, I’m trying to make my package easy to build on, so being able to write extensions with Pythran would be another great option for speed ups. Thanks
- cycomanic 6y agoJust for the fun of it I tested what speed up I could get with a naive algorithm and pythran. Based on your description it looks like the I should do the following: def threshold_pixel(img, thr): out = np.zeros_like(img) o = np.mean(img, axis=-1) out[o>thr] = 255 return out This runs in ~30ms for a (1024,1024,3) array using numpy on my machine. Using pythran (note I had to explicitely write out the loop for out[o>thr] =255, due to a bug, that I found and just reported), I get a speed of 6.ms (with openmp) and 9ms without (I did not tune the openmp, but this should yield a much higher speedup). P.S.: Just had a look at your project, very cool, I have to try that