Gremoooooooo
parent
894dcc5e04
commit
10d19c1243
Binary file not shown.
After Width: | Height: | Size: 98 KiB |
Binary file not shown.
After Width: | Height: | Size: 254 KiB |
Binary file not shown.
After Width: | Height: | Size: 103 KiB |
|
@ -132,7 +132,9 @@ def excercise_two() -> None:
|
||||||
pixels in the source image is greater or lower than the given threshold.
|
pixels in the source image is greater or lower than the given threshold.
|
||||||
"""
|
"""
|
||||||
#two_a()
|
#two_a()
|
||||||
two_b('./images/bird.jpg', 100, 20)
|
#two_b('./images/bird.jpg', 100, 20)
|
||||||
|
two_d()
|
||||||
|
|
||||||
|
|
||||||
def two_a() -> tuple[npt.NDArray[np.float64], npt.NDArray[np.uint8]]:
|
def two_a() -> tuple[npt.NDArray[np.float64], npt.NDArray[np.uint8]]:
|
||||||
"""
|
"""
|
||||||
|
@ -176,6 +178,7 @@ def my_hist_for_loop(image: npt.NDArray[np.float64], number_of_bins: int) -> npt
|
||||||
for pixel in image.reshape(-1):
|
for pixel in image.reshape(-1):
|
||||||
# https://stackoverflow.com/a/16244044
|
# https://stackoverflow.com/a/16244044
|
||||||
bins[np.argmax(bin_restrictions > pixel)] += 1
|
bins[np.argmax(bin_restrictions > pixel)] += 1
|
||||||
|
|
||||||
return bins / np.sum(bins)
|
return bins / np.sum(bins)
|
||||||
|
|
||||||
# Much faster implementation than for loop
|
# Much faster implementation than for loop
|
||||||
|
@ -184,10 +187,25 @@ def my_hist(image: npt.NDArray[np.float64], number_of_bins: int) -> npt.NDArray[
|
||||||
# Put pixels into classes
|
# Put pixels into classes
|
||||||
# ex. binsize = 10 then 0.4 would map into 4
|
# ex. binsize = 10 then 0.4 would map into 4
|
||||||
binarray = np.digitize(image.reshape(-1), bins).astype(np.uint8)
|
binarray = np.digitize(image.reshape(-1), bins).astype(np.uint8)
|
||||||
|
|
||||||
# Now count those values
|
# Now count those values
|
||||||
binarray = np.unique(binarray, return_counts=True)
|
binarray = np.unique(binarray, return_counts=True)
|
||||||
binarray = binarray[1].astype(np.float64) # Get the counts out of tuple
|
|
||||||
return binarray / np.sum(binarray)
|
counts = binarray[1].astype(np.float64) # Get the counts out of tuple
|
||||||
|
|
||||||
|
# Check if there is any empty bin
|
||||||
|
empty_bins = []
|
||||||
|
bins = binarray[0]
|
||||||
|
for i in range(1, number_of_bins + 1):
|
||||||
|
if i not in bins:
|
||||||
|
empty_bins.append(i)
|
||||||
|
|
||||||
|
# Add empty bins with zeros
|
||||||
|
if empty_bins != []:
|
||||||
|
for i in empty_bins:
|
||||||
|
counts = np.insert(counts, i - 1, 0)
|
||||||
|
|
||||||
|
return counts / np.sum(counts)
|
||||||
|
|
||||||
|
|
||||||
def two_b(image_path: str, number_of_bins_first: int, number_of_bins_second: int) -> None:
|
def two_b(image_path: str, number_of_bins_first: int, number_of_bins_second: int) -> None:
|
||||||
|
@ -222,6 +240,40 @@ def two_b(image_path: str, number_of_bins_first: int, number_of_bins_second: int
|
||||||
|
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
def two_c():
|
||||||
|
assert("to be implemented", "to be implemented")
|
||||||
|
|
||||||
|
def two_d():
|
||||||
|
"""
|
||||||
|
Test myhist function on images (three or more) of the same scene in
|
||||||
|
different lighting conditions. One way to do this is to capture several images using
|
||||||
|
your web camera and change the lighting of the room. Visualize the histograms for
|
||||||
|
all images for different number of bins and interpret the results.
|
||||||
|
"""
|
||||||
|
light = uz.imread_gray("./images/ROOM_LIGHTS_ON.jpg")
|
||||||
|
darker = uz.imread_gray("./images/ONE_ROOM_LIGH_ON.jpg")
|
||||||
|
dark = uz.imread_gray("./images/DARK.jpg")
|
||||||
|
|
||||||
|
H1 = my_hist(light, 100)
|
||||||
|
H2 = my_hist(darker, 100)
|
||||||
|
H3 = my_hist(dark, 100)
|
||||||
|
|
||||||
|
fig, axs = plt.subplots(3, 2)
|
||||||
|
fig.suptitle("spanskiduh and histgrams")
|
||||||
|
|
||||||
|
axs[0, 0].imshow(light, cmap="gray")
|
||||||
|
axs[0, 0].set(title="Image in light conditions")
|
||||||
|
axs[0, 1].bar(np.arange(100), H1)
|
||||||
|
|
||||||
|
axs[1, 0].imshow(darker, cmap="gray")
|
||||||
|
axs[1, 0].set(title="Image in darker conditions")
|
||||||
|
axs[1, 1].bar(np.arange(100), H2)
|
||||||
|
|
||||||
|
axs[2, 0].imshow(dark, cmap="gray")
|
||||||
|
axs[2, 0].set(title="Image in dark conditions")
|
||||||
|
axs[2, 1].bar(np.arange(100), H3)
|
||||||
|
|
||||||
|
plt.show()
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
#excercise_one()
|
#excercise_one()
|
||||||
|
|
Loading…
Reference in New Issue