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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With