Skip to main content
QUICK REVIEW

[Paper Review] Matlab vs. OpenCV: A Comparative Study of Different Machine Learning Algorithms

Ahmed A. Elsayed, Waleed A. Yousef|arXiv (Cornell University)|May 3, 2019
Machine Learning and Data ClassificationComputer Science7 citations
TL;DR

This paper compares the execution speed of Matlab and OpenCV for 20 real-world machine learning datasets using 10 different algorithms. OpenCV consistently outperforms Matlab, with speedups exceeding 80x in some cases, demonstrating that native C++ implementations deliver significantly faster performance than high-level environments like Matlab, especially for computationally intensive tasks in machine learning and computer vision.

ABSTRACT

Scientific Computing relies on executing computer algorithms coded in some programming languages. Given a particular available hardware, algorithms speed is a crucial factor. There are many scientific computing environments used to code such algorithms. Matlab is one of the most tremendously successful and widespread scientific computing environments that is rich of toolboxes, libraries, and data visualization tools. OpenCV is a (C++)-based library written primarily for Computer Vision and its related areas. This paper presents a comparative study using 20 different real datasets to compare the speed of Matlab and OpenCV for some Machine Learning algorithms. Although Matlab is more convenient in developing and data presentation, OpenCV is much faster in execution, where the speed ratio reaches more than 80 in some cases. The best of two worlds can be achieved by exploring using Matlab or similar environments to select the most successful algorithm; then, implementing the selected algorithm using OpenCV or similar environments to gain a speed factor.

Motivation & Objective

  • To evaluate and compare the execution speed of Matlab and OpenCV for implementing various machine learning algorithms.
  • To identify performance bottlenecks in high-level scientific computing environments like Matlab when scaling to large datasets or high experiment counts.
  • To provide empirical evidence supporting the use of native C++ libraries like OpenCV for deploying final machine learning models after algorithm selection in high-level environments.
  • To guide researchers and practitioners in choosing between development convenience (Matlab) and runtime efficiency (OpenCV) based on project phase and performance requirements.

Proposed method

  • The study evaluates 10 machine learning algorithms—classification trees, naive Bayes, boosting, random forests, and KNN—across 20 real-world datasets from the UCI Machine Learning Repository.
  • For each algorithm, equivalent implementations were developed in both Matlab and OpenCV (C++), ensuring feature and hyperparameter equivalence across platforms.
  • Execution times were measured over 1000 runs per algorithm-dataset combination to ensure statistical stability and convergence.
  • The performance ratio (log of execution time in Matlab divided by OpenCV) was computed and visualized to compare relative speeds across all experiments.
  • The analysis accounts for dataset-specific factors such as feature dimensionality, sample size, and training set usage, particularly in KNN where performance varied significantly.
  • The study uses standardized data formats and ensures consistent preprocessing and model configuration between the two platforms to isolate language and environment effects.

Experimental results

Research questions

  • RQ1How do Matlab and OpenCV compare in execution speed for common machine learning algorithms across diverse real-world datasets?
  • RQ2What factors influence the performance gap between high-level environments (Matlab) and low-level optimized libraries (OpenCV)?
  • RQ3In which scenarios does Matlab outperform OpenCV, and under what conditions does OpenCV dominate?
  • RQ4To what extent does algorithm complexity, dataset size, or feature dimensionality affect the relative performance of Matlab versus OpenCV?
  • RQ5Can the performance gap be mitigated by algorithm-specific optimizations, such as dimensionality reduction or efficient data structures in KNN?

Key findings

  • OpenCV outperforms Matlab in execution speed across all 20 datasets and 10 algorithms, with speedup ratios exceeding 80x in some cases.
  • The KNN algorithm on the Pen-Based Recognition dataset is the only case where Matlab outperforms OpenCV, likely due to the interplay of high dimensionality and training set characteristics.
  • When applied to high-dimensional datasets like Arcene (10,000 features), reducing dimensionality to 16 features significantly narrowed the performance gap, with the log ratio dropping from 0.8 to 0.5.
  • For datasets like Madelon (500 features), the performance gap was reduced from a log ratio of 0.9 to 0.06 when using only 16 dimensions, indicating that dimensionality has a strong impact on relative performance.
  • The study confirms that OpenCV's C++-based implementation delivers superior runtime efficiency, especially for computationally intensive tasks such as model training and inference.
  • The results support a two-phase workflow: use Matlab for rapid prototyping and model selection, then re-implement the final model in OpenCV for production deployment to achieve optimal speed.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.