快速累积和?

问题描述

与脚本编写相比,菜单命令“体积>投影>沿Z投影”确实非常快(即使使用内部变量)。 z方向上512x512x200的3D图像体积的累积和(投影)需要 8秒相比。通过使用脚本。除了使用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,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中使用。)

实际上,如果您将它作为切片的for循环进行,则比使用命令菜单要快 ,这很可能是由于调用该命令和标记结果的开销所致。 / p>

// 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,i,1,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有一个命令 称为:

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,Boolean rescale )

但是此命令尚未正式记录,因此可以随时重命名/删除。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...