
How to sum up specific layers of a 3d wave?

LausX
I have a 3d wave witch contains images (512x512) and the names of these images end with to “pos”, “neg”, “prepos” or “preneg”. Now I like to add every image which ends to “pos”, to “neg” or to one of the others.
My first straightforward attempt was the following:
for (ilayer = 0; ilayer < nlayers; ilayer += 1) //select images with matching criteria take1 = “pos” if( GrepString(wstackfiles[ilayer], take1) ) addShiftedImage(wcoadd1,wstack,ilayer,0,0) normalization1+=1 endif if( GrepString(wstackfiles[ilayer], take2) ) addShiftedImage(wcoadd2,wstack,ilayer,0,0) normalization2+=1 endif if( GrepString(wstackfiles[ilayer], take3) && strlen(take3) > 0 ) addShiftedImage(wcoadd3,wstack,ilayer,0,0) normalization3+=1 endif if( GrepString(wstackfiles[ilayer], take4) && strlen(take4) > 0 ) addShiftedImage(wcoadd4,wstack,ilayer,0,0) normalization4+=1 endif endfor
With
Function addShiftedImage(wcoadd1,wstack,ilayer,pdrift,qdrift) … wcoadd1 += wstack[p+pdrift][q+qdrift][ilayer] End
But this is slow, for 40 images it takes around 6 seconds. The main time consuming process is the addShiftedImage. Therefore I thougt it should be possible to speed it up by use of MatrixOp and/or MulthiThread.
If I use MatrixOp Funtions, I can speed up by a factor of 3:
for (ilayer = 0; ilayer < nlayers; ilayer += 1) if( GrepString(wstackfiles[ilayer], take1) ) MatrixOP/NTHR=0/O/Free temp = wcoadd1 + wstack[][][ilayer] wcoadd1 = temp normalization1+=1 endif if( GrepString(wstackfiles[ilayer], take2) ) MatrixOP/NTHR=0/O/Free temp2 = wcoadd2 + wstack[][][ilayer] wcoadd2 = temp2 normalization2+=1 endif if( GrepString(wstackfiles[ilayer], take3) && strlen(take3) > 0 ) MatrixOP/NTHR=0/O/Free temp3 = wcoadd3 + wstack[][][ilayer] wcoadd3 = temp3 normalization3+=1 endif if( GrepString(wstackfiles[ilayer], take4) && strlen(take4) > 0 ) MatrixOP/NTHR=0/O/Free temp4 = wcoadd4 + wstack[][][ilayer] wcoadd4 = temp4 normalization4+=1 endif endfor
Now, I think it should be possible to speed it more up by Multithreading and to start a thread for each “pos”, “neg”…
Is this possible?
Thanks,
-As fas as I understand your code each image can only be one of take1, take2, ...? If yes use one if/endif with elseif.
-For even more speedup you might try to rearrange wstack before so that all take? images are adjacent, then you could use the syntax
wave3d[][][a,b]
of MatrixOp to sum then up in one call.What is your target layer number?
December 11, 2013 at 02:02 am - Permalink
can I send you an email (22mb) with an example?
December 11, 2013 at 02:57 am - Permalink
rearrangewas a great idea! In total I reduced the compuation time from 6s to around 0.1s!
Thanks a lot,
December 11, 2013 at 04:03 am - Permalink
December 11, 2013 at 04:27 am - Permalink
http://www.igorexchange.com/node/2377#comment-3872
, whoch solved the problem.
December 11, 2013 at 04:57 am - Permalink
glad it works now fast enough.
December 11, 2013 at 05:49 am - Permalink