更好的图像着色逻辑/算法 [英] Better image coloring logic/algorithm

查看:222
本文介绍了更好的图像着色逻辑/算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iOS应用程序,用户可以通过触摸它来更改图像颜色的一部分,例如茶杯。我使用Floodfill算法来填充颜色,以便用户必须点击茶杯更改其颜色。这工作正常。但是,最终的颜色看起来与替换颜色略有不同。我有一些问题找到一个更好的逻辑,将对象的(茶杯)颜色转换为所选择的颜色,考虑到它的饱和度&亮度。



我使用以下逻辑来获得结果颜色。我代表颜色为 (色调,饱和度,值)

  touchedColor =(tchd_h,tchd_s,tchd_v); //我现在不使用这个

pixelColor =(old_h,old_s,old_v);
replacementColor =(new_h,new_s,new_v);
resultColor =(new_h,new_s,old_v);
pixelColor = resultColor;

在绘画前的杯子(以红色圈起来)。 >

>



所选的replacementColor。





在涂刷replacementColor(以红色圈出)后进行杯。 >

>



查看上面的最终图片。因为我只是改变 hue&饱和 ,而不是 pixelColor 看起来与所选 replacementColor 类似。图像的亮度保持不变。



如果我改变 以及饱和

  resultColor =(new_h,new_s,new_v); 
pixelColor = resultColor;

然后杯子变得平整,缺少灯光,这样的阴影,



/ p>

我想要一些想法来调整上述逻辑,将像素颜色更改为匹配的替换颜色。可以是一些公式来导出 饱和度&

在您的示例中,我们将粉红色的颜色称为要替换的颜色 ,我们称之为棕色的替换颜色。对于目标中的每个像素,查找源中的相应像素。看看它是如何变化从颜色替换。现在对替换颜色进行类似的调整,并将其用作当前输出像素的颜色。



例如,如果当前源像素比颜色替换为5v单位,然后将输出像素设置为以5v为单位变暗的替换颜色。 (您也想对色调和饱和度进行相同的调整。)



您可能需要限制调整的颜色范围,不会使其他对象变成不同的颜色。


I am developing an iOS app in which the user can change a part of an image's color, say a Tea Cup, by touching it. I am using Floodfill algorithm to fill colors so that the user has to tap on the Tea Cup to change its color. That's working fine. But, the final color looks little different than the replacement color. I have some problem finding out a better logic to convert the object's(Tea Cup) color to the selected color considering its saturation & lightness.

I am using the following logic to get the result color. I am representing color as (hue, saturation, value).

touchedColor = (tchd_h, tchd_s, tchd_v); // I am not using this now 

pixelColor = (old_h, old_s, old_v); 
replacementColor = (new_h, new_s, new_v);
resultColor = (new_h, new_s, old_v);
pixelColor = resultColor;

The cup before painting (circled with red color).

The selected replacementColor.

Cup after painting the replacementColor (circled with red color).

See the final image above. As I am just changing only the hue & saturation, and not the value of the pixelColor, the applied color doesn't look similar to the selected replacementColor. The lightness of the image remains unaltered.

If I change the value along with hue & saturation like this,

resultColor = (new_h, new_s, new_v);
pixelColor = resultColor;

Then the cup becomes flat colored, missing the lights & shades like this,

I want some idea to tweak the above logic to change the pixel color into a matching replacement color. May be some formula to derive the saturation & value.

解决方案

In your example, let's call the pink color the "Color To Replace," and let's call the brown color the "Replacement Color." For each pixel in the destination, find the corresponding pixel in the source. See how it varies from the "Color to Replace". Now make similar adjustments to the "Replacement Color" and use that as the color at the current output pixel.

As an example, if the current source pixel is darker than the color to replace by 5 "v" units, then set the output pixel to the replacement color made darker by 5 "v" units. (And you'd want to make the same adjustments in hue and saturation, as well.)

You'll probably need to limit the range of colors you adjust so you aren't turning other objects a different color.

这篇关于更好的图像着色逻辑/算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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