Skip to content

Instantly share code, notes, and snippets.

@kwsp
Created February 23, 2022 03:12
Show Gist options
  • Save kwsp/3d89df2eb1f874029725029041fbda4f to your computer and use it in GitHub Desktop.
Save kwsp/3d89df2eb1f874029725029041fbda4f to your computer and use it in GitHub Desktop.
import numpy as np
import cv2
def polar2cart(img: np.ndarray):
"""
Convert image (B-scan) from Polar coordinates to Cartesian coordinates
"""
# Resize image to square first
h, w = img.shape[:2]
sz = min(h, w)
r = sz // 2
img = cv2.resize(img, (sz, sz))
# warp - requires rotation
img = cv2.rotate(img, cv2.ROTATE_90_COUNTERCLOCKWISE)
img = cv2.warpPolar(img, img.shape[:2], (r, r), r, cv2.WARP_INVERSE_MAP)
img = cv2.rotate(img, cv2.ROTATE_90_COUNTERCLOCKWISE)
return img
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment