64 lines
1.7 KiB
Python
64 lines
1.7 KiB
Python
import numpy as np
|
|
import numpy.typing as npt
|
|
from matplotlib import pyplot as plt
|
|
import cv2
|
|
import uz_framework.image as uz_image
|
|
import uz_framework.text as uz_text
|
|
import os
|
|
|
|
##############################################
|
|
# EXCERCISE 1: Exercise 1: Image derivatives #
|
|
##############################################
|
|
|
|
def ex1():
|
|
one_a()
|
|
one_b()
|
|
|
|
def one_a() -> None:
|
|
img = uz_image.imread_gray("data/graf/graf_a.jpg", uz_image.ImageType.float64)
|
|
sigmas = [3, 6, 9, 12]
|
|
# Plot the points
|
|
fig, axs = plt.subplots(2, len(sigmas))
|
|
fig.suptitle("Hessian corner detection")
|
|
|
|
for i, sigma in enumerate(sigmas):
|
|
determinant, hessian_points = uz_image.hessian_points(img, sigma, 0.004)
|
|
# Plot determinant
|
|
axs[0, i].imshow(determinant)
|
|
axs[0, i].set_title(f"Sigma: {sigma}")
|
|
# Plot grayscale image
|
|
axs[1, i].imshow(img, cmap="gray")
|
|
# Plot scatter hessian points
|
|
axs[1, i].scatter(hessian_points[:, 1], hessian_points[:, 0], s=20, c="r", marker="x")
|
|
|
|
plt.show()
|
|
|
|
def one_b() -> None:
|
|
img = uz_image.imread_gray("data/graf/graf_a.jpg", uz_image.ImageType.float64)
|
|
sigmas = [3, 6, 9]
|
|
# Plot the points
|
|
fig, axs = plt.subplots(2, len(sigmas))
|
|
fig.suptitle("Harris corner detection")
|
|
|
|
for i, sigma in enumerate(sigmas):
|
|
determinant, harris_points = uz_image.harris_detector(img, sigma, treshold=1e-6)
|
|
# Plot determinant
|
|
axs[0, i].imshow(determinant)
|
|
axs[0, i].set_title(f"Sigma: {sigma}")
|
|
# Plot grayscale image
|
|
axs[1, i].imshow(img, cmap="gray")
|
|
# Plot scatter hessian points
|
|
axs[1, i].scatter(harris_points[:, 1], harris_points[:, 0], s=20, c="r", marker="x")
|
|
|
|
plt.show()
|
|
|
|
# ######## #
|
|
# SOLUTION #
|
|
# ######## #
|
|
|
|
def main():
|
|
ex1()
|
|
|
|
if __name__ == '__main__':
|
|
main()
|