快速累积总和? [英] Fast Cumulative Sum?
问题描述
菜单命令音量"投影>沿着Z投影"与脚本编写相比(甚至具有内在变量)确实非常快.在z方向上的512×512×200的3D图像体积的累积和(投影)花费<0.5秒.与> 8秒相比.通过使用脚本.除了使用ChooseMenuItem()以外,是否可以直接访问此脚本功能?
The menu command "Volume > Projection > Project Along Z" is really fast as compared to scripting (even with intrinsic variables). Cumulative sum (projection) of a 3D image volume of 512x512x200 in z-direction takes <0.5 sec. as compared to >8 sec. by using script. Is there a direct access this script function other than using ChooseMenuItem()?
显示差异的脚本示例:
// create an image of 512x512x200, assign random numbers
image img := exprsize(512, 512, 200, random());
img.SetName( "test" );
img.ShowImage();
//
number start_tick, end_tick, calc_time;
// do volume projectin with menu command : Volume>Project>Project Along Z
start_tick = GetHighResTickCount();
ChooseMenuItem( "Volume", "Project", "Project Along Z"); // do z-projection
end_tick = GetHighResTickCount();
// calculate execution time
calc_time = CalcHighResSecondsBetween( start_tick, end_tick );
// display result image
Image img_projZ1 := GetFrontImage();
img_projZ1.SetName( "Z-proj.#1 (" + calc_time.format("%.2fs") + ")");
img_projZ1.ShowImage();
// do volume project in z-direction (using intrinsic variable iplane)
image img_projZ2 := exprsize(512, 512, 0.0);
start_tick = GetHighResTickCount();
img_projZ2[icol, irow, iplane] += img; // do z-projection
end_tick = GetHighResTickCount();
// calculate execution time
calc_time = CalcHighResSecondsBetween( start_tick, end_tick );
// display result image
img_projZ2.SetName( "Z-projection#1 (" + calc_time.format("%.2fs") + ")");
img_projZ2.ShowImage();
推荐答案
使用内在变量不是 脚本编制中最快的方法.(它很久以前就在GMS 1中使用.)
Using intrinsic variables is not the fastest way to go about this in scripting. (It used to be in GMS 1 a long time ago.)
实际上,如果您将它作为切片上的for循环来进行,则比使用命令菜单要快 ,这很可能是由于调用该命令和标记结果的开销所致./p>
In fact, if you do it as a for loop over slices you are a bit faster than with the command menu - most likely due to the overheads of calling that command and tagging the results.
// create an image of 512x512x200, assign random numbers
number sx = 512
number sy = 512
number sz = 200
image img := RealImage("",8,sx,sy,sz)
img = random();
img.SetName( "test" );
img.ShowImage();
number start_tick, end_tick, calc_time;
// do volume projectin with menu command : Volume>Project>Project Along Z
start_tick = GetHighResTickCount();
ChooseMenuItem( "Volume", "Project", "Project Along Z"); // do z-projection
end_tick = GetHighResTickCount();
// calculate execution time
calc_time = CalcHighResSecondsBetween( start_tick, end_tick );
// display result image
Image img_projZ1 := GetFrontImage();
img_projZ1.SetName( "Z-proj.#1 (" + calc_time.format("%.2fs") + ")");
img_projZ1.ShowImage();
// do volume project in z-direction (using intrinsic variable iplane)
image img_projZ2 := img_projZ1.ImageClone()
img_projZ2 = 0
start_tick = GetHighResTickCount();
for(number i=0; i<sz; i++)
img_projZ2 += img.slice2(0,0,i,0,sx,1,1,sy,1)
end_tick = GetHighResTickCount();
// calculate execution time
calc_time = CalcHighResSecondsBetween( start_tick, end_tick );
// display result image
img_projZ2.SetName( "Z-projection#1 (" + calc_time.format("%.2fs") + ")");
img_projZ2.ShowImage();
但是,要回答有关命令的问题:GMS 3.4有一个命令称为:
However, to answer your questions for a command: GMS 3.4 has a command called:
RealImage Project( BasicImage img, Number axis )
RealImage Project( BasicImage img, Number axis, Boolean rescale )
void Project( BasicImage img, BasicImage dst, Number axis )
void Project( BasicImage img, BasicImage dst, Number axis, Boolean rescale )
但是此命令尚未正式记录,因此可以随时重命名/删除.
But this command is not officially documented, so it might be renamed/removed at any time.
这篇关于快速累积总和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!