DSTT
DSTT
import numpy as np
import matplotlib.pyplot as plt
#cái này là 3D với 2D nha hình ảnh máy tính tự động chọn
def rotate_point_2d(x, y, angle):
"""Rotate a point (x, y) around the origin by the given angle (in
degrees)."""
angle_rad = math.radians(angle)
cos_theta = math.cos(angle_rad)
sin_theta = math.sin(angle_rad)
x_new = x * cos_theta - y * sin_theta
y_new = x * sin_theta + y * cos_theta
return x_new, y_new
if angles_3d is None:
angle = angle_2d % 360
center_x, center_y = width / 2, height / 2
output_image = np.ones_like(input_image) * 255
for x in range(width):
for y in range(height):
x_translated, y_translated = x - center_x, y - center_y
x_rotated, y_rotated = rotate_point_2d(x_translated,
y_translated, angle)
x_rotated += center_x
y_rotated += center_y
if 0 <= x_rotated < width and 0 <= y_rotated < height:
output_image[int(x_rotated), int(y_rotated)] =
input_image[x, y]
else:
angle_x, angle_y, angle_z = angles_3d
output_image = np.ones_like(input_image) * 255
for x in range(width):
for y in range(height):
for z in range(3): # 3 channels (RGB)
x_rotated, y_rotated, z_rotated = rotate_point_3d(x,
y, z, angle_x, angle_y, angle_z)
x_rotated, y_rotated = int(x_rotated), int(y_rotated)
if 0 <= x_rotated < width and 0 <= y_rotated < height:
output_image[int(x_rotated), int(y_rotated), z] =
input_image[x, y, z]
return output_image
angle_2d = 10
angles_3d = (45, 30, 60)
rotated_image_2d = rotate_image(input_image_2d, angle_2d)
rotated_image_3d = rotate_image(input_image_3d, None, angles_3d)
plt.figure(figsize=(10, 5))
plt.subplot(1, 2, 1)
plt.imshow(rotated_image_2d)
plt.title('Rotated 2D Image')
plt.subplot(1, 2, 2)
plt.imshow(rotated_image_3d)
plt.title('Rotated 3D Image')
plt.show()