From f7064180388cae474a1d8c6d5bd1cd5e3c3951c0 Mon Sep 17 00:00:00 2001 From: Gasper Spagnolo Date: Mon, 17 Oct 2022 20:33:00 +0200 Subject: [PATCH] Normaliziraj brate --- assignment1/solution.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/assignment1/solution.py b/assignment1/solution.py index 8a20f84..3fb8d94 100644 --- a/assignment1/solution.py +++ b/assignment1/solution.py @@ -131,7 +131,8 @@ def excercise_two() -> None: size where the value of pixels is determined by whether the value of the corresponding pixels in the source image is greater or lower than the given threshold. """ - two_a() + #two_a() + two_b('./images/bird.jpg', 100, 20) def two_a() -> tuple[npt.NDArray[np.float64], npt.NDArray[np.uint8]]: """ @@ -167,7 +168,12 @@ def two_a() -> tuple[npt.NDArray[np.float64], npt.NDArray[np.uint8]]: plt.show() return (image, binary_mask) -def two_b() -> None: +def count_image_bins(image: npt.NDArray[np.float64], number_of_bins: int) -> npt.NDArray[np.uint8]: + bins = np.arange(0, 1, 1 / number_of_bins) + binarray = np.digitize(image.reshape(-1), bins).astype(np.uint8) + return binarray + +def two_b(image_path: str, number_of_bins_first: int, number_of_bins_second: int) -> None: """ Write a function myhist that accepts a grayscale image and the number of bins that will be used in building a histogram. The function should return a 1D array that @@ -181,6 +187,22 @@ def two_b() -> None: Write a script that calculates and displays histograms for different numbers of bins using bird.jpg """ + image = uz.imread_gray(image_path) + + H1 = count_image_bins(image, number_of_bins_first) + H2 = count_image_bins(image, number_of_bins_second) + + fig, (ax0, ax1, ax2) = plt.subplots(1, 3) + fig.suptitle("Birdie and its mask") + + + ax0.imshow(image, cmap="gray") + ax1.hist(H1, bins=number_of_bins_first) + ax2.hist(H2, bins=number_of_bins_second) + + plt.show() + + def main() -> None: