The performance of an algorithm depends on the hardware platform it was designed .... ule for development with no performance optimization and switch to the target ... Considering mobile platforms running on Android, which is using a Linux ...
Microcirculation Detection with Correlation Mapping Processing: A Review with MATLAB, Java and Python Kai Neuhaus1, James McGrath1, Hrebesh M. Subhash1, Martin Leahy1,2 1
Tissue Optics and Microcirculation Imaging facility, National Biophotonics and Imaging Platform, National University of Ireland, Galway 2 Royal College of Surgeons (RCSI), Dublin, Ireland
Abstract With the increasing availability of mobile computing platforms, such as smart-phones, the desire to use them for image reconstruction is growing. The imaging capabilities are determined by the algorithm and its efficiency to access the available hardware resources of the mobile platform, therefore it is desirable to understand how different software environments support the development and optimization of algorithms for imaging. MATLAB, Java and Python are compared based on their capabilities to implement and optimize the correlation mapping algorithm. Correlation mapping is a post-processing algorithm applied to OCT volumes and utilizes the spatio-temporal variations in intensity to distinguish dynamic from static scatterers. It has been shown to be very useful for visualization of microcirculation structures in biological tissue. It was found that MATLAB is sufficient to compute algorithms and reconstruct images with good performance on desktop platforms, but requires a significant amount of expertise in low-level programming languages for implementation on mobile platforms. Java requires more training in advance but provides excellent processing speeds for imaging, and is supported by Android for implementation of algorithms on mobile platforms. Python combines support of advanced programming features known from low-level languages with the simplicity of scripting known from MATLAB. But it also allows easy optimization of algorithms for image processing, and has support to access wide range of language libraries to improve speed and portability of code towards different hardware environments.
2. Performance and Usability Methods of Comparison To compare the efficiency of programming environments one obvious parameter is to measure the speed of the algorithm implemented. The correlation-mapping (CM) algorithm was re-implemented[5] for each programming environment and then run for different data volumes. A simplified description of the CM algorithm (Fig. 1) indicates two image arrays and the movement of a kernel matrix over the images and the calculation of the correlation value for each position. kernel Image A
Image B
corr
Processing Speed vs Data Volume matlab (linux) matlab (win) NumPy (linux) NumPy (win) NumPy (linux, ctypes) java (linux) java (win,openGL)
00
00
16
data volume (kSamples)
14
00
12
00
10
0 80
0 60
40
0
Figure 3: Python using the MayaVi module to render 3D volumes.
0
The three programming environments were selected based on popularity in science and engineering and their capability to serve multiple hardware platforms. A large amount of other programming environments are available, such as C/C++, but were not included, as they are low-level languages and can be managed by the discussed tools. Other high-level languages, to mention only a few, are Mathematica (http://www.wolfram.com/mathematica/), Julia (www.julialang.org) and Octave (www.gnu.org/software/octave). Mathematica is not further considered as it is similar to MATLAB but with more emphasis on symbolic mathematical computation. Octave is a clone of the core language of MATLAB and provides an open source alternative to running MATLAB-code, but it does not provide all the toolboxes. Julia is advertised as a high-speed and high-level programming environment with a syntax similar to Python. Due to Python’s capability to call Julia functions and the capability to import a wide variety of other programming environments, Python was considered for further discussion in this review. For performance evaluation of Python the NumPy[4] module was used. NumPy was selected, as it is the primary standard module for mathematical computation and matrix manipulation.
160 140 120 100 80 60 40 20 0
20
Programming environments such as Java target the hardware at low-levels to achieve highest performance. Java is of particular interest due its multi-platform capabilities by providing run-time engines for a wide variety of hardware platforms, such as smartphones [1]. Java[2] was designed with the goal to run “everywhere”, which is somewhat true, as it is possible to design a run-time engine for any new hardware platform if required. MATLAB is a commercial system for high-level algorithmic design used in science and engineering, and promising sufficient performance on desktop systems and provides a large choice of add-on modules that can be purchased. Python is an open-source general purpose “gluing”[3], high-level scripting and programming language that intends to connect algorithmic tools from a wide choice of libraries and other languages available. It does not provide performance on its own but rather harvests the performance of native libraries that can be conveniently accessed using modules.
The speed measurements were performed on a Windows 7 64 bit environment (i7-2600, 3.4 GHz, 8 GB RAM) and a Linux environment with Mint 17.1 (kernel 3.16, i7-4710HQ, 3.4 GHz, 16 GB RAM) shown in Fig. 2. For the algorithmic programming and data array handling with Python the mathematical toolbox NumPy was used, as indicated in the figure.
0
The performance of an algorithm depends on the hardware platform it was designed for and the tool it was designed with. Computing systems available nowadays are powerful enough to compensate for penalties due to naive design patterns and even smart-phone devices move into the focus for medical data processing.
Speed Measurements
processing time (s)
1. Introduction
to extend the functionality for visualizing scientific data within the native environment. For instance to show isometric 3D volume data from a set of image-slices the MayaVi[7] module is a nice example for the multitude of options with Python (Fig. 3).
Figure 2: Performance comparison for non-optimized code. The results show the problem if relying solely on evaluation of algorithmic performance in a monolithic programming environment. Perhaps the speed characteristics for Java are most dramatic, as it is not obvious how the underlying run-time engine can compensate for inefficient code structures. The Java implementation certainly shows an impressive performance on the particular hardware and software environment but may skew the expectations of performance on mobile platforms. Considering that Android is working with the Linux kernel and Dalvik as Java run-time environment the expectations of the speed for different algorithms can vary substantially[6]. Lin, Lin, Dow, et al. reports an average difference of performance of 34 percent between algorithms and coding in Java or native code. performs on both machines well, although it cannot challenge the Java performance. The reasons for the slower speed are most likely found in the additional convenience functions to simplify the programming and coding of array structures. MATLAB
The penalties for convenient programming with array structures using NumPy and Python are even more pronounced. The NumPy module for Python is a very high-level coding frame-work paying most attention to algorithmic analysis and human readable code. The actual philosophy of Python in this case, is to use one module for development with no performance optimization and switch to the target module later on or generate native code with other extensions available. As an example the ctypes module was used to set the variable types to C-code equivalents and let the module compile parts of our code into C. In particular no actual C-code was touched and all programming remained in the Python domain and the processing speed could be increased matching nearly that of the MATLAB processing speed. More significant may be, that with Python a large set of modules support the export to Windows, Mac and Linux platforms, or the direct call of native function from system libraries. A similar approach can be taken with MATLAB and the generation of C-code with the MEX compiler toolbox can accelerate algorithms in development. However, at the time of writing this document, no methods were known to generate code for mobile platforms directly. Although, it is to expect that this will change at some time in the future.
A more difficult and debatable subject is about the coding efficiency, meaning how much code needs to be written for a given problem. For Python it is reported that it requires two to three times less code and about 50 percent less time to produce a solution for a given problem compared to Java and C/C++[8]. A survey of top forty eight US universities concluded with the recommendation to use Python “as a preferred language” [9]. Unfortunately MATLAB was not included in the report, but some extrapolation based on the similar syntax compared to Java may help to estimate some value.
4. Conclusion In conclusion it was shown that the measurement of raw speed on one hardware platform may not be sufficient to predict the performance of an algorithm if ported towards another hardware. The speed results with Java illustrate the danger of over estimating the performance, which was excellent on a Windows desktop computer but showed considerable reduction of performance on a Linux system. Considering mobile platforms running on Android, which is using a Linux kernel variant, more elaborate studies need to be included before an algorithm can be validated. The ability to test algorithms on different environments and hardware platforms may required a significant amount of software engineering expertise. Although MATLAB provides tools to generate C-code to accelerate MATLAB-code, such code is not easily portable to other hardware platforms. Python is an environment to “glue” different software libraries together, in compiled form or as an code base. Using Python’s standard library NumPy to do matrix calculations is not the most performant solution, whereas it is excellent during algorithmic design. For increased performance one can select one of the modules available from an continuous growing online database. Python provides also modules to generate code for Mac, Linux and Windows, which makes it a competitive system in a fast paced environment marked with quickly changing hardware requirements and the coding efficiency will help to develop more rapidly robust algorithms[10]. “Python has now entered a phase where its clearly a valid choice for high-level scientific code development, and its use is rapidly ´ growing.” Perez, Granger, and Hunter (2011)
References [1] T.-M. Grønli, J. Hansen, and G. Ghinea, “Android vs windows mobile vs java ME: a comparative study of mobile development environments,” in Proceedings of the 3rd International Conference on PErvasive Technologies Related to Assistive Environments, ser. PETRA ’10, New York, NY, USA: ACM, (2010). 45:1–45:8, [2] J. Gosling and H. McGilton, “The java language environment,” Sun Microsyst. Comput. Co., vol. 2550. (1995). ´ [3] F. Perez, B. E. Granger, and J. D. Hunter, “Python: an ecosystem for scientific computing,” Comput. Sci. Eng., vol. 13. No. 2, pp. 13–21, (Mar. 1, 2011). [4] C. Bauckhage, “NumPy / SciPy recipes for data science: computing the kullback-leibler divergence between generalized gamma distributions,” (2015).
3. Modules for Visualization and Research Figure 1: Simplified graphical representation of the correlationmapping algorithm. The coding was kept naive, meaning no attention to particular structural optimization or reduction of redundancies was applied, as it is often encountered for first generation algorithms.
provides 3D presentation capabilities including a separate program called Viewer3D on MatlabCentral. While with Java one would have the potential to program such a tool oneself, and ImageJ (www.imagej.net) is an good example of Java’s GUI and image processing capabilities. Although, ImageJ is capable to interpret Python-script as well, available modules for Python allow us MATLAB
[5] J. Enfield, E. Jonathan, and M. Leahy, “In vivo imaging of the microcirculation of the volar forearm using correlation mapping optical coherence tomography (cmOCT),” Biomed. Opt. Express, vol. 2. No. 5, p. 1184, (Apr. 13, 2011). [6] C.-M. Lin, J.-H. Lin, C.-R. Dow, and C.-M. Wen, “Benchmark dalvik and native code for android system,” in 2011 Second International Conference on Innovations in Bio-inspired Computing and Applications (IBICA), (Dec. 2011). Pp. 320–323. [7] P. Ramachandran and G. Varoquaux, “Mayavi: 3d visualization of scientific data,” Computing in Science & Engineering, vol. 13. No. 2, pp. 40–51, (2011). [8] L. Prechelt, “An empirical comparison of c, c++, java, perl, python, rexx and tcl,” IEEE Comput., vol. 33. No. 10, pp. 23–29, (2000). [9] A. Raju and S. Annigeri, “Computing in engineering education: the current scenario,” in 2014 International Conference on Contemporary Computing and Informatics (IC3I), (Nov. 2014). Pp. 130–134. ´ J. Luque, A. Gomez-Jaime, ´ [10] M. Moron, E. Casilari, and A. D´ıaz-Estrella, “Prototyping of a remote monitoring system for a medical personal area network using python,” in 3rd International Conference on Pervasive Computing Technologies for Healthcare, 2009. PervasiveHealth 2009, (Apr. 2009). Pp. 1–5.
This work was supported by NUI Galway, Galway University Foundation, the University of Limerick Foundation, the National Biophotonics Imaging Platform (NBIP) Ireland funded under the Higher Education Authority PRTLI Cycle 4, co-funded by the Irish Government and the European Union - Investing in your future, and Compact Imaging, Inc. All authors have a financial interest in Compact Imaging, Inc.