在频域中改变亮度
Change brightness in frequency domain
我可能不明白频域是如何工作的。对于一个项目,我必须使用 Python 并且不在空间域中工作来更改图像的亮度。
目前我可以通过卷积应用一些模糊滤镜,如下例所示:
def arithmeticMeanFilter(self, img):
img = img.convert('RGB')
open_cv_image = np.array(img)
red = open_cv_image[:, :, 0]
green = open_cv_image[:, :, 1]
blue = open_cv_image[:, :, 2]
mean_arithmetic = np.ones((9, 9))*(1/81)
width, height, _ = open_cv_image.shape
kernel1 = np.zeros((width, height))
kernel1[:mean_arithmetic.shape[0], :mean_arithmetic.shape[1]] = mean_arithmetic
kernel1 = np.fft.fft2(kernel1)
im = np.array(red)
fim = np.fft.fft2(im)
Rx = np.real(np.fft.ifft2(kernel1 * fim)).astype(float)
im = np.array(green)
fim = np.fft.fft2(im)
Gx = np.real(np.fft.ifft2(kernel1 * fim)).astype(float)
im = np.array(blue)
fim = np.fft.fft2(im)
Bx = np.real(np.fft.ifft2(kernel1 * fim)).astype(float)
open_cv_image[:, :, 0] = abs(Rx)
open_cv_image[:, :, 1] = abs(Gx)
open_cv_image[:, :, 2] = abs(Bx)
img = Image.fromarray(open_cv_image)
return img
但是如何使用此技术更改亮度?
更改图像中的亮度是通过将每个像素乘以一个常数来实现的。
因为Fourier transform is a linear operation,在空间域乘以一个常数等同于在频域乘以同一个常数
函数的线性度 F 定义为:
aF(x) + bF(y) = F(ax + by)
从这个等式很容易证明 aF(x) = F(ax),或者,正如我上面所说的,在一个域中乘以等于在其他.
that multiplication in the frequency domain is convolution in the spatial domain. This is true. But since we’re dealing with a constant, things are a bit simpler. In any case, one can see that a constant function in the frequency domain is an impulse (or dirac delta) function在空间域。与脉冲函数进行卷积与乘以常数相同。
为了改变亮度而进入频域是一种浪费,但如果你已经在那里,你可以这样做。
我可能不明白频域是如何工作的。对于一个项目,我必须使用 Python 并且不在空间域中工作来更改图像的亮度。
目前我可以通过卷积应用一些模糊滤镜,如下例所示:
def arithmeticMeanFilter(self, img):
img = img.convert('RGB')
open_cv_image = np.array(img)
red = open_cv_image[:, :, 0]
green = open_cv_image[:, :, 1]
blue = open_cv_image[:, :, 2]
mean_arithmetic = np.ones((9, 9))*(1/81)
width, height, _ = open_cv_image.shape
kernel1 = np.zeros((width, height))
kernel1[:mean_arithmetic.shape[0], :mean_arithmetic.shape[1]] = mean_arithmetic
kernel1 = np.fft.fft2(kernel1)
im = np.array(red)
fim = np.fft.fft2(im)
Rx = np.real(np.fft.ifft2(kernel1 * fim)).astype(float)
im = np.array(green)
fim = np.fft.fft2(im)
Gx = np.real(np.fft.ifft2(kernel1 * fim)).astype(float)
im = np.array(blue)
fim = np.fft.fft2(im)
Bx = np.real(np.fft.ifft2(kernel1 * fim)).astype(float)
open_cv_image[:, :, 0] = abs(Rx)
open_cv_image[:, :, 1] = abs(Gx)
open_cv_image[:, :, 2] = abs(Bx)
img = Image.fromarray(open_cv_image)
return img
但是如何使用此技术更改亮度?
更改图像中的亮度是通过将每个像素乘以一个常数来实现的。
因为Fourier transform is a linear operation,在空间域乘以一个常数等同于在频域乘以同一个常数
函数的线性度 F 定义为:
aF(x) + bF(y) = F(ax + by)
从这个等式很容易证明 aF(x) = F(ax),或者,正如我上面所说的,在一个域中乘以等于在其他.
为了改变亮度而进入频域是一种浪费,但如果你已经在那里,你可以这样做。