Note that there are some explanatory texts on larger screens.

plurals
  1. POPerformance issues using nested for loops for image processing
    text
    copied!<p>I have code, shown <a href="https://github.com/wesleybowman/cgh/blob/master/cgh.py" rel="nofollow">here</a>, that makes a computer generated hologram given an initial image. The image that the program is currently using can be found in the in the <a href="https://github.com/wesleybowman/cgh" rel="nofollow">image directory</a>.</p> <p>My program takes approx. one minute to run, and that is for a 10x10 pixel A, that only has 14 spots that the nested for loops actually care about. The slow down is the in getComplexwave function:</p> <pre><code> def getComplexwave(): '''Iterate through every source point, and calculate the complex wave contribution at each sampling pixel on the film.''' for o in xrange(objPointShape): print o+1 for i in xrange(ipxShape): for j in xrange(ipyShape): dx=objectpoints[o][0] - ipx[0][i] dy=objectpoints[o][1] - ipy[0][j] dz=objectpoints[o][2] distance=np.sqrt(dx**2+dy**2+dz**2) complexwave=np.exp(1j*k*distance) hologram[i][j]=hologram[i][j]+complexwave </code></pre> <p>Can someone help me vectorize this, or at least make it to where it is faster? I am still fairly new to python.</p> <p>Also, any other suggestions to make the code better will be much appreciated! The output should look like <a href="http://imgur.com/a/YQ4Z9#1bW6g3J" rel="nofollow">this</a>.</p> <p><a href="http://pastebin.com/rwxvhhS0" rel="nofollow">The profiling information</a> for those who want it. Note that this is only the first ten, and it is sorted by internal time.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload