Search code examples
pythonimage-processingscikit-image

Performing a polar transformation on an image in reverse clock direction using scikit-image


As the following experiment shows, the warp_polar function of the scikit-image library performs the polar transformation in clock direction. However, I want to perform a polar transformation in the reverse clock direction. I should probably flip or rotate the image in some way to achieve the desired end result. However, I am not sure how to do this. I would appreciate any efficient solution.

In a correct solution, the transformed image would have the following sequence of numbers: 3, 2, 1, 12, 11, 10....

from matplotlib import pyplot as plt
import matplotlib.image as mpimg
import matplotlib.gridspec as gridspec
from skimage.transform import warp_polar
import cv2

testImg = cv2.cvtColor(mpimg.imread('clock.png'), cv2.COLOR_BGR2GRAY)
pol = warp_polar(testImg, radius=min(testImg.shape)/2)

# Create 2x2 sub plots
gs = gridspec.GridSpec(1, 2)

fig = plt.figure()
ax1 = fig.add_subplot(gs[0, 0]) # row 0, col 0
ax1.imshow(testImg)
ax1.set_title("Original Image")

ax2 = fig.add_subplot(gs[0, 1]) # row 0, col 1
ax2.imshow(pol)
ax2.set_title("Polar Transformation")

plt.show()

enter image description here


Solution

  • Thanks to the comment, I found out that the solution was much simpler than I thought. Flipping the result of warp_polar vertically is equivalent to applying the polar transformation in the reverse clock direction.

    import numpy as np
    pol = np.flip(pol,0)
    

    enter image description here