Reputation: 11
Trying to implement offset function for 3D data. This is a test code,
image ThreeDOffSet(image img3D, number shiftx, number shiftY) {
image img3DTmp, rst
img3DTmp:=img3D.ImageClone()
img3DTmp=img3D[icol+shiftx, irow+shifty, iplane]
//img3D_.showImage()
return img3DTmp
}
void main() {
number startTick, stopTick
startTick = GetHighResTickCount()
image img3D:=exprSize(200, 200, 1024,random())
image rst:=img3D.ThreeDOffSet(10, -6)
stopTick = GetHighResTickCount()
img3D.showImage()
rst.showImage()
result("\nDuration:"+(stopTick-StartTick)/GetHighResTicksPerSecond()+"sec\n")
}
main()
Can DM-script do faster than this?
Upvotes: 0
Views: 52
Reputation: 11
Found a faster way. This is 20 times faster.
image ThreeDOffSet(image img3D, number shiftx, number shiftY, number method) {
number startTick, stopTick, d0,d1, d2, x, y
image rst
startTick = GetHighResTickCount()
if (method==0) {
rst:=img3D.ImageClone()
rst=img3D[icol+shiftx, irow+shifty, iplane]
stopTick = GetHighResTickCount()
}
else if (method==1) {
img3D.get3dsize(d0,d1,d2)
rst:=exprSize(d0,d1,d2,0)
x=shiftX
y=ShiftY
rst[x,y,0,d0,d1,d2]=img3D.slice3(0,0,0,0,d0-x,1, 1,d1-y,1,2,d2,1)
stopTick = GetHighResTickCount()
}
result("\nDuration:"+(stopTick-StartTick)/GetHighResTicksPerSecond()+"sec\n")
return rst
}
void main() {
number method
image rst
image img3D:=exprSize(200, 200, 1024,random())
getnumber("method", method,method)
rst:=img3D.ThreeDOffSet(10, 6,method)
img3D.showImage()
rst.showImage()
}
main()
Upvotes: 0