Last active
July 11, 2022 19:42
-
-
Save omaraflak/04d46c095d2158b9dda1e188b6163148 to your computer and use it in GitHub Desktop.
3D projection
This file contains 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 cv2 | |
import numpy as np | |
import plotly.graph_objects as go | |
image = cv2.imread("earth.jpeg", cv2.IMREAD_COLOR) | |
height, width, _ = image.shape | |
image = cv2.resize(image, (300, int(height * 300 / width))) | |
height, width, _ = image.shape | |
theta = np.repeat(range(height), width) * np.pi / height | |
phi = np.tile(range(width), height) * 2 * np.pi / width | |
x = np.sin(theta) * np.cos(phi) | |
y = np.sin(theta) * np.sin(phi) | |
z = np.cos(theta) | |
b, g, r = np.dsplit(image.astype(np.uint32), 3) | |
c = np.vectorize(lambda i: f"#{i:06x}")(r << 16 | g << 8 | b).flatten() | |
fig = go.Figure(data=go.Scatter3d(x=x, y=y, z=z, mode="markers", marker=dict(color=c, size=3))) | |
fig.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
But really you can render anything...