4

I want to learn practical image processing from scratch/basics in easy way. Which software will be helpful in this regard? Matlab or python?

DSP_CS
  • 1,910
  • 2
  • 29
  • 65

5 Answers5

11

[Comparison with cars at the end] For learning from scratch, I would not suggest a programming language alone, but instead the couple "teaching materials" (book, lecture notes) + "exercises with a specific programming language". So if you find a book that you like on "Python for computer vision with exercises" or "Image processing theory and practice with Matlab, that could be interesting starting points. Also, your programming tastes and skills may evolve, and learning a first programming language helps you learning a second one in general. But laziness sometimes drives you to sticking to your first language, reusing old librairies. Last, the purpose is important. In my case, I mostly engineer algorithms as prototypes and proofs of concepts, that can stay as them, or are turned into "solid programs" by people that are better at, and like better, programming with the rules-of-art in lower levels languages, depending on the target.

To that respect, Matlab is great at designing and fine tuning algorithms, possesses a lot of documentation and help that you can follow step-by-step, and enjoys a long list of contributed toolboxes, esp. at MatlabCentral FileExchange. When the workflow is set, if you care of speed, efficiency, etc., it is time to pass the algorithmic prototyping over to real programmers (C++, or lower level, which I can't do).

Python now has a large community, and has developed toolsets like Scikit-Image, and there is a tutorial for instance at Scikit-image: image processing. It is also interfaced with OpenCV.

Globally, as long as you grow solid image processing skills, I would think what mostly differ between Matlab and Python are the cost and the trendiness. On my side, I would switch to Python for machine learning and data science, but I will stick to Matlab for most of my signal processing and image analysis works for a while.

You can also use (free) open source software, with contributed toolboxes and plugins, that often benefit from external publications. I would suggest:

For comparisons (with cars):

MATLAB [...] It’s probably still the easiest to learn for basic numerical tasks. Meticulous documentation and decades of contributed learning tools definitely matter.

MATLAB is the BMW sedan of the scientific computing world. It’s expensive [...] rock-solid [...] attracts a disproportionate amount of hate.

Python is a Ford pickup. It’s ubiquitous and beloved by many (in the USA). It can do everything you want, and it’s built to do some things that other vehicles can’t. Chances are you’re going to want to borrow one now and then. But it doesn’t offer a great pure driving experience.

Julia is a Tesla. It’s built with an audacious goal of changing the future, and it might. It may also become just a footnote. But in the meantime you’ll get where you are going in style, and with power to spare.

Laurent Duval
  • 31,850
  • 3
  • 33
  • 101
  • 1
    Laurent, you might be interested in this: https://www.nature.com/articles/d41586-019-02310-3 – MBaz Sep 23 '19 at 00:01
  • I was very exited with Julia at the beginning. However, it seems it takes time to have an field ecosystem around it. I admit I did not check whether there is a good image processing toolbox by now – Laurent Duval Sep 23 '19 at 13:47
  • 1
    Very well explained – DSP_CS May 17 '20 at 18:56
  • 1
    If comfortable, will you please try to update your answer keeping in view latest and most updated trends. – DSP_CS Mar 02 '23 at 14:20
7

I have spent the first 20 years of my career working extensively in MATLAB for signal processing applications. Six years ago I gravitated over to Python out of curiosity and it has since completely replaced Matlab as my tool of choice meeting all my needs for signal processing.

Matlab still rules in integrated hardware and co-simulation solutions, and I have access to both tools, yet I prefer using Python for general signal processing simulation and analysis.

I wanted to share here some main points that influenced me and why I am such a big fan of Python for this application space.

  • It's Free (although Octave served that purpose for me, but Octave is slower than Matlab)

  • It's comparable to Matlab in speed, both in writing an application and its execution.

  • It's user friendly, once you really understand its functionality and features. Jumping in without actually learning it can be very frustrating if coming from Matlab; but in particular once you learn how well and universally it handles iteration, it is quite beautiful!

  • It's supported by a MUCH LARGER user community.

The above main points are my perceptions based on my own experience which is always evolving and open to change, but let me also share some supporting evidence that have influenced my thinking to date (beyond my personal experience with both tools). I am not overly biased toward any of the tools other than these reasons; each on their own are fantastic accomplishments by the people involved in putting them together and I would be happy to be stuck on an island with any of these tools (between Matlab, Octave and Python) if it was an island where I still needed to solve challenging signal processing related problems. (The island of misfit transforms perhaps).

Benchmarks with Matlab

At this link Rob Hicks has benchmarked Matlab with Python/Numpy (last updated 2015) with this result:

Benchmark Matlab vs Python

For the plot above, "LA" denotes linear algebra test models where Matlab wins on speed while the other lines where Python wins are with statistical models. A later plot as you read down the post shows that under parallel operation distributed across multiple processor cores, Matlab still wins with the LA models but with marginal difference in that scenario.

Julia has been posting benchmarks comparing Octave, Matlab and Python that captured my interest. This chart was made by the Julia folks (surprise, they are at the top of the run-time speed scale), but of interest to me was something I personally wanted to see-- how does Python compare to Matlab, and Matlab to Octave. So I was pleased to see that in considering switching from Matlab to Python that the speeds are comparable. Matlab is faster in some categories and slower than others, but overall the processing speed is similar in contrast to Matlab vs Octave. Not that Python is a choice when speed is the ultimate concern but I did want to know if there would be a significant penalty. I see that over time the reported results from Julia are changing (here is an earlier one from 2017) and not sure if that has to do with different versions of the tools or changes in the testing approach.

Recent benchmark from Julia captured 4/30/2022

I am motivated to do my own benchmarking specific to common applications in signal processing since I have access to all three tools, perhaps as a Github repository as Chris Luengo has suggested in the comments. I like that idea, and will post a link here if progress is made on that front, or if I find other existing benchmarks more specific to signal processing tools.

Much Larger User Community

Python is supported by a very large community in many areas beyond where Matlab participates (web design for example). The reason that it is a general purpose software development tool and not reserved just for mathematical algorithm development is specifically an advantage to building a larger community, given that with the right libraries (numpy and scipy in particular) it still provides all the powerful mathematical algorithm development with vector processing similar to Matlab. It is widely used in many fields and applications including specifically scientific computing and engineering, but has a broad user base of different disciplines. Given it is an open source user supported tool this is a huge strength in quickly finding the help you need to questions, or the tool you need for any given application (in most cases you can find it rather than build it, or build on it). This also contributes to writing applications faster. Below are some interesting datapoints suggesting a scale on the size of the relative communities:

The plot below was generated at the time of writing this at this link. These are the trending results for questions based on different languages posted to Stack Overflow. Based on the importance to me of a large user community (and the advantages I have experienced from that), I won't be jumping over to Julia anytime soon according to these same results, but could be a promising language to consider in the future:

Stack Overflow Trends

And similarly based on worldwide searches using Google Trends results in:

Google trends

And this Blog result from Codingdojo.com was also interesting, although it didn't include MATLAB:

Worldwide jobs

So the above points were "frosting on the cake" once I understood that I could easily create all the signal processing applications and analysis, with all the graphics and integrated development features I enjoyed with MATLAB, with a very intuitive easy to read and write language.

Dan Boschen
  • 50,942
  • 2
  • 57
  • 135
  • 3
    MATLAB is definitely much, much faster than Python. Code that loops over individual pixels is easily 100x as fast in MATLAB, which has a built-in JIT. In Python you’d need to use Numba for similar performance. The Julia benchmarks are very biased, the maintainers seem to have something against MATLAB. I tried to get them to fix MATLAB code in their benchmarks some years back, but they didn’t want to have it represented fairly, as it would remove most of Julia’s advantage (of course they didn’t acknowledge that, but it was clear to me). – Cris Luengo Apr 30 '22 at 15:39
  • 1
    @CrisLuengo not sure that's true, using Numpy for vector based processing rather than "Looping". However I am certainly open to having been mislead by the benchmark shown (although I already saw from our MBaz here that Julia is MUCH faster than python and Matlab from his own testing). But how about we come up with some of our own bench mark cases; I have access to both tools and we can get to the bottom of that ourselves. I'm not biased toward either tool beyond these perceived advantages I list. – Dan Boschen Apr 30 '22 at 15:45
  • Actually, it seems you didn’t post the graph from the Julia benchmarks. That one shows MATLAB as significantly faster than Python except for I/O. But the names of the benchmarks do match in part. Weird! Where is your graph from? – Cris Luengo Apr 30 '22 at 15:46
  • Using vectorized operations over matrices you’d see slightly better performance in MATLAB, nothing to write home about. And that is how we use both MATLAB and Python ideally. But the Python interpreter is slower than the MATLAB interpreter, because of the JIT. Python has a more efficient function call, I think, but looping is definitely much slower. Glad to help you put together some relevant benchmarks. – Cris Luengo Apr 30 '22 at 15:49
  • @CrisLuengo Ah interesting, it was from the exact same link but in early 2020; perhaps different Matlab versions and they have addressed the speed issue. I have Matlab R2019B, and Octave 4.4.1, and Python 3.8.6, so I could compare all three of those with some relevant benchmarks if they would be easy to code up. That would be very interesting and perhaps put some perceptions to rest. – Dan Boschen Apr 30 '22 at 15:57
  • @ChrisLuengo Seems my capture was much earlier, here it is on 10/22/2017 https://web.archive.org/web/20171022030430/https://julialang.org/benchmarks/ with Matlab 2017A vs Python 3.46-- seems it jumps all over the place so yes I would be very interested in running my own benchmarks and specific to signal processing (something I always wanted to do but when I first saw this I felt it was done for me...) How do we proceed? Here in this Q&A or should I open a new one titled "benchmarks of Python and Matlab for Signal Processing"? Meanwhile I am going to remove "The Faster Than Matlab" parts – Dan Boschen Apr 30 '22 at 16:41
  • Python isn't even close to MATLAB speed wise. For BLAS / LAPACK in case they both use MKL they are comparable. For functions written in auxiliary language they are the same. But for pure Python vs. MATLAB code, they are not even close since Python has, at the moment, not JIT. You may get that using Numba which is amazing in some cases, but pure Python vs. MATLAB isn't even close. – Royi Apr 30 '22 at 18:26
  • I saw that @CrisLuengo, Wrote about performance. Moreover, community wise, I'm not sure that your assertion regarding the community holds when talking about Image Processing which is the context of the question. Probably not even in DSP. – Royi Apr 30 '22 at 18:31
  • @Royi no contest and actually no concern with “pure Python”- my interest though would be with the Python universe for scientific computing and anything I would have easy access to within open source solutions. Do the Julia benchmarks suggest differently regarding “not even close” but it is an interesting question and I want to put together some meaningful benchmarks to see what it would actually be for the types of things I do (signal processing)— I may post a another question specific to this to build on with some good additional tests once I do some basic examples – Dan Boschen Apr 30 '22 at 18:31
  • And agree my concern and thoughts are with signal processing not necessary image processing specifically- so better I migrate it to another question - stay tuned and it will be interesting / informative – Dan Boschen Apr 30 '22 at 18:32
  • From Julia's test, knowing them quite well, what you might look at is the quick sort, Fibonacci and the Pi sum. In all of them MATLAB is way ahead of Python and with recent version of MATLAB the gap is getting bigger. Hopefully, Python 3.11 will bring some improvements to the table. There is a lot of investment in Python these days, so probably within 3-5 years the language will be much faster and with the pass by reference option it might be better than MATLAB. But not at the moment. – Royi Apr 30 '22 at 18:37
  • Regarding the communities, I'd say that MATLAB's signal and image processing communities are bigger than Python's. I might be wrong, but certainly it is not close to the gap of Python community vs. MATLAB. Since every user of MATLAB is basically there for either DSP, Image Processing or Control (Not counting Simulink here).

    What I do agree is that the horizon of Python looks better than MATLAB's.

    – Royi Apr 30 '22 at 18:39
  • 2
    One more thing, Neither Julia not Python has anything close to MATLAB's plotting library. Especially when trying to explore data and not only display a static graph. MATLAB's experience is smooth with great performance. I wish MatplotLib will have the figure() element that MATLAB has with all of its tools to explore the data. – Royi Apr 30 '22 at 18:42
  • @Royi Yeah I would agree with that, within the specific application spaces where Matlab excels the communities there may be larger. What I like is in its more universal nature and modularity with the larger overall community is in the cross over tools such as graphics and plotting. Still I would like to see test cases representing the common signal processing tasks—- I wouldn’t be surprised if Matlab is faster but would be interesting to see and how much of a difference it is. – Dan Boschen Apr 30 '22 at 18:44
  • It would be good to hear from others too that do actually have a thorough knowledge and experience with both tools and do still prefer Matlab and why. I am sure they are out there (I am not saying Matlab is bad), just haven’t come across anyone yet (or when I do, they don’t actually really know Python and have a preliminary impression). – Dan Boschen Apr 30 '22 at 18:46
  • There are a lot of great plotting libraries for Python beyond matplotlib and plotly - but not sure what you mean about static plots with matplotlib - they are dynamic and interactive plots with ability to zoom and scan though the data smoothly – Dan Boschen Apr 30 '22 at 18:49
  • 1
    @DanBoschen, I have a lot of experience with Python and MATLAB. For non ML / DL task I'd chose MATLAB every day. The question is the context of Image Processing, not a genera purpose language. Regarding plotting, I know Bokeh, I know PlotLy Altair and MatPlotLib. I'm not aware of others which are engines (Not wrappers like SeaBorn). There might be more smaller ones based on WebGL. But from my experience none of them can have the smooth experience of MATLAB's figure. The data tips, Zooming, Panning, handling large data sets, hovering data, etc... – Royi Apr 30 '22 at 19:06
  • 1
    The Web based engines have great experience but struggle with large data. MATLAB has them both (It also has Plotly if needed). By the way, MathWorks is working on a web based engine as well, I hope it will stay as efficient as the current one (Hybrid of Web / Java). – Royi Apr 30 '22 at 19:07
  • Folium was the other library in addition to the ones you mentioned (good for geo-plotting). I mostly use Matplotlib and Plotly. Thanks for your insights! – Dan Boschen Apr 30 '22 at 19:12
  • Dan, maybe we can make a repository on GutHub or something like that for the benchmark. I would compare a few generic functions such as conv, as well as some code that loops over the samples (such as a naive implementation of conv), to compare various different aspects — I never like summarizing everything into a single number. :) – Cris Luengo Apr 30 '22 at 21:23
  • @CrisLuengo That's a great idea. I was thinking fft for sure, spectrum plotting and analysis, filtering, filter design (firls, remez....) – Dan Boschen Apr 30 '22 at 21:26
6

most of the people who answer questions here tend to use python or matlab.

you are more likely to get help here using those tools rather than labview.

in of itself, this doesn’t say matlab is “better”. it all depends on what is better for you.

in the distant past, matlab was restricted to double floats for all numerical representations. this made matlab a huge memory hog with images. this is no longer true.

a lot of questions posted here, concern opencv. if i were you, i would factor opencv compatibly highly.

  • Sorry dear,i m not a native english. I couldn't understand your last linepart " i would factor opencv compatibly highly" – DSP_CS Sep 21 '19 at 14:25
  • matlab historically has been slow in offering interfaces to tools outside of itself. calling R from matlab is difficult is an example. you probably will want to be able to call opencv easily from whatever tool you choose –  Sep 21 '19 at 15:15
  • 1
    @engr: "Dear" is for family members or your boyfriend or girlfriend. – JRE Sep 21 '19 at 18:54
  • @JRE got it sir – DSP_CS Sep 21 '19 at 18:55
5

MATLAB is one of the most important software inventions of the twentieth century. From a DSP point of view, its syntax is simply the best in the world. And, image processing is one of its strongest points. However, it has naturally an academic (learning & inventing, research & development) focus, and thus it avoids integration with industry standard platforms or applications. So, if you look for such ready to install hardware, embedded, or software applications, you should better consider some other or additional tools.

LabView is one such example, and its natural integration with NI produced DSP chips and platforms is probably its strongest part. Yet for core algorithm development, (where you need a lot of flexibility), you would still benefit from MATLAB or its free clone OCTAVE.

Python is a free, powerful, and expanding language. Very versatil. I don't like its syntax which simply sucks. Neverthless it's free, growing, and academically accepted with excellent Linux integration vs poor Windows support. Its packages, (such as machine learning and AI), are probably its strongest parts, and syntax is the weakest.

OpenCV is a specialised tool for unique task of image processing. It's quite popular in machine vision, or industrial automation world. I think however that, as Python packages are growing and improving day by day, they may eventually replace whole OpenCV as a package of Python in the future.

Fat32
  • 28,152
  • 3
  • 24
  • 50
  • 5
    This is a highly subjective answer. Granted, many people seem to like Matlab's syntax – fair enough, this is a matter of taste. But syntax is a pretty trivial part of languages' design space; far more important are semantics, in that regard NumPy is close to being a clone of Matlab but within a language that's much better for non-matrix stuff. Lauding Matlab as an “important software invention” because of its syntax is at any rate pretty ridiculous, it's a bit like lauding the DeLorean as one of the greatest cars of the 20th century because you like the look of its stainless steel body panels. – leftaroundabout Sep 21 '19 at 23:42
  • 3
    Not so. MATLAB's natural syntax is so powerfully, uniquely and inherently linked with linear algebra and DSP notation that it certainly deserves an oscar (for those subjective lovers) if not a nobel (for those strictly objective lovers ;-) ). I hope you didn't try to compare Matlab Development Environment with languages like C / C++ / Java / Python etc. which I deduced from your semantics argumentation. Matlab is not a software development system, rather a mathematical algorithm development environment; the de-facto choice for most academics and especially (electrical) engineers. – Fat32 Sep 22 '19 at 09:56
  • 5
    Would have Matlab chosen a $0$-based indexing, it would have been flawless :) – Laurent Duval Sep 22 '19 at 17:10
  • 3
    I'll add my own opinion to this subjective discussion: Matlab is historically very important, and the language is a huge leap in productivity compared to C or Fortran. It also has a large number of flaws that hang around its neck like a ton of bricks. Newer languages have learned from those mistakes and are much, much better than Matlab. An example of a beautiful modern language is Julia. – MBaz Sep 22 '19 at 23:56
  • 1
    @MBaz you are also making the same mistake. Matlab is not a general purpose programming language like C / C++ / Java / Python / Julia etc. Yes it has syntax and an interpreter engine but it's not a general purpose programming languge. It's intention is to provide a robust and flexible computational environment for algorithm development. This includes data input, imports, exports, plots, figures, visualisations and seamless data processing. Yet it has grown into something much more than that in time. So many toolboxes and blocksets and simulink, x-target, real-time etc.. – Fat32 Sep 23 '19 at 08:18
  • 3
    @Fat32 I know all of that; I've been using Matlab since 1997 and continue to use it today. What I think is a mistake is to ignore Matlab's warts, and to ignore better-designed, modern, often free alternatives. – MBaz Sep 23 '19 at 14:42
0

MATLAB's Image Processing toolbox is much richer than what you'd find on Python except OpenCV. OpenCV on Python doesn't feel natural yet still give you access to basically the largest library of image processing related algorithms. Usually they are also implemented quite efficiently.

When comparing them I'd say MATLAB's advantages are:

  1. Great documentation.
  2. Coherent package.
  3. Good performance per function.
  4. Graphics library.

Python advantage:

  1. Access to Deep Learning based algorithms.
  2. Python supports pass by reference which means in a pipeline of functions it might be faster.
  3. Access to OpenCV which has a lot of state of the art algorithms.
  4. Support for GPU using CuPy or PyTorch.

If you start now, probably you should go with Python.
Pay attention that if you implement something in Python to take advantage of Numba or the GPU (See CuPy).

Eric Johnson
  • 324
  • 1
  • 3
  • 16
  • I'd add MATLAB's plotting library which is superior to Python's. – Royi Apr 30 '22 at 18:43
  • “Python supports pass by reference” — MATLAB’s lazy copy means that any value passed to a function is not copied unless modified in the function (ie passed by reference). Furthermore, if written correctly, a function can modify its input data in place, with no copy made (ie same result as if passed by reference). – Cris Luengo Apr 30 '22 at 21:15
  • I am aware of those tricks. But the correct mental picture is that Python works by reference and MATLAB by copy. It means it is not trivial to do in place functions in MATLAB. – Eric Johnson May 01 '22 at 14:48
  • Matlab's documentation vary based which toolboxes you have. The core and older toolboxes (signal processing, image processing) are quite good and contained references to papers for the implementations. For newer toolboxs (STAP, Tracking) the documentation is complete garbage. You basically get a black box with no idea of what's going on inside - also there are no references. Another issue with Matlab is the granularity of the toolboxes. If I want one spline function I need the whole toolbox. – David May 02 '22 at 14:11