简体   繁体   English

为什么将图像通过低通滤波器产生的值高于原始图像?

[英]Why is it that passing an image through a low pass filter yields values higher than the original image?

I have a hybrid image that was created by superimposing the low frequencies of one image with the high frequencies of another.我有一个混合图像,它是通过将一个图像的低频与另一个图像的高频叠加来创建的。 I'm trying to separate (de-hybridize) this image by passing it through a low-pass filter to extract the low frequencies (one of the two images), and then subtracting that from the original image to yield the other image (high frequencies).我试图通过将其通过低通滤波器以提取低频(两幅图像之一),然后从原始图像中减去该图像以产生另一幅图像(高频率)。

**Problem: ** When I extract the low frequencies, the values are all higher than the original image, so when I subtract the low frequencies from the original image, what's left is a bunch of negative values. **问题:**当我提取低频时,值都高于原始图像,所以当我从原始图像中减去低频时,剩下的是一堆负值。

Does anyone know why my low pass filter is yielding higher frequency values than the original image?有谁知道为什么我的低通滤波器产生比原始图像更高的频率值?

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from numpy.fft import fft2, ifft2, fftshift, ifftshift

# Make Gaussian filter
def makeGaussianFilter(numRows, numCols, sigma, highPass=True):
   centerI = int(numRows/2) + 1 if numRows % 2 == 1 else int(numRows/2)
   centerJ = int(numCols/2) + 1 if numCols % 2 == 1 else int(numCols/2)

   def gaussian(i,j):
      coefficient = np.exp(-1.0 * ((i - centerI)**2 + (j - centerJ)**2) / (2 * sigma**2))
      return 1 - coefficient if highPass else coefficient

   return np.array([[gaussian(i,j) for j in range(numCols)] for i in range(numRows)])

# Filter discrete Fourier transform
def filterDFT(imageMatrix, filterMatrix):
   shiftedDFT = fftshift(fft2(imageMatrix))
   filteredDFT = shiftedDFT * filterMatrix
   return ifft2(ifftshift(filteredDFT))

# Low-pass filter
def lowPass(imageMatrix, sigma):
   n,m = imageMatrix.shape
   return filterDFT(imageMatrix, makeGaussianFilter(n, m, sigma, highPass=False))

# Read in einsteinandwho.png and convert to format that can be displayed by plt.imshow
im3 = mpimg.imread('einsteinandwho.png')
rows = im3.shape[0]
cols = im3.shape[1]
img3 = np.ones((rows, cols, 4))
for i in range(rows):
    for j in range(cols):
        img3[i][j][0:3] = im3[i][j]
        img3[j][j][3] = 1

# Extract low frequencies and convert to format that can be displayed by plt.imshow
lowPassed = np.real(lowPass(im3, 10))
low = np.ones((rows, cols, 4))

for i in range(rows):
    for j in range(cols):
        low[i][j][0:3] = lowPassed[i][j]
        low[j][j][3] = 1

# Remove low frequencies from image
output = img3[:,:,0:3] - low[:,:,0:3]

Does anyone know why my low pass filter is yielding higher frequency values than the original image?有谁知道为什么我的低通滤波器产生比原始图像更高的频率值?

Do notice the difference between pixel values and frequency values.请注意像素值和频率值之间的差异。 You are seeing the pixel values being higher, not the frequency values!您看到的是像素值更高,而不是频率值!


When I run your code I see the high-frequency component having both negative and positive pixel values, not all negative values.当我运行您的代码时,我看到高频分量同时具有负像素值和正像素值,而不是所有负值。 It is expected for this image to have a zero mean.预计此图像的均值为零。 The zero frequency component (also called DC component) is the one that sets the mean pixel value.零频率分量(也称为 DC 分量)是设置平均像素值的分量。 By subtracting a low-pass filtered image, you are setting the zero frequency to 0, and thus setting the mean pixel value to 0 (the low-pass filtered image contains all of the power of the zero frequency).通过减去低通滤波图像,您将零频率设置为 0,从而将平均像素值设置为 0(低通滤波图像包含零频率的所有幂)。

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

相关问题 低通滤波器用于模糊图像 - Low Pass Filter for blurring an image 通过 scipy 低通滤波器传递 CuPy 数组 - Passing CuPy array through scipy low pass filter 为什么自适应阈值图像比原始图像小? - Why is adaptive threshold image smaller than the original? 如何对 python 中的 dicom 图像应用低通滤波器? - How to apply a low pass filter to a dicom image in python? 为什么要替换原始图像矩阵值? - Why is the original image matrix values getting replaced? 通过低通滤波器后的音频文件听起来很糟糕/嘈杂 - audio file sounds bad/noisy after passing through low pass filter 为什么CSV值多于图片的尺寸? - Why more CSV values than the dimension of image? 为什么我在 python 中使用 imread() 读取图像时,显示的图像与原始图像的颜色略有不同? - Why is it that when I use imread () in python to read my image, it shows an image with a slightly different color than my original image? 如何将多个分割的蒙版图像与原始图像叠加 - how to overlay more than one segmented mask image with original image 为什么使用CV2转换的视频文件(分辨率较低)比原始文件(分辨率较高)大 - Why is the converted video file (lower resolution) using CV2 larger than the original file (higher resolution)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM