ahmet / Python-for-Data-Science
Herkese Açık Ahmet Kerem Piscine Final
zoom.py 814 B
import matplotlib.pyplot as plt
from load_image import ft_load
def main() -> None:
"""Load animal.jpeg, zoom into it and display the zoomed part."""
try:
array = ft_load("../animal.jpeg")
if array is None:
return
print(f"Size in pixels: X = {array.shape[1]}, Y = {array.shape[0]}")
print(f"Number of channels: {array.shape[2]}")
print(array)
zoomed = array[100:500, 400:800, 0:1]
print(f"New shape after slicing: {zoomed.shape}")
print(zoomed)
plt.imshow(zoomed[:, :, 0], cmap="gray")
plt.title("Zoomed image")
plt.xlabel("X axis (pixels)")
plt.ylabel("Y axis (pixels)")
plt.show()
except Exception as error:
print(f"Error: {error}")
if __name__ == "__main__":
main()