From 39202630d8605d86d1db73861c41ce510fa89aba Mon Sep 17 00:00:00 2001 From: Arne van Iterson Date: Fri, 22 Sep 2023 15:24:00 +0200 Subject: [PATCH] Heatmap --- src/helpers/algorithms/canny_map.py | 56 +++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/helpers/algorithms/canny_map.py diff --git a/src/helpers/algorithms/canny_map.py b/src/helpers/algorithms/canny_map.py new file mode 100644 index 0000000..412d329 --- /dev/null +++ b/src/helpers/algorithms/canny_map.py @@ -0,0 +1,56 @@ +import cv2 +import timeit +import seaborn as sns +import matplotlib.pyplot as plt +import numpy as np + +# Read the original image +img = cv2.imread("./res/trees/berk_sq1_original.png") + +# Convert to graycsale +img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + +# resize image +resized = cv2.resize(img_gray, (720, 720), interpolation=cv2.INTER_AREA) + +# Display original image +# cv2.imshow("Original", resized) + +# Blur the image for better edge detection +# img_blur = cv2.GaussianBlur(resized, (3, 3), 0) + +def thing(): + canny_max = 1000 + canny_step = 20 + + results = [[] for x in range((int)(canny_max / canny_step))] + + for th1 in range(0, canny_max, canny_step): + for th2 in range(0, canny_max, canny_step): + # Canny Edge Detection + edges = cv2.Canny(image=resized, threshold1=th1, threshold2=th2) + + w_res = cv2.countNonZero(edges) + y_ind = (int)(th1 / canny_step) + x_ind = (int)(th2 / canny_step) + + print(f"Result at thres {th1}, {th2}; \tIndex {y_ind}, {x_ind} \t= {w_res}") + + results[y_ind].append(w_res) + print(results[y_ind]) + + + # Create a heatmap + sns.heatmap(results) + + # Display the heatmap + plt.show() + +print(timeit.timeit(lambda: thing(), number=1)) + +# # Display Canny Edge Detection Image +# cv2.imshow("Canny Edge Detection", edges) + +# cv2.waitKey(0) + +# cv2.destroyAllWindows()