[英]Do I need to normalize image after blurring? (if the sum of gaussian filter is not 1)
hi I smooth grayscale image using gaussian blur.嗨,我使用高斯模糊平滑灰度图像。 And I wonder do i have to normalize after gaussian blur.我想知道我是否必须在高斯模糊后进行归一化。
when i make 3x3 gaussian kernel, the kernel's value is [[0.05856 0.09656 0.05856] [0.09656 0.1592 0.09656] [0.05856 0.09656 0.05856]] and the sum of gaussian filter is 0.78.当我制作 3x3 高斯内核时,内核的值为 [[0.05856 0.09656 0.05856] [0.09656 0.1592 0.09656] [0.05856 0.09656 0.05856]],高斯滤波器的总和为 0.78。
I think if the sum of gaussian filter is 1, then i dont have to do normalization.我认为如果高斯滤波器的总和为 1,那么我不必进行归一化。 but is this case, the sum is not 1.但在这种情况下,总和不是 1。
so, does the normalization is necessary?那么,标准化是否必要? or can I just clip the value to the range0~255或者我可以将值剪辑到范围 0~255
< python code > <python代码>
def Gaussian_kernel(kernel_size=3, sig=1):
gaussian = np.empty((kernel_size,kernel_size), dtype=np.float32)
index = kernel_size//2 #center = (0,0) gaussian filter
for i in range(-index , index+1):
for j in range(-index, index+1):
t1 = 1/(2*np.pi*sig**2)
t2 = np.exp(-(i**2 +j**2)/(2*sig**2))
gaussian[i+index][j+index] = t1*t2
return gaussian
def Gaussianblur(image,kernel,sig):
H = image.shape[0]
W = image.shape[1]
blurImage = np.empty((H-kernel+1,W-kernel+1), dtype=np.uint16)
#stride=1, padding=0
gau_kernel=Gaussian_kernel(kernel,sig)
gaumax=1
for i in range(H-kernel+1):
for j in range(W-kernel+1):
Gau=0
for x in range(kernel):
for y in range(kernel):
Gau += gau_kernel[x][y] * image[i+x][j+y]
blurImage[i][j] = Gau
if Gau > gaumax : gaumax=Gau
#normalization
for i in range(H-kernel+1):
for j in range(W-kernel+1):
blurImage[i][j] *=255.0/gaumax
#clip
#blurImage=np.clip(blurImage,0,255)
return blurImage
实际上,我们总是对高斯核进行归一化,使高斯滤波器的和为 1。对于 sum>1 的核,结果会更亮,反之亦然。
The brightness in your image has been multiplied by 0.78, it is 78% as bright as the input image.图像中的亮度乘以 0.78,是输入图像亮度的 78%。 You need to divide by 0.78 to get the original brightness back.您需要除以 0.78 才能恢复原始亮度。 This is not the same thing as normalizing the image though.不过,这与标准化图像不同。
Blurring kernels must sum to 1 to avoid a change in brightness.模糊内核的总和必须为 1 以避免亮度变化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.