In image editing tools such as GIMP and Photoshop, image layers can be combined or blended using different pixel blending modes. While modes such as the contrast enhancing modes don't suggest their operating methods so directly, certainly the component and arithmetic modes do. Addition and division modes suggest the underlying math. Hue and saturation suggest the channels to be transferred between foreground and background. The detail-oriented observer might begin to raise questions at this point. Hue? Saturation? In what model are we working?
What about the 'color' mode? Mere observation suggests that it's a combination of hue and saturation information being transferred, but again, the details are critically important. Various sources online suggest that this mode performs a HS transfer in HSV... or HSB... or HSL... or HSY? One begins to wonder if anybody knows what they're talking about.
As my experience lies with GIMP, I based my expectations on its behavior. Certainly, I can't test my blending algo against software I don't have; however, it might be worth keeping in mind that other suites may use different approaches. The passing impression of online resources suggests that GIMP uses HSV or HSL, Photoshop uses CIELAB, and according to simplefilter.de, PaintShopPro uses some bastard HSL/HSY swap that has people so baffled that they ask questions of forums only to get more nonsensical guidance. Let's sort this out as best we can by simple experiment.
I assume at this point a few things about what is desired. Forgive my loose language hereon, but in this pixel blending mode, what should be transferred is the chroma information independent of the luminosity-related information. In other words, the hue and colorfulness should change, but not the perceived brightness. White should remain white, black should remain black. Acronyms make it sound like a simple task, don't they?
Let's start with HSV, HSL, and HSI. These are polar models used to express the content of the sRGB color space. The convenience of these familiar models is simply the manner in which their polar format allows intuitive selection and adjustment of colors.
HSV is commonly visualized as a hexagonal cone or prism defined by piecewise math. HSI is expressed as a cylinder or cone defined by simple trigonometry. HSL is often described as a hexagonal bicone. What's with all the different geometry? All we want to do is separate HS from L/V/I, right? Feel free to look at the math, but I think it's more valuable to the novice (me) to see how the isosurfaces associated with these models are projected into the sRGB space.
Isosurfaces of Value and Intensity as projected into the RGB cube |
Value, the V in HSV, is defined as the the maximum of the RGB channels. This means that the isosurfaces of V are cube shells in RGB. Intensity (I in HSI) is the simple average of the channels. This translates to planar isosurfaces. At this point, it might start to look like HSI would provide more meaningful separation of color information from brightness information. Does it make sense that [1 1 1] and [1 0 0] have the same brightness metric as they do in HSV? Let's try to do an HS swap in these models and see what happens.
Foreground image |
Background Image |
Color blend in HSV |
Color blend in HSI |
Color blend in HSL |
Saturation isosurfaces as projected into the RGB cube from HSV, HSI, HSL |
Color blend in CIELCHab |
The trajectory of an out-of-gamut point in unconstrained LCHab and HuSLab |
If the goal remains to isolate the effects of color manipulation and image brightness, the geometry of this projection poses an issue. To transfer the radial position of a primary or secondary corner to a pixel which is near the extent of the L axis would be to push the pixel outside the cube. If we were to rotate the hue of a pixel which lies on a primary or secondary corner, it would again move outside the cube. How can we manage the existence and graceful conversion of these points? To be honest, I'm not sure I know the best methods. All I can offer are my current approaches.
One approach would be to do data truncation prior to RGB conversion. Of course, the maximum chroma for a given L and H is not simple to calculate, but this would keep the trajectories of out-of-gamut points in a plane of constant L. This produces good results, but reveals an issue with working methods.
Color blend in CIELCHab |
This is more of a problem for image and color adjustment than for a single channel swapping blend operation, but it's something to keep in mind. I'll probably come back to the topic of normalized versions of LCH at a later date.
If implementing a constrained color model like this is beyond the realm of practical effort-costs, consider this simple dirty method to retain brightness in a color blend. Simply copy the background luma, perform a HS channel swap in HSL, then re-establish the original luma using your favorite luma-chroma transformation. This might seem like it would waste a lot of time with converting twice, but it's often the fastest method among those I've described. The results are similar to the normalized methods, and existing conversion tools can typically be used.
Color blend in HSL with Y preservation |
No comments:
Post a Comment