Welcome to RetouchPRO, the web community for retouchers.
You are currently viewing as an unregistered guest which gives you limited access. Registration is fast, simple and absolutely free so please, join RetouchPRO today!
If you have any problems with the registration process or your account login, please contact us. If you've forgotten your password, click here.
| | Software Photoshop, Paintshop Pro, Painter, etc., and all their various plugins. Of course, you can also discuss all other programs, as well. | 
02-10-2006, 08:40 AM
|  | Senior Member | | Join Date: Jan 2005
Posts: 309
| | (byRo: This thread has been split - so some posts may seem out of context)
I'm sure most of us are familiar with the various colour spaces. The ones that come to mind are RGB, HSL, HSB, Lab, and CMYK. Oy, but Photoshop uses a priority space when you are not looking. This space is very similiar to HSL and HSB with a hint of xyz/Lab tossed in.
I used to call this colour space HS/Lum, but have taken to calling it HsY. I got the name, HsY, from a guy in Germany (I think Germany). I just like his name better.
Whenever you use the blending modes Hue, Saturation, Colour, or Luminosity, you are using this hidden space.
Here is a simple experiment to try:
- open photograph in RGB mode, preferably with lots of blue and yellow
- Adjustment Layer > Hue/Sat
-- bring Sat all the way down to -100
When you do this, you are looking at Lightness of HSL.
Now change the blending mode of the H/S Ad-Layer to Hue, Colour, or Sat. Different, eh? This is because you are now using HsY and seeing Y or Luminosity.
Here is the basic code for turning RGB into HsY: Code: %ffp
ForEveryPixel:{
int hue,sat,lum;
hue=rgb2hsl(r,g,b,0);
sat=max(r, max(g,b) ) - min(r, min(g,b) );
lum= r*0.30 + g*0.59 + b*0.11;
R=hue;
G=sat;
B=lum;
} After running this, use the Channels palette to inspect the channels separately. One thing I want you to note is that the resulting Lum 'channel' will usually have higher fidelity than the Hue and Sat 'channels'.
You see, the two colour channels are usually compressed more than the luminosity channel. This is why there are tutorials out there about smoothifying when you increase saturation (Deke). If you amplify a compressed channel, then you will bring out the compressedness of the channel.
This one little thing can mean an awlful lot.
Last edited by byRo : 05-06-2006 at 12:22 PM.
Reason: byRo: Thread split
| 
02-10-2006, 11:01 AM
|  | Senior Member | | Join Date: Feb 2005 Location: Lancashire (UK)
Posts: 1,112
| | | Thank you Stroker.
It’s amazing what you can achieve with a few simple lines of code.
I am still learning. And find C+ syntax quite confusing at times. I learnt VB instead.
I usually look through the FilterMeister code library for a similar type filter and then amend it.
It’s Interesting the way you split HsY onto the channels. That was a good idea as I don’t think FilterMeister will let you create new layers.
Now if I could only put this back together again.
Ken | 
02-10-2006, 07:20 PM
|  | Senior Member | | Join Date: Feb 2005 Location: Lancashire (UK)
Posts: 1,112
| | | Tips
If you wish to try Stroker’s code you will find that you can’t use the mouse to paste code straight into FilterMeister.
It is possible to paste with the keyboard.
• Ctrl+C - Copy (OR You Can use the mouse)
• Ctrl+V - Paste (place the cursor where you want to paste first)
Or, of course, the code can be saved as a *.ffp file using notepad.
Ken | 
02-11-2006, 03:41 AM
|  | Senior Member | | Join Date: Jan 2005
Posts: 309
| | What Ken said about copy, cut, and paste.
In my previous example, used rgb2hsl function to get a value of hue in the range of 0 to 255. You know, 1 dimensional greyscale or something. But what about full colour hue?
One way of doing this is by using rgb2hsl and hsl2rgb. Check it out: Code: %ffp
ForEveryPixel:{
int hue;
hue = rgb2hsl(r,g,b,0);
R=hsl2rgb(hue,255,128,0);
G=hsl2rgb(hue,255,128,1);
B=hsl2rgb(hue,255,128,2);
} First we get the hue in the range of 0 to 255. Now, in order to get hue in full colour, we have to use sat=255 and lightness=128 in the hsl2rgb function. Why? Because in the HSL double-cone that is where the full range of RGB lies. That is, smack dab in the center with full saturation.
As fun as that is, there is another way that uses the scale function (scl). Find the min, find the max, then scale everything to full 0 to 255 range. Code: %ffp
ForEveryPixel:{
int min,max;
min = min(r, min(g,b) );
max = max(r, max(g,b) );
R=scl(r,min,max,0,255);
G=scl(g,min,max,0,255);
B=scl(b,min,max,0,255);
} I prefer the latter. Later I'll tell you why. | 
02-11-2006, 06:36 AM
|  | Senior Member | | Join Date: Jan 2005
Posts: 309
| | Easy Sat: Code: sat=max(r, max(g,b) ) - min(r, min(g,b) ); Pieces of easy sat: Code: min = min(r, min(g,b) );
max = max(r, max(g,b) ); Scale for full colour hue: Code: R=scl(r,min,max,0,255);
G=scl(g,min,max,0,255);
B=scl(b,min,max,0,255); Now we are going to take all of those pieces and put them together. Code: %ffp
ForEveryPixel:{
int min,max,sat;
min = min(r, min(g,b) );
max = max(r, max(g,b) );
sat = max - min;
R=scl(r,min,max,0,sat);
G=scl(g,min,max,0,sat);
B=scl(b,min,max,0,sat);
} Notice that the scl functions use the different pieces of the saturation code. That is, we are using mix, max, and sat to scale the RGB values.
What did we do? Rather than scale RGB to full colour hue, we scaled RGB to saturation while retaining hue. That is, the final output will have the hue and sat information of the original input image. All we did is rearrange the hue and sat a little bit.
- copy photograph
- run that code
- change blending mode to Hue, Sat, or Colour
See any difference? You shouldn't because we are using HsY.
Let's try it again but with simple subtraction: Code: %ffp
ForEveryPixel:{
int min;
min = min(r, min(g,b) );
R=r-min;
G=g-min;
B=b-min;
}
Now let's try addition using max: Code: %ffp
ForEveryPixel:{
int max;
max = max(r, max(g,b) );
R = r + ( 255 - max );
G = g + ( 255 - max );
B = b + ( 255 - max );
} The output should look way different, but it will still have the same hue and sat information present in the original. Try Hue, Sat, and/or Colour on the output.
What's the point of all of this? I'm not sure. I think it has something to do with different ways of getting the same data and moving it around different ways to get the same things. I guess your plan of attack will depend on what you are trying to achieve. Sound good? Probably not because I am going rather fast.
At the very least, you should have an idea about hue in RGB and sat. Maybe.
edit:
Okay, I'm gonna see if I can re-focus for where I want to go.
Last edited by Stroker : 02-11-2006 at 07:21 AM.
| 
02-11-2006, 08:13 PM
|  | Senior Member | | Join Date: Feb 2005 Location: Lancashire (UK)
Posts: 1,112
| | Stroker. Thank You.
This is great. Not only are you teaching us FilterMeister but you are teaching us about color spaces as well. Wonderful stuff.
And they thought this was just for geeks. They don’t know what they are missing.
Keep it coming.
FilterMeister can do allsorts of other great things. Here is an example of a bit of code for making borders, Quote:
%ffp
ctl[0]: "Border thickness"
ctl[2]: "Red coloring"
ctl[3]: "Green coloring"
ctl[4]: "Blue coloring
R: ( x < ctl(0) || x > X-ctl(0)-1 || y < ctl(0) || y > Y-ctl(0)-1) ? ctl(2) : r
G: ( x < ctl(0) || x > X-ctl(0)-1 || y < ctl(0) || y > Y-ctl(0)-1) ? ctl(3) : g
B: ( x < ctl(0) || x > X-ctl(0)-1 || y < ctl(0) || y > Y-ctl(0)-1) ? ctl(4) : b
A:a
| Ken | 
02-12-2006, 04:19 PM
|  | Senior Member | | Join Date: Jan 2005
Posts: 309
| | I'm just too ADD sometimes. Pretty sad when I've got to put myself on a leash. Okay, re-focus in effect. Gonna be headin' in Ken's direction. Quote: |
Now if I could only put this back together again.
| That is where we are headed. If I start to stray too much, give me the beat-down.
New code to work with: Code: %ffp
SupportedModes: RGBMode
ForEveryTile:{
int x,y,r,g,b;
int min,max;
int hue,sat,lum;
for (y=y_start; y<y_end; y++){
//if(updateProgress(y,y_end)) abort();
for (x=x_start; x<x_end; x++){
r=src(x,y,0);
g=src(x,y,1);
b=src(x,y,2);
hue=rgb2hsl(r,g,b,0);
min=min(r,min(g,b));
max=max(r,max(g,b));
sat=max-min;
lum=(max+min)/2;
pset(x,y,0,hue);
pset(x,y,1,sat);
pset(x,y,2,lum);
} // end x preview
} // end y preview
return true;
} // end for every tile There are quite a few differences in there. The biggest thing I want you to note is this chunk: Code: ForEveryTile:{
int x,y,r,g,b;
int min,max;
int hue,sat,lum; Notice that the structure is ForEveryTile (FET) instead of ForEveryPixel (FEP). While this isn't quite as easy as FEP, it is way more efficient. For images, it is usually better to work with chunks at a time, and those chunks are commonly called tiles. Usually you won't see a speed difference until you start working with way huge images, but let's get started using FET right now.
Using also FET means
- have to make a few extra declarations
- you have to cycle through the image one pixel at a time using for loops and src()
In the code, I have updateProgress commented out. I rarely use this, but I keep it in there just in case I feel the need.
Also made use of SupportedModes. While this won't affect testing within FM, it will make a difference when it comes time to make a stand-alone. RGBMode = RGB using 8-bit per channel.
Another difference, probably more major than minor, is this: Even though the variable is lum, this is actually the formula for Lightness in HSL. Going to be using this for edification reasons. Once we get past a certain hump or two, we'll change this back to Luminosity that Photoshop uses. By going this route, hopefully save ya'll a lot of frustration.
What exactly are we doing right now? We are mixing-n-matching for our own colour space. Basically taking the easy parts from HSL and HsY. | 
02-12-2006, 07:04 PM
|  | Senior Member | | Join Date: Feb 2005 Location: Lancashire (UK)
Posts: 1,112
| | Hee Hee
Don’t try this at home folks Quote:
%ffp
SupportedModes: ADD ADHD
ctl[0]: "Attention Deficit Disorder"
ctl[1]: "Attention Deficit Hyperactivity Disorder"
/*R,G,B:
| Stroker
I can’t get you last post code to work. It does not even want to compile. (But it does change the picture) I Can’t understand this. Should it work on a RGB picture or is it designed to work with HsY in the channels?
How on Earth did you find that you needed a gradient to put saturation back?
Ken | 
02-13-2006, 07:16 AM
|  | Senior Member | | Join Date: Jan 2005
Posts: 309
| | If it's not compiling, it should give you an error. What is the error?
The last code that I posted is for RGB mode with 8-bits per channel. What it does is take the RGB values and convert them over to our own blend of HSL/HsY. It's pretty much the same as the first code I posted in this thread. Quote: |
How on Earth did you find that you needed a gradient to put saturation back?
| It's just a matter of knowing what you've got, what you want, and the tools available. If you really understand saturation as Photoshop uses it, you should be able to put the saturation back in using Curves, Levels, or Channel Mixer. You can even do it right in the Channels palette if you really want to. I chose Gradient Map because I thought it would make more sense to other people. | 
02-13-2006, 03:36 PM
|  | Senior Member | | Join Date: Feb 2005 Location: Lancashire (UK)
Posts: 1,112
| | | Stroker.
Thanks. Everything is working fine. Your code is putting HSL into the channels.
It seems like using the code more than once is the problem. The second time it is run on the same picture it seems to run without the need to compile it.
Open Picture
Open FilterMeister
Paste your code
Press Compile
Press OK
At this point everything is OK and HSL are in the channels
Now
Open FilterMeister again
Now the picture changes without pressing compile
I think I’ve seen this happen before.
Anyway the main thing is that it is working with FET.
Ken | 
02-13-2006, 04:10 PM
|  | Senior Member | | Join Date: Jan 2005
Posts: 309
| | Quote: |
Now the picture changes without pressing compile
| This is because the last compile is cached.
Glad it's working. I'll get to work on the next bit. Actually make a graphic or two. Egads. | 
02-14-2006, 12:08 AM
|  | Senior Member | | Join Date: Jan 2005
Posts: 309
| | In previous examples, we saw that we could take hue and sat and move them around. In one example, 0 was used as the reference or starting point of sorts. In another example, 255 was used as the reference. You have to pick where to start and then go from there.
In our custom space, the reference or starting point is going to be lum ( lum is the name of the variable, but Lightness by definition). Then it's just a matter of scaling. Scale what? Scale hue in full colour, of course.
Plan of attack
- get hue, sat, and lum
- get hue in full RGB colour using temporary values
- scale it using saturation to set the range and lum as the starting point
See attachment for a graphic.
While we are at it, lets add some controls to manipulate hue, sat, and lum.
New code: Code: %ffp
SupportedModes: RGBMode
ctl(0):standard,"Hue",range=(-128,128),val=0,track
ctl(1):standard,"Sat",range=(-255,255),val=0,track
ctl(2):standard,"Lum",range=(-255,255),val=0,track
ForEveryTile:{
int x,y,r,g,b;
int min,max;
int hue,sat,lum;
int rt,gt,bt;
for (y=y_start; y<y_end; y++){
//if(updateProgress(y,y_end)) abort();
for (x=x_start; x<x_end; x++){
r=src(x,y,0);
g=src(x,y,1);
b=src(x,y,2);
hue=rgb2hsl(r,g,b,0);
min=min(r,min(g,b));
max=max(r,max(g,b));
sat=max-min;
lum=(max+min)/2;
// tweak
hue+=ctl(0);
sat+=ctl(1);
lum+=ctl(2);
// get full colour hue
rt=hsl2rgb(hue,255,128,0);
gt=hsl2rgb(hue,255,128,1);
bt=hsl2rgb(hue,255,128,2);
// scale full colour hue down
// to sat range using lum as reference
r=scl(rt,0,255,lum-sat/2,lum+sat/2);
g=scl(gt,0,255,lum-sat/2,lum+sat/2);
b=scl(bt,0,255,lum-sat/2,lum+sat/2);
pset(x,y,0,r);
pset(x,y,1,g);
pset(x,y,2,b);
} // end x preview
} // end y preview
return true;
} // end for every tile Notice that the controls make use of track. This will make the filter go as you scrub the sliders. Fine for simple filters, but may bog down as things get more intensive.
Also notice that the range of the hue slider is -128 to +128. Cookie if you know why. (Bonus cookie if you know why the range should really be -128 to +127.)
As you get to playing with it, you may notice some funky things. One funky thing in particular is when Sat is set to -255. What this does is allow for illegal values of saturation and that's not always good. To fix, you have to clamp it.
Add something like this: Code: if (sat>255){sat=255;}
if (sat<0)}{sat=0;} Once you have that, you can desaturate to Lightness in HSL. This is *exactly* the same as hitting ctrl + shift + u. Feel free to do the detective work on that.
Feel free to clamp lum while you are at it. (Bonus cookie for why hue doesn't have to be clamped.)
There is still a lot of funkiness in there. The next funkiness is really funky.
Last edited by Stroker : 02-14-2006 at 12:18 AM.
| 
02-14-2006, 07:59 AM
|  | Senior Member | | Join Date: Jan 2005
Posts: 309
| | | I would like to thank the RetouchPRO Powers that Be for attachments. Normally I would use my own server for my own junk. Mucho appreciated.
In the last code that I posted, there is some funkiness. The major, glaring funk we are looking at is hue. What happens to hue when you get crazy with the Lum slider? It gets funkified. Why? Absolute clipping.
One of the interesting things about hue is that the RGB values stay relative to each other regardless of sat and lum. Do you know the RGB <> hue pattern for yellow? How about the RGB <> hue pattern for green? I'm sure most of you know this, but I don't know if any of you have ever looked at it this way.
The problem with the last code is that RGB <> hue is not being kept relative. If one value is out of bounds, it will get clipped, and that will inadvertantly affect hue. Hopefully the attachment illustrates this.
Welcome to my world. | 
02-14-2006, 06:28 PM
|  | Senior Member | | Join Date: Feb 2005 Location: Lancashire (UK)
Posts: 1,112
| | Stroker.
I have never seen ‘Track’ before. I can’t even find it in the manual. But I do understand what it is doing
I’ve spent a lot of time trying to win the cookies but I admit defeat. I could not find the answer at Tech Slop or at the Asylum. I did find an interesting article here. http://en.wikipedia.org/wiki/Talk:HSV_color_space
I hope I did not miss the answers in this thread.
if (sat<0)}{sat=0;}
I took the extra bracket out
Should I be clamping Sat before or after the calculation of scale full colour hue down
I can’t see any difference on the pictures I tried if the code was before or after or not there at all
Stroker, at http://tech-slop.serveit.org/wiki/in...a_frequencies1
You are breaking down the picture into frequencies. In another thread (another forum) I read where you tore the luminosity into low, medium and high to correct a face.
I know this can be done with Filtermeister as you must have used it in TS_LumFrequency. Would it be straying too far off subject to show us how to do this?
It’s nice to find someone who can spell ‘colour’ correctly.
Ken
Last edited by Cameraken : 02-14-2006 at 06:56 PM.
| 
02-15-2006, 02:15 AM
|  | Senior Member | | Join Date: Jan 2005
Posts: 309
| | | Track can be found in UserGuide.pdf in section 3.3 User control properties.
For the cookies, you won't exactly find them anywhere. As you do your own research and fiddling, keep them in mind and the answers may come. If not, don't fret too much over it.
Clamp sat immediately like so:
sat+=ctl(1);
if(sat<0){sat=0;}
if(sat>255){sat=255;}
Good catch with the extra bracket.
Actually, more about clamping saturation is coming soon.
Ah, the frequency thing. Fun, isn't it? I used Tom's code because it is wicked fast:
sourcecode\codelibrary\recursiveGauss4b-clean.ffp
- read Lum into an array
- use recursive Gauss for high blur
- High Pass the high bur
- another pass for low blur
- calculate the medium frequencies
- tweak, put back together, and output
That's the real quick of it. Once a lot of this other stuff is out of the way, I'll do a stripped-down version for you.
I think I'm the only person in the USA that still spells colour. I have to make an effort to spell it States style. |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | All times are GMT -6. The time now is 10:51 PM. |