RetouchPRO

Go Back   RetouchPRO > Tools > Software
Register Blogs FAQ Site Nav Search Today's Posts Mark Forums Read


Software Photoshop, Lightroom, Paintshop Pro, Painter, etc., and all their various plugins. Of course, you can also discuss all other programs, as well.

FilterMeister - Color Theory and Conversions

Reply
 
Thread Tools
  #1  
Old 02-10-2006, 09:40 AM
Stroker's Avatar
Stroker Stroker is offline
Senior Member
 
Join Date: Jan 2005
Posts: 370
(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 01:22 PM. Reason: byRo: Thread split
Reply With Quote top
  #2  
Old 02-10-2006, 12:01 PM
Cameraken's Avatar
Cameraken Cameraken is offline
Senior Member
 
Join Date: Feb 2005
Location: Lancashire (UK)
Posts: 1,158
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
Reply With Quote top
  #3  
Old 02-10-2006, 08:20 PM
Cameraken's Avatar
Cameraken Cameraken is offline
Senior Member
 
Join Date: Feb 2005
Location: Lancashire (UK)
Posts: 1,158
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
Reply With Quote top
  #4  
Old 02-11-2006, 04:41 AM
Stroker's Avatar
Stroker Stroker is offline
Senior Member
 
Join Date: Jan 2005
Posts: 370
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.
Reply With Quote top
  #5  
Old 02-11-2006, 07:36 AM
Stroker's Avatar
Stroker Stroker is offline
Senior Member
 
Join Date: Jan 2005
Posts: 370
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 08:21 AM.
Reply With Quote top
  #6  
Old 02-11-2006, 09:13 PM
Cameraken's Avatar
Cameraken Cameraken is offline
Senior Member
 
Join Date: Feb 2005
Location: Lancashire (UK)
Posts: 1,158
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
Reply With Quote top
  #7  
Old 02-12-2006, 05:19 PM
Stroker's Avatar
Stroker Stroker is offline
Senior Member
 
Join Date: Jan 2005
Posts: 370
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:

Code:
lum=(max+min)/2;
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.
Reply With Quote top
  #8  
Old 02-12-2006, 08:04 PM
Cameraken's Avatar
Cameraken Cameraken is offline
Senior Member
 
Join Date: Feb 2005
Location: Lancashire (UK)
Posts: 1,158
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
Reply With Quote top
  #9  
Old 02-13-2006, 08:16 AM
Stroker's Avatar
Stroker Stroker is offline
Senior Member
 
Join Date: Jan 2005
Posts: 370
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.
Reply With Quote top
  #10  
Old 02-13-2006, 04:36 PM
Cameraken's Avatar
Cameraken Cameraken is offline
Senior Member
 
Join Date: Feb 2005
Location: Lancashire (UK)
Posts: 1,158
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
Reply With Quote top
Reply

  RetouchPRO > Tools > Software


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Color Space conversions Reimar Photoshop Elements Help 4 01-16-2004 06:58 AM
Batch Raw conversions in PS CS okplayer Software 0 12-19-2003 01:03 PM


All times are GMT -6. The time now is 07:37 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
Copyright © 2016 Doug Nelson. All Rights Reserved