Gre na git
parent
fc81d20df5
commit
3877090cbf
|
@ -11,9 +11,10 @@ import cv2 as cv2
|
|||
from matplotlib import pyplot as plt
|
||||
from PIL import Image
|
||||
from typing import Union
|
||||
import numpy.typing as npt
|
||||
|
||||
|
||||
def imread(path: str) -> np.float64:
|
||||
def imread(path: str) -> npt.NDArray[np.float64]:
|
||||
"""
|
||||
Reads an image in RGB order. Image type is transformed from uint8 to float, and
|
||||
range of values is reduced from [0, 255] to [0, 1].
|
||||
|
@ -21,10 +22,10 @@ def imread(path: str) -> np.float64:
|
|||
I = Image.open(path).convert('RGB') # PIL image.
|
||||
I = np.asarray(I) # Converting to Numpy array.
|
||||
I = I.astype(np.float64) / 255
|
||||
return np.float64(I)
|
||||
return I
|
||||
|
||||
|
||||
def imread_gray(path: str) -> np.float64:
|
||||
def imread_gray(path: str) -> npt.NDArray[np.float64]:
|
||||
"""
|
||||
Reads an image in gray. Image type is transformed from uint8 to float, and
|
||||
range of values is reduced from [0, 255] to [0, 1].
|
||||
|
@ -32,10 +33,10 @@ def imread_gray(path: str) -> np.float64:
|
|||
I = Image.open(path).convert('L') # PIL image opening and converting to gray.
|
||||
I = np.asarray(I) # Converting to Numpy array.
|
||||
I = I.astype(np.float64) / 255
|
||||
return np.float64(I)
|
||||
return I
|
||||
|
||||
|
||||
def imshow(img: Union[np.float64, np.uint8], title=None) -> None:
|
||||
def imshow(img: Union[npt.NDArray[np.float64], np.uint8], title=None) -> None:
|
||||
"""
|
||||
Shows an image. Image can be of types:
|
||||
- type uint8, in range [0, 255]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import UZ_utils as uz
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
#######################################
|
||||
# EXCERCISE 1: Basic image processing #
|
||||
|
@ -9,23 +10,28 @@ def excercise_one() -> None:
|
|||
image = one_a()
|
||||
one_b(image)
|
||||
|
||||
|
||||
# Display image
|
||||
def one_a() -> np.float64:
|
||||
def one_a() -> npt.NDArray[np.float64]:
|
||||
image = uz.imread('./images/bird.jpg')
|
||||
print(image.shape)
|
||||
print(image.dtype)
|
||||
uz.imshow(image, 'Birdie')
|
||||
return np.float64(image)
|
||||
return image
|
||||
|
||||
# Convert loaded image into grayscale
|
||||
def one_b(image: np.float64) -> None:
|
||||
print(image)
|
||||
def one_b(image: npt.NDArray[np.float64]) -> None:
|
||||
grayscale_image = np.zeros(image.shape[:2])
|
||||
|
||||
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
|
||||
|
||||
uz.imshow(grayscale_image, 'Birdie grayscale')
|
||||
|
||||
def one_c():
|
||||
#todo
|
||||
assert(1 == 1)
|
||||
|
||||
def main() -> None:
|
||||
excercise_one()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue