移除彩色图像的晕影滤镜 [英] Remove vignette filter of colored image

查看:39
本文介绍了移除彩色图像的晕影滤镜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Python OpenCV图像处理的新手.我要删除图像的边框/轮廓阴影,如下所示.我检查了"

解决方案

您的边框/轮廓阴影问题使我想起了小插图滤镜.如果您想了解更多有关此问题的信息,可以查看此

现在,我们需要增加图像的亮度.为此,我们将图像转换为HSV并增加饱和度和值矩阵的值.要更详细地了解它,您可以参考此

与原始明亮图像相比的结果.

如果没有逆晕影滤镜,结果将是什么样子.

I am new to Python OpenCV image processing. I want to remove the border/outline shadow of images as shown below. I checked 'how to remove shadow from scanned images' which does not work for me. Is this even possible?

解决方案

Your problem of border/outline shadows reminded me of the vignette filter. You can have a look at this question if you want to know more about it. So essentially our task to remove the effect of the vignette filter and then increase brightness.

#####VIGNETTE
import cv2
import numpy as np

img = cv2.imread('Paris.jpg')
height, width = img.shape[:2]
original = img.copy()
# generating vignette mask using Gaussian kernels
kernel_x = cv2.getGaussianKernel(width, 150)
kernel_y = cv2.getGaussianKernel(height, 150)
kernel = kernel_y * kernel_x.T
mask = 255 * kernel / np.linalg.norm(kernel)

# applying the mask to each channel in the input image
for i in range(3):
    img[:, :, i] = img[:, :, i] * mask


cv2.imshow('Original', original)
cv2.imshow('Vignette', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

To counter the effect change img[:, :, i] = img[:, :, i] * mask to img[:, :, i] = img[:, :, i] / mask

Now we need to increase the brightness of the image. For this, we will convert the image to HSV and increase the values of saturation and value matrices. To know about it in more detail you can refer to this article.

#THE FULL CODE
import cv2
import numpy as np

img = cv2.imread('shadow.jpg')
original = cv2.imread('bright.jpg')
height, width = img.shape[:2]
# generating vignette mask using Gaussian kernels
kernel_x = cv2.getGaussianKernel(width, 150)
kernel_y = cv2.getGaussianKernel(height, 150)
kernel = kernel_y * kernel_x.T
mask = 255 * kernel / np.linalg.norm(kernel)

test = img.copy()
for i in range(3):
    test[:, :, i] = test[:, :, i] / mask    

hsv = cv2.cvtColor(test, cv2.COLOR_BGR2HSV)
hsv = np.array(hsv, dtype = np.float64)
hsv[:,:,1] = hsv[:,:,1]*1.3 ## scale pixel values up or down for channel 1(Lightness)
hsv[:,:,1][hsv[:,:,1]>255]  = 255
hsv[:,:,2] = hsv[:,:,2]*1.3 ## scale pixel values up or down for channel 1(Lightness)
hsv[:,:,2][hsv[:,:,2]>255]  = 255
hsv = np.array(hsv, dtype = np.uint8)
test = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)


cv2.imshow('Original_bright', original)
cv2.imshow('Original_dark', img)
cv2.imshow('Result', test)
cv2.waitKey(0)
cv2.destroyAllWindows()

The result compared with the original bright image.

How the result would have looked like without the inverse vignette filter.

这篇关于移除彩色图像的晕影滤镜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆