mirror of
https://github.com/balajsra/EECS-442-WN19-DIC-Project.git
synced 2025-09-03 17:33:14 +00:00
Matching Method Comparison
Used OpenCV to find matching template and draw arrows of displacement. Made a plot using each template matching method. SQDIFF and SQDIFF_NORMED appear to be best.
This commit is contained in:
BIN
Plots/Matching Method Comparison/CCOEFF.png
Normal file
BIN
Plots/Matching Method Comparison/CCOEFF.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 61 KiB |
BIN
Plots/Matching Method Comparison/CCOEFF_NORMED.png
Normal file
BIN
Plots/Matching Method Comparison/CCOEFF_NORMED.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 105 KiB |
BIN
Plots/Matching Method Comparison/CCORR.png
Normal file
BIN
Plots/Matching Method Comparison/CCORR.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 68 KiB |
BIN
Plots/Matching Method Comparison/CCORR_NORMED.png
Normal file
BIN
Plots/Matching Method Comparison/CCORR_NORMED.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 110 KiB |
BIN
Plots/Matching Method Comparison/SQDIFF.png
Normal file
BIN
Plots/Matching Method Comparison/SQDIFF.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 115 KiB |
BIN
Plots/Matching Method Comparison/SQDIFF_NORMED.png
Normal file
BIN
Plots/Matching Method Comparison/SQDIFF_NORMED.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 115 KiB |
@@ -44,8 +44,11 @@ def read_images():
|
||||
filenames = os.listdir(image_dir)
|
||||
|
||||
images = []
|
||||
|
||||
images.append(None)
|
||||
|
||||
for file in filenames:
|
||||
images.append(cv2.imread(os.path.join(image_dir, file)))
|
||||
images.append(cv2.imread(os.path.join(image_dir, file), 0))
|
||||
|
||||
return images
|
||||
|
||||
@@ -100,5 +103,51 @@ def get_sift_distance(img1, img2):
|
||||
return distances
|
||||
|
||||
|
||||
def find_displacement(match_method):
|
||||
images = read_images()
|
||||
|
||||
specimen, load_disp_data = file_data.read_file("../Section001_Data.txt")
|
||||
|
||||
plt.figure(1)
|
||||
|
||||
reference = images[8]
|
||||
compare_img = images[12]
|
||||
|
||||
plt.imshow(reference, cmap="gray", vmin=0, vmax=255)
|
||||
|
||||
subset_size = 5
|
||||
subset_spacing = 20
|
||||
|
||||
for x in range(650, 2080, subset_spacing):
|
||||
for y in range(120, 500, subset_spacing):
|
||||
up_bound = (subset_size + 1) // 2
|
||||
low_bound = subset_size // 2
|
||||
|
||||
subset = reference[y-low_bound:y+up_bound, x-low_bound:x+up_bound]
|
||||
|
||||
res = cv2.matchTemplate(image=compare_img, templ=subset, method=match_method)
|
||||
|
||||
minVal, maxVal, minLoc, maxLoc = cv2.minMaxLoc(res)
|
||||
|
||||
dx = None
|
||||
dy = None
|
||||
|
||||
if match_method in [cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED]:
|
||||
dx = minLoc[0] - x
|
||||
dy = minLoc[1] - y
|
||||
elif match_method in [cv2.TM_CCORR, cv2.TM_CCORR_NORMED,
|
||||
cv2.TM_CCOEFF, cv2.TM_CCOEFF_NORMED]:
|
||||
dx = maxLoc[0] - x
|
||||
dy = maxLoc[1] - y
|
||||
|
||||
plt.arrow(x=x, y=y, dx=dx, dy=dy, color="yellow", length_includes_head=True, shape="full")
|
||||
|
||||
plt.show()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
# main()
|
||||
for match_method in [cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED,
|
||||
cv2.TM_CCORR, cv2.TM_CCORR_NORMED,
|
||||
cv2.TM_CCOEFF, cv2.TM_CCOEFF_NORMED]:
|
||||
find_displacement(match_method)
|
||||
|
Reference in New Issue
Block a user