Somme cumulative rapide?

Sep 28 2020

La commande de menu "Volume> Projection> Projet le long de Z" est très rapide par rapport au script (même avec des variables intrinsèques). La somme cumulée (projection) d'un volume d'image 3D de 512x512x200 dans la direction z prend <0,5 sec. par rapport à> 8 sec. en utilisant un script. Existe-t-il un accès direct à cette fonction de script autre que l'utilisation de ChooseMenuItem ()?

Exemple de script montrant la différence:

// 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();

Réponses

1 BmyGuest Sep 29 2020 at 00:16

L'utilisation de variables intrinsèques n'est pas le moyen le plus rapide d'y parvenir dans les scripts. (Il était dans GMS 1 il y a longtemps.)

En fait, si vous le faites comme une boucle for sur des tranches, vous êtes un peu plus rapide qu'avec le menu de commande - probablement en raison des frais généraux liés à l'appel de cette commande et au marquage des résultats.

// 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();

Cependant, pour répondre à vos questions pour une commande: GMS 3.4 a une commande appelée:

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 )

Mais cette commande n'est pas officiellement documentée, elle peut donc être renommée / supprimée à tout moment.