如何对多幅图像进行傅里叶变换并将输出保存为单个对象

How to Fourier Transform multi images and save output into single object

我有 96 张不同尺寸和像素大小的 jpeg 无人机正射影像。我试图通过使用基于非参考的图像质量技术来确定每个正射影像的质量。这需要使用傅里叶变换将图像从空间域转换到频域。分析频率的分布可以深入了解图像中的模糊和噪声量,从而了解图像的质量,因为模糊会减少高频的数量。

但是,为了比较不同图像的质量,我需要创建一个索引,该索引必须对我的整个数据集进行归一化,这将允许我比较我的数据集中图像之间的图像质量,但不适用于我的数据集之外的图像(这没问题)。为此,我需要一起分析所有 96 jpeg 的频率分布,并确定,比如说,前 15% 最高频率的值。如果我知道我的数据集的最高频率,我可以使用它来定义一个阈值来创建我的图像质量指数。

所以我的问题是。我如何创建一个循环来读取我的所有图像、应用高斯模糊、应用傅里叶变换、将所有频率的分布保存到一个对象中,然后识别我的数据集中前 15% 的最高频率?

这是我迄今为止创建的用于处理一张图片的代码:

import numpy as np
import cv2
from matplotlib import pyplot as plt

img = cv2.imread('Image1.jpg', 0)

# Smooting by gaussian blur to remove noise
imgSmooth = cv2.GaussianBlur(img, (5, 5), 0)

# Fourier transform
dft = cv2.dft(np.float32(imgSmooth), flags=cv2.DFT_COMPLEX_OUTPUT)
dft_shift = np.fft.fftshift(dft)
magnitude_spectrum = 20 * np.log(cv2.magnitude(dft_shift[:, :, 0], dft_shift[:, :, 1]))

我是 python 的新手,因为我通常使用 R 编写代码。非常感谢任何帮助或建议。

根据我对问题的理解,你想计算每张图片的平均频率,然后得到这些图像中前 15% 的频率值。我们可以通过以下方式做到这一点:

import numpy as np
import cv2
import os
from matplotlib import pyplot as plt

images_dir = 'folder/containing/images/'
images_list = os.listdir(images_dir)
images_mean_freq = []

for img_file in images_list:
    img_path = os.path.join(images_dir, img_file)
    img = cv2.imread(img_path, 0)

    # Smooting by gaussian blur to remove noise
    imgSmooth = cv2.GaussianBlur(img, (5, 5), 0)

    # Fourier transform
    dft = cv2.dft(np.float32(imgSmooth), flags=cv2.DFT_COMPLEX_OUTPUT)
    dft_shift = np.fft.fftshift(dft)
    magnitude_spectrum = 20 * np.log(cv2.magnitude(dft_shift[:, :, 0], dft_shift[:, :, 1]))
    # get the standard deviation of the frequencies
    img_mean_freq = np.mean(magnitude_spectrum)
    images_mean_freq.append(img_mean_freq)
# then we can get the value of the top 15% highest frequencies, that is the 85% percentile of the distribution
top_15 = np.percentile(images_mean_freq, 85)
# finally we can select which images are above (or below) this top 15% threshold
images_above_top_15 = [images_list[idx] for idx in range(len(images_list)) if images_mean_freq[idx] > top_15]