如何应用傅立叶变换来提取图像中某些边缘的频率?
How to apply Fourier transform to extract the frequency of only certain edges in an image?
标题好像有点不清楚,不过我还是把原委讲给大家听听,希望大家多多指教。
我正在尝试检测给定图像中的某些特定边缘,尤其是那些比其他边缘出现得更多的边缘。为此,最好的办法是进行傅立叶变换,将离散像素域映射到频域。在应用傅里叶变换之前,我必须测量一些理想边缘的距离的平均值,然后使用傅里叶变换来找到它们的频率。问题是如何设置 FFT 算法的平均距离(在 Python 或 Matlab 上)。
谢谢
FFT 将 return 1
和 number_of_samples/2
之间每个重复元素的频率。
因此,您将寻找 image_width/100
附近的频率峰值。
如果您的 FFT 输出数组是从零开始索引的,FFT_array[0]
将是稳态偏移,而 FFT_array[image_width/100]
将是您要查找的峰值。
在伪代码中,您的函数类似于:
image_full = # 2d array of pixel values ex: [[1,2,3],[4,5,6],[7,8,9]]
width_slice_center = image_full[int(len(image_full)/2)]
FFT_slice = FFT(width_slice_center)
#this is where you'll find the values that you are looking for
range = 5 #how far away from exactly 100px you want to look for edges
frequency_100 = int(len(image_full[0])/100) #how many times something 100px wide would appear in image
total_edges_signal = sum(FFT_slice[frequency_100-5:frequency_100+5]) #signal strength of edges in at given width
#then tune the total_edges_signal using an image with known edges
total_edges = int(total_edges_signal*tuning_parameter)
我试图使伪代码尽可能通用,您应该可以修改这个想法以匹配多种数据类型。希望对您有所帮助。
标题好像有点不清楚,不过我还是把原委讲给大家听听,希望大家多多指教。 我正在尝试检测给定图像中的某些特定边缘,尤其是那些比其他边缘出现得更多的边缘。为此,最好的办法是进行傅立叶变换,将离散像素域映射到频域。在应用傅里叶变换之前,我必须测量一些理想边缘的距离的平均值,然后使用傅里叶变换来找到它们的频率。问题是如何设置 FFT 算法的平均距离(在 Python 或 Matlab 上)。
谢谢
FFT 将 return 1
和 number_of_samples/2
之间每个重复元素的频率。
因此,您将寻找 image_width/100
附近的频率峰值。
如果您的 FFT 输出数组是从零开始索引的,FFT_array[0]
将是稳态偏移,而 FFT_array[image_width/100]
将是您要查找的峰值。
在伪代码中,您的函数类似于:
image_full = # 2d array of pixel values ex: [[1,2,3],[4,5,6],[7,8,9]]
width_slice_center = image_full[int(len(image_full)/2)]
FFT_slice = FFT(width_slice_center)
#this is where you'll find the values that you are looking for
range = 5 #how far away from exactly 100px you want to look for edges
frequency_100 = int(len(image_full[0])/100) #how many times something 100px wide would appear in image
total_edges_signal = sum(FFT_slice[frequency_100-5:frequency_100+5]) #signal strength of edges in at given width
#then tune the total_edges_signal using an image with known edges
total_edges = int(total_edges_signal*tuning_parameter)
我试图使伪代码尽可能通用,您应该可以修改这个想法以匹配多种数据类型。希望对您有所帮助。