Why is skimage.transform.rotate significantly slower than PIL Image.rotate?

I'm in the process of converting some PIL code to NumPy, but I found that the skimage.transform.rotate function skimage.transform.rotate significantly slower than the PIL Image.rotate .

As a rough comparison, using skimage rotates on an image 1000 × 1000 pixels in size takes ~ 2.2 seconds, and Image.rotate takes ~ 0.1 seconds:

 import time from PIL import Image import numpy as np from skimage.transform import rotate im = Image.open("some_big_image.png").convert("L") print "Image size: %s" %(im.size, ) s = time.time() im.rotate(10, Image.BICUBIC, expand=True) print "Image.rotate: %0.04f" %(time.time() - s, ) ima = np.array(im) / 255.0 s = time.time() rotate(ima, 10, order=3) # order=3 --> bi-cubic filtering print "skimage.transform.rotate: %0.04f" %(time.time() - s, ) 

And the conclusion:

 $ py rotate.py Image size: (1275, 1650) Image.rotate: 0.1154 skimage.transform.rotate: 2.2310 

(these numbers are more or less consistent between several runs, I do not believe that this is an artifact, because of which there are not enough tests)

So! What's up with that? Is there any way to speed up skimage rotate ?

Version Information:

  • PIL: 1.1.7
  • skimage: 0.14.1
  • numpy: 1.7.1
  • Python: 2.7.2

You can also note:

  • If BICUBIC filtering BICUBIC not used, im.rotate operation takes ~ 0.01 seconds, and when setting order=0 , the closest neighbor filtering is used, skimage.rotate takes ~ 0.6 seconds.
+6
source share
2 answers

Install the latest version from https://github.com/scikit-image/scikit-image . Just a few days ago, I fixed a bug (see https://github.com/scikit-image/scikit-image/commit/d5776656a8217e58cb28d5760439a54e96d15316 ) related to this slowdown.

My current versions are:

 from PIL import Image import numpy as np from skimage.transform import rotate a = np.zeros((1000, 1000), dtype=np.uint8) im = Image.fromarray(a) %timeit im.rotate(10, Image.BICUBIC, expand=True) ima = a / 255.0 %timeit rotate(ima, 10, order=1) %timeit rotate(ima, 10, order=3) ## -- Output -- 10 loops, best of 3: 41.3 ms per loop 10 loops, best of 3: 43.6 ms per loop 10 loops, best of 3: 101 ms per loop 
+7
source

Just by reading Python code, not Cython code for warp() , assume that since skimage uses a common warp code, its code paths are less efficient than something written specifically for rotation in the plane, and nothing more.

+1
source

Source: https://habr.com/ru/post/957466/


All Articles