Heatmap
This commit is contained in:
parent
d65bc9848a
commit
39202630d8
56
src/helpers/algorithms/canny_map.py
Normal file
56
src/helpers/algorithms/canny_map.py
Normal file
@ -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()
|
Loading…
Reference in New Issue
Block a user