我正在开发基于微软论文白板扫描和图像增强的自动图像增强
在“白平衡和图像增强”部分中,它们提供了增强步骤:
首先:他们估计扫描文档或检测到的白板的背景:
1. “将白板区域划分为矩形单元格。单元格大小应与我们预期的白板上单个字符的大小大致相同(在我们的实现中为 15 x 15 像素)。”
然后
2. “将每个单元格中的像素按亮度值排序。由于墨水吸收了入射光,因此白板像素的亮度高于笔划像素”。因此,单元格内的白板颜色是最高的颜色亮度。在实践中,我们对前 25 个百分位像素的颜色进行平均,以减少传感器噪声引入的误差"
然后
3. “通过在RGB空间中局部拟合一个平面来过滤单元格的颜色。偶尔会有完全被笔划覆盖的单元格,因此在步骤2中计算的单元格颜色是不正确的。这些颜色被拒绝为异常值局部拟合平面并被其邻居的插值替换。”
我的问题是第二步和第三步:
他们如何获得亮度值,我应该将输入图像转换为 YUV 颜色空间并从 Y 通道获取亮度值还是只在 RGB 颜色空间上工作?
如何在 RGB 空间中拟合局部平面?
这是我的 python 代码,我试图从输入图像中创建单元格,从 YUV 颜色空间中获取亮度值,以及一个简单的结果,与他们在论文中得到的结果相比似乎不正确。
蟒蛇代码:
import cv2
import numpy as np
## Return List of cells from a given Image
def SubImage(image):
Cells = []
CellRows = []
for i in range(0,rows/CellSize):
subIm = image[i*CellSize:(i+1)*CellSize,:]
CellRows.append(subIm)
for img in CellRows:
for i in range(0,cols/CellSize):
subIm = img[:,i*CellSize:(i+1)*CellSize]
Cells.append(subIm)
return Cells
## Sort luminosity Value
def GetLuminance(Cells):
luminance = []
for cel in Cells:
luminance.append(cel.max())
return luminance
## Estimate the background color of the white board
def UniformBackground(CelImage,img,luminance):
a = 0
for c in range(0,len(CelImage)):
cel = CelImage[c]
for i in range(0,cel.shape[0]):
for j in range(0, cel.shape[1]):
cel[i,j] = min(1,cel[i,j]/ luminance[c])
for i in range(0,rows/CellSize):
for j in range(0,cols/CellSize):
img[i*CellSize:(i+1)*CellSize,j*CellSize:(j+1)*CellSize] = CelImage[a]
a = a + 1
if __name__ == '__main__':
img = cv2.imread('4.png')
CellSize = 15
rows,cols,depth = img.shape
if (rows%CellSize !=0):
rows = rows - rows%CellSize
if (cols%CellSize !=0):
cols = cols - cols%CellSize
yuvImg = cv2.cvtColor(img, cv2.COLOR_BGR2YUV)
# Get cells from Y channel
CellsY = SubImage(yuvImg[:,:,0])
CellsB = SubImage(img[:,:,0])
CellsG = SubImage(img[:,:,1])
CellsR = SubImage(img[:,:,2])
# Get Luminance From Y cells
LuminanceY = GetLuminance(CellsY)
# Uniform Background
UniformBackground(CellsB, img[:,:,0], LuminanceY)
UniformBackground(CellsG, img[:,:,1], LuminanceY)
UniformBackground(CellsR,img[:,:,2], LuminanceY)
#bgrImg = cv2.cvtColor(imgB, cv2.COLOR_GRAY2BGR)
#print imgB
cv2.imwrite('unifrom.jpg',img)
输入白板图像:
输出图像:
预期输出: