As in the title, which is the fastest way to resize an image? I'm using Python + OpenCV 2.11 (not openCV3), and it seems cv2.resize() is very slow.
We can use CUDA with OpenCV3 (http://www.coldvision.io/2015/12/22/image-resize-with-opencv-and-cuda/), but is it supported in OpenCV 2?
OpenCV 2 has gpu module but unfortunately there's no bindings for Python.
CUDA programming comes with a pretty big warmup- and code complexity overhead itself.
There exists a SIMD fork of Pillow, which claims to have much better performance than ImageMagick or plain Pillow, but there are no comparisons to OpenCV. Maybe worth checking out how they compare.
Related
I optimized my code to process images with pillow. It uses all the sources to get as fast as possible. Just the GPU would make it faster. I don't find any solution beside CUDA and that wont't work on Catalina. Is there any way to use my GPU(NVIDIA GeForce GT 750M 2 GB
Intel Iris Pro 1536 MB) to make the process more efficient?
Thanks for your help!
Actually there is no way to use pillow to do that! If you need a better speed, you can use ImageMagick (Wand as python wrapper) or GraphicsMagick (pgmagick as Python wrapper). If you need to use GPU, ImageMagick gives some option to use it if possible (I am not sure about GM) but it is not neither as efficient nor complete as you use CUDA or OpenCL. I recommend you to use Vulkan if you need better result and cross platform (Nvidia and AMD, MacOS, Linux Windows...).
I'm implementing a real-time LMS algorithm, and numpy.dot takes more time than my sampling time, so I need numpy to be faster (my matrices are 1D and 100 long).
I've read about building numpy with ATLAS and such, but never done such thing and spent all my day trying to do it, with zero succes...
Can someone explain why there aren't builds with ATLAS included? Can anyone provide me with one? Is there any other way to speed up dot product?
I've tried numba, and scipy.linalg.gemm_dot but none of them seemed to speed things up.
my system is Windows8.1 with Intel processor
If you download the official binaries, they should come linked with ATLAS. If you want to make sure, check the output of np.show_config(). The problem is that ATLAS (Automatically Tuned Linear Algebra System) checks many different combinations and algorithms, and keeps the best at compile time. So, when you run a precompiled ATLAS, you are running it optimised for a computer different than yours.
So, your options to improve dot are:
Compile ATLAS yourself. On Windows it may be a bit challenging, but it is doable. Note: you must use the same compiler used to compile Python. That is, if you decide to go for MinGW, you need to get Python compiled with MinGW, or build it yourself.
Try Christopher Gohlke's Numpy. It is linked against MKL, that is much faster than ATLAS (and does all the optimisations at run time).
Try Continuum analytics' Conda with accelerate (also linked with MKL). It costs money, unless you are an academic. In Linux, Conda is slower than system python because they have to use an old compiler for compatibility purposes; I don't know if that is the case on Windows.
Use Linux. Your Python life will be much easier, setting up the system to compile stuff is very easy. Also, setting up Cython is simple too, and then you can compile your whole algorithm, and probably get further speed up.
The note regarding Cython is valid for Windows too, it is just more difficult to get it working. I tried a few years ago (when I used Windows), and failed after a few days; I don't know if the situation has improved.
Alternative:
You are doing the dot product of two vectors. Then, np.dot is probably not the most efficient way. I would give a shot to spell it out in plain Python (vec1*vec2).sum() (could be very good for Numba, this expression it can actually optimise) or using numexpr:
ne.evaluate(`sum(vec1 * vec2)`)
Numexpr will also parallelise the expression automatically.
I want to know if it is possible to use opencv gpu functions like those from here?
Or I have to wrap it into python class.
Right now OpenCV 2.4.7 doesn't support the GPU module on OpenCV-Python.
That means that you must write wrappers yourself.
To answer the question in the comment made by fbence in the accepted answer, this is now possible with OpenCV 3 and Python 2.7+ or Python 3+. However, the OpenCV 3 GPU module must be compiled from source.
Assuming you are working on a Linux system you can follow these guides:
For OpenCV 3 GPU and Python 2.7+ follow this guide.
For OpenCV 3 GPU and Python 3, follow this guide from Step 0 to Step 5.
i'm searching a Python lib with good image processing functionalities .
I was searching for CImg (which i've already used on C++ projects) bindings, but i wasn't lucky.
I found PIL, but it lacks a lot of features that CImg has so, is there any good alternative ?
Thanks
UPDATE
PIL is good, but i need Python 3 support on a Mac OS X system.
I would suggest you to enumerate the functionality that you find desirable which is there in Cimg and not in PIL.
Discussion on SO
Image Processing, In Python?
pypi also throws up a lot of modules on image processing. Try seeing, if some of them is suitable for you.
http://pypi.python.org/pypi?:action=search&term=image+processing&submit=search
What are some of the better libraries for image generation in Python? If I were to implement a GOTCHA (for example's sake), thereby having to manipulate an image on the pixel level, what would my options be? Ideally I would like to save resulting image as a low-resolution jpeg, but this is mere wishing, I'll settle for any common image format.
Thank you for your attention.
The Python Imaging Library (PIL) is the de facto image manipulation library on Python. You can find it here, or through easy_install or pip if you have them.
Edit: PIL has not been updated in a while, but it has been forked and maintained under the name pillow. Just install it this way in a shell:
pip install Pillow
The import statements are still the same as PIL (e.g., from PIL import image) and is backward compatible.
Pillow is a fork of PIL that is still actively developed. While PIL is not dead it has been a number of years since the last release.
If you should generate text or other vector based images (and then save to .png or .jpg), you could also consider Cairo (PyCairo, in this case). I use it a lot.
Otherwise, for pixel-level manipulation, PIL is the obvious choice.