Reputation: 468
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()
Upvotes: 1
Views: 964
Reputation: 468
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)
Upvotes: 1
Reputation: 1055
you could flip the image on axis prior to input, then run your current polar warp to get the result like this:
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)
horizontal_flip = testImg[:, ::-1]
pol = warp_polar(horizontal_flip, radius=min(horizontal_flip.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(horizontal_flip)
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()
Upvotes: 0