Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Matlab so popular in the computer vision community even with OpenCV being so complete? [closed]

Tags:

I've noticed that Matlab is very popular among the computer vision and image processing community still to this day, even though OpenCV is a very mature package for C++. I've never used Matlab, but looking at it I see no advantages over OpenCV in C++. It's so commonly used however that I'm considering picking it up.

Why is it so popular among this crowd? What are its advantages over OpenCV?

like image 888
zebra Avatar asked Jan 12 '12 00:01

zebra


1 Answers

I am a phD student in computer vision, and I've already answered about the comparison between matlab and python for scientist in this question: What is MATLAB good for? Why is it so used by universities? When is it better than Python?

I will update my answer for the comparison between matlab and opencv for computer vision:

I used to code only with C++/OpenCV a while ago, but since the begining og my phD (3 years a go), I code only in Matlab. so I know well the topic.

There is ONE reason why matlab is so good and so widely used, compared to opencv:

EXTREMELY FAST CODING

Personally, I code around 10 times faster in matlab than in OpenCV/C++, and there is much less bug at the end.

1) Computer Vision Researchers need fast prototyping

In research environment, we have (hopefully) often new ideas, and we want to test them really quick to see if it's worth keeping on in that direction. And most often only a tiny sub-part of what we code will be useful. Moreover it's often not possible to guess beforehand if an idea is going to work or not.

Matlab is often a bit slower at execution time and opencv is definitely the fastest for running time, but we don't care much. Because we don't know in advance what method is going to be successful, we have to try many things, so our bottle neck is programming time, because our code will most often run a few times to get the results to publish, and that's all.

So let's see how matlab can help to improving programming time.

2) Everything I need is already there

Matlab has really a lot of functions that I need, so that I don't have to reinvent them all the time:

change the index of a matrix to 2d coordinate: ind2sub extract all patches of an image: im2col; compute a histogram of an image: hist(Im(:)); find the unique elements in a list unique(list); add a vector to all vectors of a matrix bsxfun(@plus,M,V); convolution on n-dimensional arrays convn(A); calculate the computation time of a sub part of the code: tic; %%code; toc; graphical interface to crop an image: imcrop(im);

The list could be very long... And they are very easy to find by using the help.

However, conserning the pure computer vision functions, I think that the core Opencv is a bit more exhaustive, than matlab plus toolboxes. But Nowadays, so many researchers publish their source code in matlab that if you want to test the latest discovery you basically have to use matlab.

3) No C++ specific problems

No need to allocate and free memory. Matlab does that for you, so you can focus on your work.

No buffer overflow. So, no more long time trying to find out where it crashes. Matlab stops automatically, and tells you where the code tries to get a value outside of the matrix range.

No compilation time...

No header to write...

4) IDE

An example: I launch a script. It produces an error because of a matrix. I can still execute code with the command line. I visualize it doing: imagesc(matrix). I see that the last line of the matrix is weird. I fix the bug. All variables are still set. I select the remaining of the code, press F9 to execute the selection, and everything goes on. Debuging becomes fast, thanks to that.

Matlab underlines some of my errors before execution. So I can quickly see the problems. It proposes some way to make my code faster.

With OpenCV/C++/Visual Studio, I can debug. But this debugger does not allow me to execute code during the debugging, so I cannot for instance visualize matrices and so on.. So in practice, I have to copy paste some code to dump matrices, to check where is the error. This is very painful.

There is an awesome profiler included in the IDE. KCahcegrind for C++ is such a pain to use compared to that.

I wrote more there: Are there any alternative editors for .m files?

5) Concise code

Matlab code is more consize, which mean easier to debug, to read, to understand and: the code looks like my formulas.

To normalize all the columns of a matrix ( which I need all the time), I do: bsxfun(@times,A,1./sqrt(sum(A.^2)))

To remove from a matrix all colums with small sum:

A(:,sum(A)<e)=[]

To do the computation on the GPU:

gpuX = gpuarray(X); 
%%% code normally and everything is done on GPU

To paralize my code:

parfor n=1:100
%%% code normally and everything is multi-threaded

What language can beat that?

And of course, I rarely need to make loops, everything is included in functions, which make the code way easier to read, and no headache with indices. So I can focus, on what I want to program, not how to program it.

6) Plotting tools

Matlab is famous for its ploting tools. They are very helpful. OpenCV has just the basic plotting functions.

7) Excellent documentation

And it's very easy to acces it, by typing doc

PS: And what I hate with matlab: its price

like image 153
Oli Avatar answered Nov 03 '22 18:11

Oli