Created
February 23, 2022 03:12
-
-
Save kwsp/3d89df2eb1f874029725029041fbda4f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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