ZIP indir
0
main
1 dal
git@carbon4code.com:ahmet/Python-for-Data-Science.git
Ahmet Kerem Piscine Final
10 commit
rotate.py 1.1 KB
import matplotlib.pyplot as plt
import numpy as np
from load_image import ft_load


def transpose_array(array: np.ndarray) -> np.ndarray:
    """Transpose a 2D array manually, without any library function."""
    rows, cols = array.shape
    transposed = np.zeros((cols, rows), dtype=array.dtype)
    for i in range(rows):
        for j in range(cols):
            transposed[j, i] = array[i, j]
    return transposed


def main() -> None:
    """Cut a square from animal.jpeg, transpose it and display it."""
    try:
        array = ft_load("../animal.jpeg")
        if array is None:
            return
        square = array[100:500, 400:800, 0:1]
        print(f"The shape of image is: {square.shape}")
        print(square)

        transposed = transpose_array(square[:, :, 0])
        print(f"New shape after Transpose: {transposed.shape}")
        print(transposed)

        plt.imshow(transposed, cmap="gray")
        plt.title("Transposed 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()