有人知道在Photoshop中调整图层是如何工作的吗?我需要生成一张结果图像,其中包括源图像和色相/饱和度调整图层中的HSL值。将其转换为RGB,然后与源颜色相乘并不起作用。
或者是否可以将色相/饱和度调整图层替换为普通图层,并适当设置混合模式(Multiply、Screen、Hue、Saturation、Color、Luminocity等)? 如果可以,那么如何操作?
谢谢!
有人知道在Photoshop中调整图层是如何工作的吗?我需要生成一张结果图像,其中包括源图像和色相/饱和度调整图层中的HSL值。将其转换为RGB,然后与源颜色相乘并不起作用。
或者是否可以将色相/饱和度调整图层替换为普通图层,并适当设置混合模式(Multiply、Screen、Hue、Saturation、Color、Luminocity等)? 如果可以,那么如何操作?
谢谢!
我已经反向工程计算出“启用“着色”复选框”的过程。以下所有代码均为伪代码。
输入参数如下:
HSV(photoshop_hue, 100, 100).ToRGB()
photoshop_saturation / 100.0
(范围为0~1)photoshop_lightness / 100.0
(范围为-1~1)pixel.ToHSV().Value
,缩放到0~1的范围内。单个像素进行着色的方法:
color = blend2(rgb(128, 128, 128), hueRGB, saturation);
if (lightness <= -1)
return black;
else if (lightness >= 1)
return white;
else if (lightness >= 0)
return blend3(black, color, white, 2 * (1 - lightness) * (value - 1) + 1)
else
return blend3(black, color, white, 2 * (1 + lightness) * (value) - 1)
其中blend2
和blend3
是:
blend2(left, right, pos):
return rgb(left.R * (1-pos) + right.R * pos, same for green, same for blue)
blend3(left, main, right, pos):
if (pos < 0)
return blend2(left, main, pos + 1)
else if (pos > 0)
return blend2(main, right, pos)
else
return main
if(b<1) c = b * c;
else c = c + (b-1) * (1-c);
一些测试:
b = 0 >>> c = 0 // black
b = 1 >>> c = c // same color
b = 2 >>> c = 1 // white
(r+g+b) * 0.333
colorRGB是您的目标颜色
finalRGB是结果
伪代码:
finalRGB = inputRGB * (colorRGB + inputRGB * 0.5);
我认为它快速而高效
@Roman Starkov的解决方案Java实现:
//newHue, which is photoshop_hue (i.e. 0..360)
//newSaturation, which is photoshop_saturation / 100.0 (i.e. 0..1)
//newLightness, which is photoshop_lightness / 100.0 (i.e. -1..1)
//returns rgb int array of new color
private static int[] colorizeSinglePixel(int originlPixel,int newHue,float newSaturation,float newLightness)
{
float[] originalPixelHSV = new float[3];
Color.colorToHSV(originlPixel,originalPixelHSV);
float originalPixelLightness = originalPixelHSV[2];
float[] hueRGB_HSV = {newHue,100.0f,100.0f};
int[] hueRGB = {Color.red(Color.HSVToColor(hueRGB_HSV)),Color.green(Color.HSVToColor(hueRGB_HSV)),Color.blue(Color.HSVToColor(hueRGB_HSV))};
int color[] = blend2(new int[]{128,128,128},hueRGB,newSaturation);
int blackColor[] = new int[]{Color.red(Color.BLACK),Color.green(Color.BLACK),Color.blue(Color.BLACK)};
int whileColor[] = new int[]{Color.red(Color.WHITE),Color.green(Color.WHITE),Color.blue(Color.WHITE)};
if(newLightness <= -1)
{
return blackColor;
}
else if(newLightness >=1)
{
return whileColor;
}
else if(newLightness >=0)
{
return blend3(blackColor,color,whileColor, (int) (2*(1-newLightness)*(originalPixelLightness-1) + 1));
}
else
{
return blend3(blackColor,color,whileColor, (int) ((1+newLightness)*(originalPixelLightness) - 1));
}
}
private static int[] blend2(int[] left,int[] right,float pos)
{
return new int[]{(int) (left[0]*(1-pos)+right[0]*pos),(int) (left[1]*(1-pos)+right[1]*pos),(int) (left[2]*(1-pos)+right[2]*pos)};
}
private static int[] blend3(int[] left,int[] main,int[] right,int pos)
{
if(pos < 0)
{
return blend2(left,main,pos+1);
}
else if(pos > 0)
{
return blend2(main,right,pos);
}
else
{
return main;
}
}
当“着色”复选框被选中时,底层图层的亮度与色相和饱和度滑块的值相结合,并根据https://en.wikipedia.org/wiki/HSL_and_HSV#From_HSL中的方程式从HSL转换为RGB。(亮度滑块只是将亮度重新映射到比例尺的子集上,从直方图可以看出效果非常糟糕,我不明白为什么会有人使用它。)
rgb(128, 128, 128)
是什么?是原始单个像素的 RGB 颜色吗? - zwcloud#808080
。 - Roman Starkov