简体   繁体   English

在频域中更改亮度

[英]Change brightness in frequency domain

I probably did not understand how frequency domain works. 我可能不明白频域是如何工作的。 For a project I have to change the brightness of an image with Python and without working in the spatial domain. 对于一个项目,我必须使用Python更改图像的亮度,而不必在空间域中工作。

At the moment I can apply some blur filters through convolution, as in the example below: 目前我可以通过卷积应用一些模糊滤镜,如下例所示:

 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

But how can I change brightness using this technique? 但是如何使用这种技术改变亮度呢?

Changing brightness in an image is accomplished by multiplying each pixel by a constant. 通过将每个像素乘以常数来实现改变图像中的亮度。

Because the Fourier transform is a linear operation , multiplying by a constant in the spatial domain is equivalent to multiplying by the same constant in the frequency domain. 因为傅立叶变换是线性运算 ,所以乘以空间域中的常数相当于乘以频域中的相同常数。

Linearity of a function F is defined as: 函数F的线性定义为:

aF(x) + bF(y) = F(ax + by) aF(x)+ bF(y)= F(ax + by)

From that equation it is easy to show aF(x) = F(ax) , or, as I stated above, multiplying in one domain is equivalent to multiplying in the other. 根据该等式,很容易显示aF(x)= F(ax) ,或者,如上所述,在一个域中的乘法相当于在另一个域中相乘。

kmario23 commented that multiplication in the frequency domain is convolution in the spatial domain. kmario23评论说 ,频域中的乘法是空间域中的卷积。 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 in the spatial domain. 在任何情况下,可以看出频域中的常数函数是空间域中的脉冲(或狄拉克三角洲)函数 Convolving with an impulse function is the same as multiplying by a constant. 与脉冲函数相关与乘以常数相同。

Going to the frequency domain for a change in brightness is wasteful, but if you're already there you can do it this way. 进入频域以改变亮度是浪费,但如果你已经在那里,你可以这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM