Mapping lightness to hue with a filter?

Post questions on how to use or achieve an effect in Inkscape.
hollandlef
Posts: 19
Joined: Fri Mar 20, 2015 5:26 pm

Mapping lightness to hue with a filter?

Postby hollandlef » Mon Mar 30, 2015 8:23 pm

Hi,

I'm currently trying to create a complex colour gradient out of a number of primitive grayscale gradients whose values are mathematically significant. I probably ought to be learning a plotting program like GNUPlot or R for this, but I was really hoping that I could get away with doing it in SVG, partly because the result is ultimately going to be used in an Inkscape drawing, and partly because those programs frighten me :? I've got as far as creating a combined grayscale gradient that represents what I want it to by using a bunch of filter operations on a few overlapping underlying gradients. What's stumping me slightly is that I'd now like to map the relatively narrow grayscale gradient I've ended up with to a range of hue values at maximum saturation and mid-lightness. In HSL terms, effectively I want to map the lightness of the grayscale to a hue value. Since I want to do this non-destructively based on the underlying primitives, I've been looking at filters to achieve this, but I'm a bit stumped by the fact that they all work in RGBA. I guess the crude way to do it would be a table-based component transfer, but that's pretty fragile. Does anyone with more of a head for maths/filters have any clever ideas?


Many thanks,

Lucian
Last edited by hollandlef on Tue Mar 31, 2015 12:59 am, edited 1 time in total.

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: Mapping lightness to hue with a filter?

Postby Lazur » Mon Mar 30, 2015 8:35 pm

Hi.

As far as I know, inkscape/svg works in the rgba space, even though you can "hack" use pre-installed icc profiles (?).
Filters are raster based. If you want to save the image as a pdf later on, you will have some limitation on them.
Because of that, I wouldn't even suggest to use masking, it doesn't work either.

So something that might work, is to edit the greyscale gradient to black to black&transparent, white to white&transparent parts.
Though this would work best if the midtone below was really mid-tone, with lightness value at 127,5.; some small compromise is necessary.

hollandlef
Posts: 19
Joined: Fri Mar 20, 2015 5:26 pm

Re: Mapping lightness to hue with a filter?

Postby hollandlef » Wed Apr 01, 2015 1:36 am

I'm not 100% sure I get what you are suggesting. My "grayscale gradient" was in fact already created by overlaying multiple gradients that faded from alpha 1 -> alpha 0. But the final step represents the addition of two overlapping sources of radiation, and I want this to be a "pure addition" operation (modelled using addition Composite filter- K2 &K3 both set to 1). This part I haven't had difficulty with. It was the translation to a range of colours that I was stuck on - because obviously the relationship between hue value and RGB values is a complex one that cannot (AFAICT) be modelled as an equation simple enough to be expressed in inkscape filters. In the end I got an approximation using a Table-based ComponentTransfer with hand-tuned values. It looked terrible because of the multiple-levels of raster processing, but it gave me something on which to base a hand-drawn replacement using a bunch of filled concentric paths that I then blurred together to look like a color gradient. The nerd in me would have liked to have had the final version working direct from the underlying data; but on the plus side it's now a great deal faster!

FWIW I have no need to export to any other vector formats - it's a map that will ultimately be rendered either to screen, bitmap or print.

Thanks for the suggestion anyway.

Lucian

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: Mapping lightness to hue with a filter?

Postby Lazur » Wed Apr 01, 2015 3:52 am

I was thinking of something similar to this.

hollandlef
Posts: 19
Joined: Fri Mar 20, 2015 5:26 pm

Re: Mapping lightness to hue with a filter?

Postby hollandlef » Wed Apr 01, 2015 4:48 am

Hey, thanks for replying again - I fear that I'm not really explaining myself very well. The final output was supposed to be something like your bottom gradient - full saturation all the way across - but I wanted to *generate* this by transforming an underlying grayscale or alpha gradient that describes where and how quickly the transitions between the colours should occur. This was the manual output I produced in the end:

Screen Shot 2015-03-31 at 19.26.34.png
Screen Shot 2015-03-31 at 19.26.34.png (136.88 KiB) Viewed 2191 times


Those colours represent climate bands. The cosmology of the world being mapped is a bit odd - a disc with two small, closely orbiting suns which pass over the east and west ends. I produced a spreadsheet that listed out the levels of insolation at given distances from each solar path based on the sizes of the suns, the angle to the surface, atmospheric absorption etc.

I then produced two sets of gradients that represented distance from either solar path, and applied a Table ComponentTransfer filter to map this distance to the insolation values from my spreadsheet. Finally, I positioned the gradients based on the solar paths, which resulted in an overlap; I applied an Arithmetic Composite filter to the upper gradient to perform a straight addition of the values in the gradients. This produced a final grayscale gradient where the luminance value at any given point represented the total level of solar insolation there. What I was then hoping to do was to translate that into a set of colours ranging from blue (lowest value) to red (highest value) to produce an image that looked a bit like the one above. The only way I could find to do that was to use another Table ComponentTransfer and try and model the relationship between hue and RGB manually that way. I got a result that had roughly the right colours, but it was really pixelated because of all the raster transformations, so I just traced over it manually to produce the image above. A lot easier!

Cheers,

Lucian

hollandlef
Posts: 19
Joined: Fri Mar 20, 2015 5:26 pm

Re: Mapping lightness to hue with a filter?

Postby hollandlef » Wed Apr 01, 2015 11:40 pm

Lazur URH wrote:I was thinking of something similar to this.


By the way, I forgot to ask, what did you use to create that colour wheel gradient? I looked through the extensions but couldn't find anything that obviously would do that - or did you generate the SVG outside of inkscape?

Thanks,

Lucian

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: Mapping lightness to hue with a filter?

Postby Lazur » Thu Apr 02, 2015 12:21 am

That gradient was made with inkscape manually -each step was snapped to guidelines at even distances.

Now that I see what you wanted to achieve, a "gradient map" effect can do similar with rasters.
Available in gimp as a plugin only (?) http://docs.gimp.org/en/plug-in-gradmap.html, while in photoshop it seems a built in feature.

Nice image by the way!

User avatar
Xav
Posts: 1209
Joined: Fri May 08, 2009 1:18 am
Location: UK
Contact:

Re: Mapping lightness to hue with a filter?

Postby Xav » Thu Apr 02, 2015 2:04 am

Lazur URH wrote:Available in gimp as a plugin only (?) http://docs.gimp.org/en/plug-in-gradmap.html


Built in to my Gimp 2.8 - Colours > Map > Gradient Map (make sure to select your target gradient first from the Gradients dialog (CTRL-G)). It used to be in the filters menu in older releases, I'm not sure when it moved.
Co-creator of The Greys and Monsters, Inked - Inkscape drawn webcomics
Web SiteFacebookTwitter

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: Mapping lightness to hue with a filter?

Postby Lazur » Thu Apr 02, 2015 2:31 am

Thank's for the correction!

hollandlef
Posts: 19
Joined: Fri Mar 20, 2015 5:26 pm

Re: Mapping lightness to hue with a filter?

Postby hollandlef » Thu Apr 02, 2015 8:40 am

Lazur URH wrote:That gradient was made with inkscape manually -each step was snapped to guidelines at even distances.

Wow. That must have taken a while!

Lazur URH wrote:Now that I see what you wanted to achieve, a "gradient map" effect can do similar with rasters.
Available in gimp as a plugin only (?) http://docs.gimp.org/en/plug-in-gradmap.html, while in photoshop it seems a built in feature.


Yes - that's *exactly* what I was looking for. I'm beginning to see why most people do this sort of work in GIMP/Photoshop rather than Inkscape. On the other hand I much prefer working with geometry and mathematical operations than pixels and brushes - I'm much more of a geek than I am an artist I guess!

Lazur URH wrote:Nice image by the way!


Thanks! It's very crude by comparison to some of the dauntingly beautiful work I've seen on Cartographer's Guild but I guess we all have to start somewhere! Now I just have to fill it all in with some actual geography... spent most of yesterday working out how to build mountains out of lighting filters; and most of today working out and writing up the Inkscape bugs I found yesterday ;) Hopefully at some point I'll have something I don't feel too embarrassed to share on one of the forums here....


Return to “Help with using Inkscape”