简体   繁体   中英

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.

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:

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.

kmario23 commented 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 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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