图像处理:肤色检测、一些滤镜和EXIF标签






4.93/5 (19投票s)
肤色检测的简单算法和一些有用的滤镜
引言
RedMatter 库是一个简单的工具,包含用于肤色检测和色彩校正的滤镜,以及用于读取EXIF标签的工具。你也可以开发自己的滤镜并使用它 - 这非常容易。目前RedMatter包含以下滤镜和工具:
- 肤色检测滤镜:先验和参数化算法的实现
- 柔和轮廓滤镜
- 矩形暗角滤镜
- 色彩波纹滤镜
- 选择性单色滤镜
- 统计色彩校正工具
- EXIF标签读取工具
- 附加:简单的分形绘制
Using the Code
肤色检测滤镜
先验肤色检测方法使用一组规则。这些规则在色彩空间中创建一个多边形。例如:
(R > 95 and G > 40 and B < 20 and max{R, G, B} – min{ R, G, B }> 15 and |R - G| > 15 and R > G and R > B) or (R > 220 and G > 210 and B > 170 and |R - G| = 15 and R > B and G > B)
或者

所有肤色检测类都实现一个简单的接口 ISkinDetector
public interface ISkinDetector: IImageSelector
{
bool IsSkin(Color color);
}
你可以非常容易地使用这些滤镜
BaseDetector detector = new BaseDetector(sourceImage, new SimpleSkinDetector());
pbxImage.Image = detector.SkinDetectionImage;
该库包含六个具有不同规则集的先验滤镜。

图1. 先验肤色检测。
参数化方法(例如,高斯方法)使用与皮肤样本的图像进行比较。皮肤颜色的分布可以用椭圆高斯联合概率密度函数 (PDF) 建模,定义如下:
这里,c 是颜色向量,µ 和 Ss 是分布参数。
其中 n 是皮肤颜色样本 cj 的总数。
用法示例
// corrImage – It is sample of skin.
GaussianSkinDetector gauss = new GaussianSkinDetector(corrImage);
gauss.Threshold = 6;
BaseDetector detector = new BaseDetector(sourceImage, gauss);
pbxImage.Image = detector.SkinDetectionImage;
柔和轮廓滤镜
用法示例
SoftContourFilter soft = new SoftContourFilter(sourceImage);
soft.Softness = 20.0;
soft.Threshold = 125;
pbxImage.Image = soft.ResultImage;
图2. 柔和轮廓滤镜。
矩形暗角滤镜
代码示例
VignetteFilter vign = new VignetteFilter(sourceImage);
vign.Fade = 35;
vign.VignetteWidth = 50;
pbxImage.Image = vign.ResultImage;

图3. 简单的暗角。
色彩波纹滤镜
这种效果类似于旧电视上的噪点。
图4.色彩波纹效果。
你可以非常容易地使用这个滤镜
WavesFilter waves = new WavesFilter(sourceImage);
waves.Period = 50;
waves.Fade = 0.5;
pbxImage.Image = waves.ResultImage;
选择性单色滤镜
你看过电影“罪恶之城”吗?这种效果类似于电影的视觉设计。


图5. “罪恶之城”效果。
这非常简单
SinCityFilter sin = new SinCityFilter(sourceImage, colorDialog.Color);
sin.Tolerance = 50;
pbxImage.Image = sin.ResultImage;
统计色彩校正
+
=
图6. 统计色彩校正。
我们需要两张图片 - 用于校正的图片和颜色源图片。代码示例:
StatisticColorCorrector scc = new StatisticColorCorrector(sourceImage, corrImage);
pbxImage.Image = scc.ResultImage;
EXIF标签读取
可交换图像文件格式 (Exif) 是数字相机使用的图像文件格式规范(有关所有规范,请参阅 此处)。
你可以获取所有EXIF标签的列表
PropertyReader pr = new PropertyReader(bitmap);
foreach (EXIFTag tag in pr.GetAllTags())
{
// some code with { tag.TagName, tag.TagValue }
}
图7. Exif标签。
结论
这个库对于图像处理、解决肤色检测问题以及创建滤镜非常有用。我经常在我的研究中使用这个库。