建设电影网站的关键,wordpress简码怎么用,wordpress 添加文章字段,挂机宝可以做网站吗1. 引言
欢迎继续来到我们的图像处理系列#xff0c;在这里我们将探讨白平衡的关键技术。如果大家曾经拍过一张看起来暗淡、褪色或颜色不自然的照片#xff0c;那么此时大家就需要了解到白平衡技术的重要性。在本文中#xff0c;我们将深入探讨白平衡的概念#xff0c;并探…1. 引言
欢迎继续来到我们的图像处理系列在这里我们将探讨白平衡的关键技术。如果大家曾经拍过一张看起来暗淡、褪色或颜色不自然的照片那么此时大家就需要了解到白平衡技术的重要性。在本文中我们将深入探讨白平衡的概念并探索各种算法来提高图像的成像质量。 闲话少说我们直接开始吧
2. 定义
白平衡是一种用于校正由不同照明条件引起的图像中的颜色校正的技术。这是一个调整图像颜色对比度的过程使白色看起来像白色使黑色看起来像黑色。这对于确保图像中的颜色是准确的并且对人眼来说是自然的是非常重要的。
3. 加载样例图像
好的按照惯例我们还是首先导入我们需要的python库如下
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from skimage import io, img_as_ubyte
from skimage.io import imread, imshow
from matplotlib.patches import Rectangle接着使用以下代码加载我们的样例图像代码如下
from skimage import io
import matplotlib.pyplot as pltimage io.imread(qmark.png)
plt.figure(figsize(10,10))
plt.title(Original Image)
plt.imshow(image)
plt.show()得到结果如下
4. 统计数据分析
为了分析图像中的统计信息让我们使用以下函数
def calc_color_overcast(image):# Calculate color overcast for each channelred_channel image[:, :, 0]green_channel image[:, :, 1]blue_channel image[:, :, 2]# Create a dataframe to store the resultschannel_stats pd.DataFrame(columns[Mean, Std, Min, Median, P_80, P_90, P_99, Max])# Compute and store the statistics for each color channelfor channel, name in zip([red_channel, green_channel, blue_channel], [Red, Green, Blue]):mean np.mean(channel)std np.std(channel)minimum np.min(channel)median np.median(channel)p_80 np.percentile(channel, 80)p_90 np.percentile(channel, 90)p_99 np.percentile(channel, 99)maximum np.max(channel)channel_stats.loc[name] [mean, std, minimum, median, p_80, p_90, p_99, maximum]return channel_stats得到结果如下 从上面数据帧中的结果可以明显看出图像中出现了蓝色伪影。仔细分析具有每个百分位数的最高平均值、中值都是蓝色通道最大。
5. White Patch Algorithm
白色补丁算法是图像处理中最常用的一种颜色平衡方法旨在通过缩放颜色通道来校正图像中的颜色投射从而使每个通道中最亮的像素变为白色。这是通过假设图像中最亮的像素是白色来实现的。
相应的代码实现如下
def white_patch(image, percentile100):Returns a plot comparison of original and corrected/white balanced image using the White Patch algorithm.Parameters----------image : numpy arrayImage to process using white patch algorithmpercentile : integer, optionalPercentile value to consider as channel maximumwhite_patch_image img_as_ubyte((image * 1.0 / np.percentile(image, percentile, axis(0, 1))).clip(0, 1))# Plot the comparison between the original and white patch corrected imagesfig, ax plt.subplots(1, 2, figsize(10, 10))ax[0].imshow(image)ax[0].set_title(Original Image)ax[0].axis(off)ax[1].imshow(white_patch_image, cmapgray)ax[1].set_title(White Patch Corrected Image)ax[1].axis(off)plt.show()# Read the input image
image imread(qmark.png)# Call the function to implement white patch algorithm
white_patch(image, 100)结果如下 使用默认参数 percentile100并没有明显改善我们的图像因为图像具有中RGB最大值已经为[255255255]观察上一章节中的统计信息可以看到其中最大值和99百分位数都是255。
为了解决上述问题我们可以将像素值的较低百分位数视为最大值而不是绝对最大值。因此让我们尝试下85百分位
white_patch(image, 85)结果如下 使用第85个百分位正确地改善了图像的颜色。可以看到以下颜色已正确分配 问号块黄色 马里奥帽子红色 背包棕色 鞋子黑色和白色 墙壁不同深浅的蓝色 6. 优缺点分析
我们接下来分析上述算法的优缺点其有点可以总结如下
简单易用。可以有效地纠正具有主要白色区域或中性灰色区域的图像中的白平衡问题。当图像中有明显的明亮区域时效果很好。
其缺点可以概括如下
假设图像中最亮的颜色是白色这可能并不总是正确的。如果假设不成立可能会导致过度校正从而导致不自然的颜色或伪影。可能导致图像的某些区域出现颜色偏移或伪影。
7. 总结
本文重点介绍了使用White Patch Algorithm进行白平衡进而改善图像成像质量的算法细节并总结了该算法的优缺点并给出了相应的代码示例。
您学废了嘛
参考