Implemented my hist with image type

main
Gasper Spagnolo 2022-10-20 16:12:02 +02:00
parent 08064ec171
commit 11eb335a74
1 changed files with 15 additions and 14 deletions

View File

@ -9,12 +9,12 @@ from PIL import Image
# EXCERCISE 1: Basic image processing #
#######################################
def excercise_one() -> None:
image = one_a()
#one_b(image)
#one_c(image)
#one_d(100, 200, 50, 200, image)
one_e()
#def excercise_one() -> None:
# image = one_a()
# one_b(image)
# one_c(image)
# one_d(100, 200, 50, 200, image)
# one_e()
def one_a() -> npt.NDArray[np.float64]:
"""
@ -134,7 +134,7 @@ def excercise_two() -> None:
"""
#two_a()
two_b('./images/bird.jpg', 100, 20)
two_d()
#two_d()
#two_e(uz.imread_gray("./images/bird.jpg", uz.ImageType.float64))
@ -184,8 +184,12 @@ def my_hist_for_loop(image: npt.NDArray[np.float64], number_of_bins: int) -> npt
return bins / np.sum(bins)
# Much faster implementation than for loop
def my_hist(image: npt.NDArray[np.float64], number_of_bins: int) -> npt.NDArray[np.float64]:
bins = np.arange(0, 1, 1 / number_of_bins)
def my_hist(image: npt.NDArray[np.float64], number_of_bins: int, img_typ: uz.ImageType) -> npt.NDArray[np.float64]:
if img_typ == uz.ImageType.float64:
bins = np.arange(0, 1, 1 / number_of_bins)
elif img_typ == uz.ImageType.uint8:
bins = np.arange(0, 255, 255/number_of_bins)
# Put pixels into classes
# ex. binsize = 10 then 0.4 would map into 4
binarray = np.digitize(image.reshape(-1), bins).astype(np.uint8)
@ -226,9 +230,8 @@ def two_b(image_path: str, number_of_bins_first: int, number_of_bins_second: int
"""
image = uz.imread_gray(image_path, uz.ImageType.uint8)
H1 = my_hist(image, number_of_bins_first)
H2 = my_hist(image, number_of_bins_second)
H1 = my_hist(image, number_of_bins_first, uz.ImageType.uint8)
H2 = my_hist(image, number_of_bins_second, uz.ImageType.uint8)
fig, (ax0, ax1, ax2) = plt.subplots(1, 3)
fig.suptitle("Birdie and histgrams")
@ -337,8 +340,6 @@ def two_e(image: npt.NDArray[np.float64]) -> None:
criterias.append( weight0 * var0 + weight1 * var1)
best_threshold = treshold_range[np.argmin(criterias)]
print(best_threshold)
print("h")
def main() -> None:
#excercise_one()