猿问

Photoshop如何将两个图像融合在一起?

有人可以解释一下Photoshop如何将两个图像融合在一起,以便在应用程序中重现相同的效果。



qq_笑_17
浏览 1236回答 3
3回答

BIG阳

通过在图像A中的每个像素上对图像B中的对应像素执行混合操作,Photoshop将两个图像混合在一起。每个像素是一种由多个通道组成的颜色。假设我们正在处理RGB像素,则每个像素中的通道将是红色,绿色和蓝色。要混合两个像素,我们混合它们各自的通道。可以在以下宏中总结在Photoshop中为每种混合模式发生的混合操作:#define ChannelBlend_Normal(A,B)&nbsp; &nbsp; &nbsp;((uint8)(A))#define ChannelBlend_Lighten(A,B)&nbsp; &nbsp; ((uint8)((B > A) ? B:A))#define ChannelBlend_Darken(A,B)&nbsp; &nbsp; &nbsp;((uint8)((B > A) ? A:B))#define ChannelBlend_Multiply(A,B)&nbsp; &nbsp;((uint8)((A * B) / 255))#define ChannelBlend_Average(A,B)&nbsp; &nbsp; ((uint8)((A + B) / 2))#define ChannelBlend_Add(A,B)&nbsp; &nbsp; &nbsp; &nbsp; ((uint8)(min(255, (A + B))))#define ChannelBlend_Subtract(A,B)&nbsp; &nbsp;((uint8)((A + B < 255) ? 0:(A + B - 255)))#define ChannelBlend_Difference(A,B) ((uint8)(abs(A - B)))#define ChannelBlend_Negation(A,B)&nbsp; &nbsp;((uint8)(255 - abs(255 - A - B)))#define ChannelBlend_Screen(A,B)&nbsp; &nbsp; &nbsp;((uint8)(255 - (((255 - A) * (255 - B)) >> 8)))#define ChannelBlend_Exclusion(A,B)&nbsp; ((uint8)(A + B - 2 * A * B / 255))#define ChannelBlend_Overlay(A,B)&nbsp; &nbsp; ((uint8)((B < 128) ? (2 * A * B / 255):(255 - 2 * (255 - A) * (255 - B) / 255)))#define ChannelBlend_SoftLight(A,B)&nbsp; ((uint8)((B < 128)?(2*((A>>1)+64))*((float)B/255):(255-(2*(255-((A>>1)+64))*(float)(255-B)/255))))#define ChannelBlend_HardLight(A,B)&nbsp; (ChannelBlend_Overlay(B,A))#define ChannelBlend_ColorDodge(A,B) ((uint8)((B == 255) ? B:min(255, ((A << 8 ) / (255 - B)))))#define ChannelBlend_ColorBurn(A,B)&nbsp; ((uint8)((B == 0) ? B:max(0, (255 - ((255 - A) << 8 ) / B))))#define ChannelBlend_LinearDodge(A,B)(ChannelBlend_Add(A,B))#define ChannelBlend_LinearBurn(A,B) (ChannelBlend_Subtract(A,B))#define ChannelBlend_LinearLight(A,B)((uint8)(B < 128)?ChannelBlend_LinearBurn(A,(2 * B)):ChannelBlend_LinearDodge(A,(2 * (B - 128))))#define ChannelBlend_VividLight(A,B) ((uint8)(B < 128)?ChannelBlend_ColorBurn(A,(2 * B)):ChannelBlend_ColorDodge(A,(2 * (B - 128))))#define ChannelBlend_PinLight(A,B)&nbsp; &nbsp;((uint8)(B < 128)?ChannelBlend_Darken(A,(2 * B)):ChannelBlend_Lighten(A,(2 * (B - 128))))#define ChannelBlend_HardMix(A,B)&nbsp; &nbsp; ((uint8)((ChannelBlend_VividLight(A,B) < 128) ? 0:255))#define ChannelBlend_Reflect(A,B)&nbsp; &nbsp; ((uint8)((B == 255) ? B:min(255, (A * A / (255 - B)))))#define ChannelBlend_Glow(A,B)&nbsp; &nbsp; &nbsp; &nbsp;(ChannelBlend_Reflect(B,A))#define ChannelBlend_Phoenix(A,B)&nbsp; &nbsp; ((uint8)(min(A,B) - max(A,B) + 255))#define ChannelBlend_Alpha(A,B,O)&nbsp; &nbsp; ((uint8)(O * A + (1 - O) * B))#define ChannelBlend_AlphaF(A,B,F,O) (ChannelBlend_Alpha(F(A,B),A,O))要混合单个RGB像素,请执行以下操作:ImageTColorR = ChannelBlend_Glow(ImageAColorR, ImageBColorR);&nbsp;ImageTColorB = ChannelBlend_Glow(ImageAColorB, ImageBColorB);ImageTColorG = ChannelBlend_Glow(ImageAColorG, ImageBColorG);ImageTColor = RGB(ImageTColorR, ImageTColorB, ImageTColorG);如果我们要执行具有特定不透明度的混合操作,请说50%:ImageTColorR = ChannelBlend_AlphaF(ImageAColorR, ImageBColorR, Blend_Subtract, 0.5F);如果您有指向图像A,B和T(我们的目标)的图像数据的指针,我们可以使用此宏简化所有三个通道的混合:#define ColorBlend_Buffer(T,A,B,M)&nbsp; &nbsp; &nbsp; (T)[0] = ChannelBlend_##M((A)[0], (B)[0]),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (T)[1] = ChannelBlend_##M((A)[1], (B)[1]),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (T)[2] = ChannelBlend_##M((A)[2], (B)[2])并可以派生以下RGB颜色混合宏:#define ColorBlend_Normal(T,A,B)&nbsp; &nbsp; &nbsp; &nbsp; (ColorBlend_Buffer(T,A,B,Normal))#define ColorBlend_Lighten(T,A,B)&nbsp; &nbsp; &nbsp; &nbsp;(ColorBlend_Buffer(T,A,B,Lighten))#define ColorBlend_Darken(T,A,B)&nbsp; &nbsp; &nbsp; &nbsp; (ColorBlend_Buffer(T,A,B,Darken))#define ColorBlend_Multiply(T,A,B)&nbsp; &nbsp; &nbsp; (ColorBlend_Buffer(T,A,B,Multiply))#define ColorBlend_Average(T,A,B)&nbsp; &nbsp; &nbsp; &nbsp;(ColorBlend_Buffer(T,A,B,Average))#define ColorBlend_Add(T,A,B)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(ColorBlend_Buffer(T,A,B,Add))#define ColorBlend_Subtract(T,A,B)&nbsp; &nbsp; &nbsp; (ColorBlend_Buffer(T,A,B,Subtract))#define ColorBlend_Difference(T,A,B)&nbsp; &nbsp; (ColorBlend_Buffer(T,A,B,Difference))#define ColorBlend_Negation(T,A,B)&nbsp; &nbsp; &nbsp; (ColorBlend_Buffer(T,A,B,Negation))#define ColorBlend_Screen(T,A,B)&nbsp; &nbsp; &nbsp; &nbsp; (ColorBlend_Buffer(T,A,B,Screen))#define ColorBlend_Exclusion(T,A,B)&nbsp; &nbsp; &nbsp;(ColorBlend_Buffer(T,A,B,Exclusion))#define ColorBlend_Overlay(T,A,B)&nbsp; &nbsp; &nbsp; &nbsp;(ColorBlend_Buffer(T,A,B,Overlay))#define ColorBlend_SoftLight(T,A,B)&nbsp; &nbsp; &nbsp;(ColorBlend_Buffer(T,A,B,SoftLight))#define ColorBlend_HardLight(T,A,B)&nbsp; &nbsp; &nbsp;(ColorBlend_Buffer(T,A,B,HardLight))#define ColorBlend_ColorDodge(T,A,B)&nbsp; &nbsp; (ColorBlend_Buffer(T,A,B,ColorDodge))#define ColorBlend_ColorBurn(T,A,B)&nbsp; &nbsp; &nbsp;(ColorBlend_Buffer(T,A,B,ColorBurn))#define ColorBlend_LinearDodge(T,A,B)&nbsp; &nbsp;(ColorBlend_Buffer(T,A,B,LinearDodge))#define ColorBlend_LinearBurn(T,A,B)&nbsp; &nbsp; (ColorBlend_Buffer(T,A,B,LinearBurn))#define ColorBlend_LinearLight(T,A,B)&nbsp; &nbsp;(ColorBlend_Buffer(T,A,B,LinearLight))#define ColorBlend_VividLight(T,A,B)&nbsp; &nbsp; (ColorBlend_Buffer(T,A,B,VividLight))#define ColorBlend_PinLight(T,A,B)&nbsp; &nbsp; &nbsp; (ColorBlend_Buffer(T,A,B,PinLight))#define ColorBlend_HardMix(T,A,B)&nbsp; &nbsp; &nbsp; &nbsp;(ColorBlend_Buffer(T,A,B,HardMix))#define ColorBlend_Reflect(T,A,B)&nbsp; &nbsp; &nbsp; &nbsp;(ColorBlend_Buffer(T,A,B,Reflect))#define ColorBlend_Glow(T,A,B)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (ColorBlend_Buffer(T,A,B,Glow))#define ColorBlend_Phoenix(T,A,B)&nbsp; &nbsp; &nbsp; &nbsp;(ColorBlend_Buffer(T,A,B,Phoenix))例子是:ColorBlend_Glow(TargetPtr, ImageAPtr, ImageBPtr);其余的Photoshop混合模式涉及将RGB转换为HLS,然后再次转换。#define ColorBlend_Hue(T,A,B)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ColorBlend_Hls(T,A,B,HueB,LuminationA,SaturationA)#define ColorBlend_Saturation(T,A,B)&nbsp; &nbsp; &nbsp;ColorBlend_Hls(T,A,B,HueA,LuminationA,SaturationB)#define ColorBlend_Color(T,A,B)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ColorBlend_Hls(T,A,B,HueB,LuminationA,SaturationB)#define ColorBlend_Luminosity(T,A,B)&nbsp; &nbsp; &nbsp;ColorBlend_Hls(T,A,B,HueA,LuminationB,SaturationA)#define ColorBlend_Hls(T,A,B,O1,O2,O3) {&nbsp; &nbsp; float64 HueA, LuminationA, SaturationA;&nbsp; &nbsp; float64 HueB, LuminationB, SaturationL;&nbsp; &nbsp; Color_RgbToHls((A)[2],(A)[1],(A)[0], &HueA, &LuminationA, &SaturationA);&nbsp; &nbsp; Color_RgbToHls((B)[2],(B)[1],(B)[0], &HueB, &LuminationB, &SaturationB);&nbsp; &nbsp; Color_HlsToRgb(O1,O2,O3,&(T)[2],&(T)[1],&(T)[0]);&nbsp; &nbsp; }这些功能将有助于将RGB转换为HLS。int32 Color_HueToRgb(float64 M1, float64 M2, float64 Hue, float64 *Channel){&nbsp; &nbsp; if (Hue < 0.0)&nbsp; &nbsp; &nbsp; &nbsp; Hue += 1.0;&nbsp; &nbsp; else if (Hue > 1.0)&nbsp; &nbsp; &nbsp; &nbsp; Hue -= 1.0;&nbsp; &nbsp; if ((6.0 * Hue) < 1.0)&nbsp; &nbsp; &nbsp; &nbsp; *Channel = (M1 + (M2 - M1) * Hue * 6.0);&nbsp; &nbsp; else if ((2.0 * Hue) < 1.0)&nbsp; &nbsp; &nbsp; &nbsp; *Channel = (M2);&nbsp; &nbsp; else if ((3.0 * Hue) < 2.0)&nbsp; &nbsp; &nbsp; &nbsp; *Channel = (M1 + (M2 - M1) * ((2.0F / 3.0F) - Hue) * 6.0);&nbsp; &nbsp; else&nbsp; &nbsp; &nbsp; &nbsp; *Channel = (M1);&nbsp; &nbsp; return TRUE;}int32 Color_RgbToHls(uint8 Red, uint8 Green, uint8 Blue, float64 *Hue, float64 *Lumination, float64 *Saturation){&nbsp; &nbsp; float64 Delta;&nbsp; &nbsp; float64 Max, Min;&nbsp; &nbsp; float64 Redf, Greenf, Bluef;&nbsp; &nbsp; Redf&nbsp; &nbsp; = ((float64)Red&nbsp; &nbsp;/ 255.0F);&nbsp; &nbsp; Greenf&nbsp; = ((float64)Green / 255.0F);&nbsp; &nbsp; Bluef&nbsp; &nbsp;= ((float64)Blue&nbsp; / 255.0F);&nbsp;&nbsp; &nbsp; Max&nbsp; &nbsp; &nbsp;= max(max(Redf, Greenf), Bluef);&nbsp; &nbsp; Min&nbsp; &nbsp; &nbsp;= min(min(Redf, Greenf), Bluef);&nbsp; &nbsp; *Hue&nbsp; &nbsp; &nbsp; &nbsp; = 0;&nbsp; &nbsp; *Lumination = (Max + Min) / 2.0F;&nbsp; &nbsp; *Saturation = 0;&nbsp; &nbsp; if (Max == Min)&nbsp; &nbsp; &nbsp; &nbsp; return TRUE;&nbsp; &nbsp; Delta = (Max - Min);&nbsp; &nbsp; if (*Lumination < 0.5)&nbsp; &nbsp; &nbsp; &nbsp; *Saturation = Delta / (Max + Min);&nbsp; &nbsp; else&nbsp; &nbsp; &nbsp; &nbsp; *Saturation = Delta / (2.0 - Max - Min);&nbsp; &nbsp; if (Redf == Max)&nbsp; &nbsp; &nbsp; &nbsp; *Hue = (Greenf - Bluef) / Delta;&nbsp; &nbsp; else if (Greenf == Max)&nbsp; &nbsp; &nbsp; &nbsp; *Hue = 2.0 + (Bluef - Redf) / Delta;&nbsp; &nbsp; else&nbsp; &nbsp; &nbsp; &nbsp; *Hue = 4.0 + (Redf - Greenf) / Delta;&nbsp; &nbsp; *Hue /= 6.0;&nbsp;&nbsp; &nbsp; if (*Hue < 0.0)&nbsp; &nbsp; &nbsp; &nbsp; *Hue += 1.0;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; return TRUE;}int32 Color_HlsToRgb(float64 Hue, float64 Lumination, float64 Saturation, uint8 *Red, uint8 *Green, uint8 *Blue){&nbsp; &nbsp; float64 M1, M2;&nbsp; &nbsp; float64 Redf, Greenf, Bluef;&nbsp; &nbsp; if (Saturation == 0)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; Redf&nbsp; &nbsp; = Lumination;&nbsp; &nbsp; &nbsp; &nbsp; Greenf&nbsp; = Lumination;&nbsp; &nbsp; &nbsp; &nbsp; Bluef&nbsp; &nbsp;= Lumination;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; else&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; if (Lumination <= 0.5)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; M2 = Lumination * (1.0 + Saturation);&nbsp; &nbsp; &nbsp; &nbsp; else&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; M2 = Lumination + Saturation - Lumination * Saturation;&nbsp; &nbsp; &nbsp; &nbsp; M1 = (2.0 * Lumination - M2);&nbsp; &nbsp; &nbsp; &nbsp; Color_HueToRgb(M1, M2, Hue + (1.0F / 3.0F), &Redf);&nbsp; &nbsp; &nbsp; &nbsp; Color_HueToRgb(M1, M2, Hue, &Greenf);&nbsp; &nbsp; &nbsp; &nbsp; Color_HueToRgb(M1, M2, Hue - (1.0F / 3.0F), &Bluef);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; *Red&nbsp; &nbsp; = (uint8)(Redf * 255);&nbsp; &nbsp; *Blue&nbsp; &nbsp;= (uint8)(Bluef * 255);&nbsp; &nbsp; *Green&nbsp; = (uint8)(Greenf * 255);&nbsp; &nbsp; return TRUE;}

撒科打诨

此答案中的“色相”,“颜色”,“饱和度”混合模式是错误的。没有Adobe产品转换为HSB,它们直接对RGB值执行操作。例如,这是用于设置亮度的GLSL:float lum(vec4 color){&nbsp; &nbsp; return ((0.3 * color.r) + (0.59 * color.g) + (0.11 * color.b));}vec4 clipColor(vec4 color){&nbsp; &nbsp; vec4 newColor=color;&nbsp; &nbsp; float l=lum(color);&nbsp; &nbsp; float n=min(min(color.r,color.g),color.b);&nbsp; &nbsp; float x=max(max(color.r,color.g),color.b);&nbsp; &nbsp; newColor.r=(n<0.0) ? l+(((color.r-l)*l)/(l-n)) : color.r;&nbsp; &nbsp; newColor.r=(x>1.0) ? l+(((color.r-l)*(1.0-l))/(x-l)) : color.r;&nbsp; &nbsp; newColor.g=(n<0.0) ? l+(((color.g-l)*l)/(l-n)) : color.g;&nbsp; &nbsp; newColor.g=(x>1.0) ? l+(((color.g-l)*(1.0-l))/(x-l)) : color.g;&nbsp; &nbsp; newColor.b=(n<0.0) ? l+(((color.b-l)*l)/(l-n)) : color.b;&nbsp; &nbsp; newColor.b=(x>1.0) ? l+(((color.b-l)*(1.0-l))/(x-l)) : color.b;&nbsp; &nbsp; return clamp(newColor,0.0,1.0);}vec4 setlum(vec4 color, float l){&nbsp; &nbsp; float d=l-lum(color);&nbsp; &nbsp; color.r+=d;&nbsp; &nbsp; color.g+=d;&nbsp; &nbsp; color.b+=d;&nbsp; &nbsp; return clipColor(color);&nbsp; &nbsp;&nbsp;}kernel vec4 blendLuminosity(sampler topimage, sampler bottomimage){&nbsp; &nbsp; vec4 base=sample(bottomimage, samplerCoord(bottomimage));&nbsp; &nbsp; vec4 blend=sample(topimage, samplerCoord(topimage));&nbsp; &nbsp; float bl=lum(blend);&nbsp; &nbsp; return setlum(base,bl);}CIKernels中不支持if .. else语句,因此使用三元运算符。
随时随地看视频慕课网APP
我要回答