Schnelle kumulative Summe?
Der Menübefehl "Lautstärke> Projektion> Projekt entlang Z" ist im Vergleich zu Skripten sehr schnell (auch bei intrinsischen Variablen). Die kumulative Summe (Projektion) eines 3D-Bildvolumens von 512 x 512 x 200 in z-Richtung dauert <0,5 Sekunden. im Vergleich zu> 8 sek. mithilfe eines Skripts. Gibt es einen anderen direkten Zugriff auf diese Skriptfunktion als die Verwendung von ChooseMenuItem ()?
Skriptbeispiel, das den Unterschied zeigt:
// 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();
Antworten
Die Verwendung von intrinsischen Variablen ist nicht der schnellste Weg, um dies in Skripten zu erreichen. (Es war vor langer Zeit in GMS 1.)
Wenn Sie dies als for-Schleife über Slices tun, sind Sie tatsächlich etwas schneller als mit dem Befehlsmenü - höchstwahrscheinlich aufgrund des Overheads beim Aufrufen dieses Befehls und beim Markieren der Ergebnisse.
// 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();
Um Ihre Fragen zu einem Befehl zu beantworten: GMS 3.4 verfügt über einen Befehl mit dem Namen:
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 )Dieser Befehl ist jedoch nicht offiziell dokumentiert und kann daher jederzeit umbenannt / entfernt werden.