diff --git a/Plots/Matching Method Comparison/CCOEFF.png b/Plots/Matching Method Comparison/CCOEFF.png new file mode 100644 index 0000000..0d336f5 Binary files /dev/null and b/Plots/Matching Method Comparison/CCOEFF.png differ diff --git a/Plots/Matching Method Comparison/CCOEFF_NORMED.png b/Plots/Matching Method Comparison/CCOEFF_NORMED.png new file mode 100644 index 0000000..c472562 Binary files /dev/null and b/Plots/Matching Method Comparison/CCOEFF_NORMED.png differ diff --git a/Plots/Matching Method Comparison/CCORR.png b/Plots/Matching Method Comparison/CCORR.png new file mode 100644 index 0000000..b069868 Binary files /dev/null and b/Plots/Matching Method Comparison/CCORR.png differ diff --git a/Plots/Matching Method Comparison/CCORR_NORMED.png b/Plots/Matching Method Comparison/CCORR_NORMED.png new file mode 100644 index 0000000..143acd4 Binary files /dev/null and b/Plots/Matching Method Comparison/CCORR_NORMED.png differ diff --git a/Plots/Matching Method Comparison/SQDIFF.png b/Plots/Matching Method Comparison/SQDIFF.png new file mode 100644 index 0000000..98f7a39 Binary files /dev/null and b/Plots/Matching Method Comparison/SQDIFF.png differ diff --git a/Plots/Matching Method Comparison/SQDIFF_NORMED.png b/Plots/Matching Method Comparison/SQDIFF_NORMED.png new file mode 100644 index 0000000..c96b853 Binary files /dev/null and b/Plots/Matching Method Comparison/SQDIFF_NORMED.png differ diff --git a/src/__main__.py b/src/__main__.py index c9a84ed..306e52e 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -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)