You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I made some tests on the builtin ArrayFuncs.Flatten function and found out that the performance is very slow on FITS images with a higher resolution and 3 image planes, where the 3 AXIS parameters are for example:
I made a simple test code which demonstrates it perfectly and also a possible solution for comparison.
As a test FITS file I used this one.
usingnom.tam.fits;usingnom.tam.util;usingSystem.Diagnostics;namespaceCSharpFits_test{internalclassProgram{staticvoidMain(string[]args){Console.WriteLine("CSharpFits ArrayFuncs.Flatten tests.");Console.WriteLine();varfpath=@"C:\Users\hellerl1\Pictures\Sas.fits";varfits=newFits(fpath);varhdu=(ImageHDU)fits.ReadHDU();varaxes=hdu.Axes;if(axes.Length!=3||hdu.BitPix!=BasicHDU.BITPIX_BYTE){Console.WriteLine("For this test an 3D cube FITS image with 8bit data is expected!");return;}varwidth=axes[2];varheight=axes[1];Console.WriteLine($"Number of axes: {axes.Length}");Console.WriteLine($"Number of bits per pixel per plane: {hdu.BitPix}");Console.WriteLine($"Image size: {width} x {height}");varplanes=(Array[])hdu.Kernel;// get list of planes from 3D cube FITS image HDUvarplane0=planes[0];// the Blue plane from BGR planesConsole.WriteLine();Console.WriteLine("Builtin flatten test:");varsw=Stopwatch.StartNew();varplane0data=(byte[])ArrayFuncs.Flatten(plane0);// flatten plane0 jagged array to byte arraysw.Stop();Console.WriteLine($"Flatten#1 result: {sw.Elapsed.TotalSeconds} seconds");Console.WriteLine();Console.WriteLine("Custom flatten test:");plane0data=newbyte[width*height];varc=0;sw.Restart();foreach(varrowin(Array[])plane0)foreach(varcolin(byte[])row)plane0data[c++]=col;// element wise flattensw.Stop();Console.WriteLine($"Flatten#2 result: {sw.Elapsed.TotalSeconds} seconds");fits.Close();}}}
Result - output:
CSharpFits ArrayFuncs.Flatten tests.
Number of axes: 3
Number of bits per pixel per plane: 8
Image size: 2048 x 1364
As you can see from the output, the simple element-wise array flattening in the second test is by 2 orders of magnitude faster than the builtin one in the first test. I know the builtin flatten function is a general one for all cases and data formats but for sure it can be improved.
BR,
Ladislav
The text was updated successfully, but these errors were encountered:
Hi @rwg0, @elendil-software
I made some tests on the builtin ArrayFuncs.Flatten function and found out that the performance is very slow on FITS images with a higher resolution and 3 image planes, where the 3 AXIS parameters are for example:
I made a simple test code which demonstrates it perfectly and also a possible solution for comparison.
As a test FITS file I used this one.
Result - output:
As you can see from the output, the simple element-wise array flattening in the second test is by 2 orders of magnitude faster than the builtin one in the first test. I know the builtin flatten function is a general one for all cases and data formats but for sure it can be improved.
BR,
Ladislav
The text was updated successfully, but these errors were encountered: