检查文本图像之间的可见性(对比度?)与背景图像顶部的透明度 [英] Check visibility (contrast?) between text image with transparency on top of background image

查看:51
本文介绍了检查文本图像之间的可见性(对比度?)与背景图像顶部的透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两张图片:一张带有彩色文本和透明背景,另一张带有随机背景(可以是任何东西...纯色、照片、绘画等).基本上,我想知道粘贴到图像背景上时文本的可见/可读程度(大约)有多少,并在需要时采取措施增加图像之间的对比度.我的猜测是我应该对两个图像的颜色直方图进行某种比较,但我不确定哪种方法是正确的.

例如考虑以下图像:

如您所见,由于文本和背景之间的对比度很小,因此文本可读性不强.这只是一个例子,我正在寻找解决这个问题的一般方法(文本和背景可以是任何东西).理想情况下,我想计算应用于文本和/或背景的变换以提高可读性(例如添加/减去亮度、饱和度等).

我正在使用 python 3,

如 Anthony Thyssen 在其出色的教程页面中所述

或者这个:

另一种可能性是将文本绘制两次,一次为亮色,一次为暗色,第一次添加 x,y 偏移和模糊,使其看起来像第二次硬轮廓后面的软阴影,未模糊的版本.

I have two images: one with colored text and transparent background and another with a random background (could be anything...solid color, photo, painting, etc). Basically I would like to know how much (approximately) the text will be visible/readable when pasted on the image background and take action to increase the contrast between images if needed. My guess is that I should do some sort of comparison between the color histograms of the two images, but I am not sure which is the right way to do so.

Consider for example the following images:

As you can see the text is no very readable due to little contrast between text and background. This is just an example, I am looking for a general approach to solve this problem (text and background could be anything). Ideally I would like to compute the transformations to apply to text and/or background to improve readability (e.g. adding/subtracting brightness, saturation, etc).

I am using python 3, PIL and OpenCV.

解决方案

The classic technique is to draw a "dim box" behind the text like this:

as described by Anthony Thyssen in his excellent tutorial pages here.

So, in your specific case, you could convert the text to greyscale and get its average grey value. If the grey value is light (i.e. greater than 128 on a scale of 0..255) make the dim box dark, and if the average greyscale value is under 128 make the dim box light.

That buys you this:

Or this:

Another possibility is to draw the text twice, once in a bright and once in a dark colour, adding an x,y offset and a blur the first time so it looks like a soft shadow behind the hard outline of the second, unblurred version.

这篇关于检查文本图像之间的可见性(对比度?)与背景图像顶部的透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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