2022-10-15 17:07:41 +02:00
|
|
|
import UZ_utils as uz
|
|
|
|
import numpy as np
|
2022-10-15 18:20:50 +02:00
|
|
|
import numpy.typing as npt
|
2022-10-15 17:07:41 +02:00
|
|
|
|
2022-10-15 17:12:38 +02:00
|
|
|
#######################################
|
|
|
|
# EXCERCISE 1: Basic image processing #
|
|
|
|
#######################################
|
|
|
|
|
|
|
|
def excercise_one() -> None:
|
|
|
|
image = one_a()
|
|
|
|
one_b(image)
|
2022-10-15 19:44:51 +02:00
|
|
|
one_c(image)
|
|
|
|
one_d(60, 180, 180, 340, image)
|
2022-10-15 17:12:38 +02:00
|
|
|
|
2022-10-15 17:07:41 +02:00
|
|
|
# Display image
|
2022-10-15 18:20:50 +02:00
|
|
|
def one_a() -> npt.NDArray[np.float64]:
|
2022-10-15 17:07:41 +02:00
|
|
|
image = uz.imread('./images/bird.jpg')
|
2022-10-15 19:44:51 +02:00
|
|
|
#uz.imshow(image, 'Birdie')
|
2022-10-15 18:20:50 +02:00
|
|
|
return image
|
2022-10-15 17:07:41 +02:00
|
|
|
|
|
|
|
# Convert loaded image into grayscale
|
2022-10-15 18:20:50 +02:00
|
|
|
def one_b(image: npt.NDArray[np.float64]) -> None:
|
|
|
|
grayscale_image = np.zeros(image.shape[:2])
|
2022-10-15 17:07:41 +02:00
|
|
|
|
2022-10-15 18:20:50 +02:00
|
|
|
for i in range(image.shape[0]):
|
|
|
|
for j in range(image.shape[1]):
|
|
|
|
grayscale_image[i, j] = (image[i, j, 0] + image[i,j, 1] + image[i, j, 2]) / 3
|
|
|
|
|
2022-10-15 19:44:51 +02:00
|
|
|
#uz.imshow(grayscale_image, 'Birdie grayscale')
|
|
|
|
|
|
|
|
# Display birdies head in grayscale
|
|
|
|
def one_c(image: npt.NDArray[np.float64]) -> None:
|
|
|
|
print(image.shape)
|
|
|
|
#uz.imshow(image[50:200, 100:400, 2])
|
|
|
|
|
|
|
|
# Convert one part of image to grayscale
|
|
|
|
def one_d(startx: int, endx: int, starty: int, endy: int, image:npt.NDArray[np.float64]) -> None:
|
|
|
|
|
|
|
|
for i in range(startx, endx):
|
|
|
|
for j in range(starty, endy):
|
|
|
|
image[i, j, 0] = 1 - image[i, j, 0]
|
|
|
|
image[i, j, 1] = 1 - image[i, j, 1]
|
|
|
|
image[i, j, 2] = 1 - image[i, j, 2]
|
|
|
|
|
|
|
|
uz.imshow(image, 'Bridie head grayscale')
|
2022-10-15 17:07:41 +02:00
|
|
|
|
2022-10-15 18:20:50 +02:00
|
|
|
|
2022-10-15 17:12:38 +02:00
|
|
|
def main() -> None:
|
|
|
|
excercise_one()
|
2022-10-15 17:07:41 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|