我正在寻找一种类似自适应阈值处理的算法,但可以保留颜色。我试图将如下图所示的图像进行处理:
并使其看起来像这样:
如果有关系的话,我正在iOS上工作。
![original image](https://istack.dev59.com/2JNub.webp)
![processed image](https://istack.dev59.com/ZfP3K.webp)
kernel vec4 coreImageKernel (sampler i)
{
vec2 dc = destCoord();
// center pixel color
vec4 c = unpremultiply(sample(i, samplerTransform(i,dc+vec2(0.0,0.0))));
// for a whiteboard, the max of a neighborhood is likely to be the color
// of the whiteboard
vec4 cmax = c;
cmax = max(unpremultiply(sample(i, samplerTransform(i,dc+vec2(10.0,0.0)))), cmax);
cmax = max(unpremultiply(sample(i, samplerTransform(i,dc+vec2(-10.0,0.0)))), cmax);
cmax = max(unpremultiply(sample(i, samplerTransform(i,dc+vec2(0.0,10.0)))), cmax);
cmax = max(unpremultiply(sample(i, samplerTransform(i,dc+vec2(0.0,-10.0)))), cmax);
// normalize the center color according to the whiteboard color
vec4 r = c / cmax;
return premultiply(r);
}
阈值化通常会产生一个二进制掩模,即低于(局部自适应)阈值的像素和高于阈值的像素。如果您有该掩模,则可以保留原始图像的颜色信息。
因此,简单的方法将产生以下工作流程:
或者也许可以:
这两种方法可能不是理想的,但对于包括问题示例在内的大多数情况可能已经足够。