Normaliziraj brate

main
Gasper Spagnolo 2022-10-17 20:33:00 +02:00
parent c5e79f5bac
commit f706418038
1 changed files with 24 additions and 2 deletions

View File

@ -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: