二維數組中的峰值偵測
挑戰:
挑戰:檢測
偵測的峰值代表狗爪下的壓力測量值,以描繪解剖學分區。<code class="python">import numpy as np import matplotlib.pyplot as plt from scipy.ndimage.filters import maximum_filter from scipy.ndimage.morphology import generate_binary_structure, binary_erosion # Define the paw data paw_data = np.loadtxt("paws.txt").reshape(4, 11, 14) # Define the 8-connected neighborhood neighborhood = generate_binary_structure(2, 2) # Function to detect peaks def detect_peaks(image): # Local maximum filter local_max = maximum_filter(image, footprint=neighborhood) == image # Create a mask of the background background = (image == 0) # Erode the background to remove artifacts eroded_background = binary_erosion(background, structure=neighborhood, border_value=1) # Final mask containing only peaks detected_peaks = local_max ^ eroded_background return detected_peaks # Detect peaks for each paw paws = [p.squeeze() for p in np.vsplit(paw_data, 4)] detected_peaks_list = [] for paw in paws: detected_peaks = detect_peaks(paw) detected_peaks_list.append(detected_peaks) # Plot the results fig, axs = plt.subplots(4, 2, figsize=(10, 10)) for i, paw in enumerate(paws): axs[i, 0].imshow(paw) axs[i, 0].set_title("Paw Image") axs[i, 1].imshow(detected_peaks_list[i]) axs[i, 1].set_title("Peak Detection") plt.tight_layout() plt.show()</code>
實際的解決方案包括使用局部最大濾波器來識別峰值。方法如下:
以上是如何使用局部最大濾波來識別代表狗爪的二維數組中的壓力峰值?的詳細內容。更多資訊請關注PHP中文網其他相關文章!