I need a binary threshold and numpy.where() seems very slow on numpy 
0.9.9.2800:

 python -m timeit  -n 10 -s "import numpy as n;a=n.ones((512,512), 
n.uint8)*129"
"a_bin=n.where( a>128, 128,0)"
10 loops, best of 3: 37.9 msec per loop

I'm thinking the conversion of  the min, max constants from python ints 
to n.uint8 might be slowing it down?  Is there a better way?  Scipy is 
also an option.  Ive search up list quickly and nothing jumps out.

For comparison Ive got some ctypes wrapped OpenCv code (that I'd like to 
avoid) doing the same thing in <  1 msec:

Cv images here are unsigned 8 bit as above:
python -m timeit  -n 50 -s "import 
cv;sz=cv.cvSize(512,512);a=cv.cvCreateImage(sz, 8, 1); 
a_bin=cv.cvCreateImage(sz,8,1)"  "cv.cvThreshold(a, a_bin, float(128), 
float(255), cv.CV_THRESH_BINARY )"
50 loops, best of 3: 348 usec per loop

And with the Intel IPP optimizations turned on < 0.1msec:
python -m timeit  -n 50 -s "import cv; sz=cv.cvSize(512,512);  
a=cv.cvCreateImage(sz, 8, 1);  a_bin=cv.cvCreateImage(sz,8,1)"  
"cv.cvThreshold(a, a_bin, float(128), float(255), cv.CV_THRESH_BINARY )"
50 loops, best of 3: 59.5 usec per loop

Regards,
Mark

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion

Reply via email to