Difference between cv2, scipy.misc and skimage

Question:

What is the main difference between

  • cv2.imread / resize/ imwrite
  • scipy.misc.imread / imresize/ imsave
  • skimage.io.imread / skimage.transform.resize / skimage.io.imsave

and how to decide which one to use?

I know cv2 and skimage have different encoder, and cv2 use ‘BGR’ not ‘RGB’ in default. But sometimes a script might use them together, for example main.py, where it uses scipy.misc.imread, cv2.imresize and cv2.imwrite. I am wondering the reason to do so.

Asked By: Panfeng Li

||

Answers:

The scipy.misc module exists historically as a place to gather functions that do not fit easily into the other SciPy submodules. It is slated for deprecation and should not be used.

In the Python ecosystem, I’d recommend imageio for reading images (or matplotlib.pyplot.imread, if you already are using matplotlib).

Scikit-image provides a convenient wrapper around all of these I/O libraries as skimage.io (it should pick up whatever is installed on your system already). It also ensures that images are converted to the correct data type and range formats for use with other skimage functions (see http://scikit-image.org/docs/dev/user_guide/data_types.html).

cv2.imread et al. operate on OpenCV image objects and, as you’ve already observed, those images are typically stored in BGR memory layout. But for loading PNGs and JPGs, most of these libraries listed above all wrap the same underlying C libraries, perhaps with slightly different parameters for compression etc.

I’d recommend that you use whichever functions minimize the dependency footprint of your script / package.

Answered By: Stefan van der Walt
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.