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
  #21  
Old 02-18-2006, 08:54 PM
Cameraken's Avatar
Cameraken Cameraken is offline
Senior Member
 
Join Date: Feb 2005
Location: Lancashire (UK)
Posts: 1,158
Back to HsY

Stroker.
I have been re-reading this thread. (Several Times)

From post 3
Quote:
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.
Yes it IS Different in RGB and CMYK but NOT in Lab. I guess this should not be happening at all in Any colour space and sorta proves what you are saying is correct.

From post 6
There is a big difference in the two pieces of code
The first makes the blacks go red
The second the blacks stay black (well blacker)

Changing HsY to HSL (or any other space like CMYK) means that there will be some loss and that is the reason for the funkiness clamping
I guess you can’t fit a square peg in a round hole OR You can’t fit a cube into a double cone.


Ken
Reply With Quote top
  #22  
Old 02-19-2006, 05:02 AM
Stroker's Avatar
Stroker Stroker is offline
Senior Member
 
Join Date: Jan 2005
Posts: 370
Okay, the Lab thing. When you are in Lab mode, everything is done using Lab - no HsY to muck about with. It's pretty nice because Lab filters are a bit more straight forward. That is, you don't have to really worry about converting spaces for basic operations that would normally require a different space.

Colour blending mode in Lab is done using a and b channels - not hue and sat as we are used to them. Oh, I feel a can of worms coming. Can you feel it? Can you?

The HsY thing was using Lightness, but we want to use Lum as Photoshop defines and uses it. I originally went with Lightness out of convenience and to acclimate ya'll to certain ideas. The main idea being that the L* component will limit the Sat component.

Using Lightness, finding Smax was fairly easy. Using Lum to find Smax is going to be a bit trickier. Time to get funky. See attachment.

Upper-Left
This is the HSL double-cone kind of unwrapped to a cylinder. Across the top is pure white and the bottom is pure black. Right in the middle at 128 is where Smax=255.

Upper-Right
This is a greyscale representation of Smax. See how Smax=255 when Lightness=128? And then Smax fades to 0 as you get closer to the top or bottom? Yeah, finding Smax was easy.

Lower-Left
This is HsY unwrapped to a cylinder in the same manner. What was once a horizontal line is now all wiggly. Well, sort of wiggly.

Lower-Right
This is greyscale Smax for HsY. Definitely funky. Did we step in something funky? Oh, yeah.

If we can find were Smax=255 in HsY, then the rest should be easy to fade to Smax=0 at the top and bottom.

Is there a pattern to this? Is there a simple formula? There is, and it has been sitting right in front of our faces this whole time. Big cookie to anybody that figures it out before I give up the funk.

- = Warning = -
You may want to brush up on your triangles and ratios.
Attached Images
File Type: jpg findingSmax.jpg (20.4 KB, 11 views)
Reply With Quote top
  #23  
Old 02-19-2006, 02:07 PM
Cameraken's Avatar
Cameraken Cameraken is offline
Senior Member
 
Join Date: Feb 2005
Location: Lancashire (UK)
Posts: 1,158
HSL
Lightness = (Max-Min)/2
Sat = Max-Min
SatMax = 255-abs(lightness-128)x2


HSY (HS/Lum)
Lum = Rx0.30 + Gx0.59 + Bx0.11
Sat = Max-Min
SatMax = I guess the formula is going to be very similar to above as it will still be based on Lum.

Then if Sat>SatMax then Sat=SatMax

I sure did a lot of reading. These things are just not out there. I really appreciate you taking the time Stroker. The last link here is to a PDF which is interesting.

http://www.13thmonkey.org/~boris/pho...tion-test.html

http://en.wikipedia.org/wiki/HSV_col...rom_RGB_to_HSV

http://support.microsoft.com/kb/q29240/

http://www.prip.tuwien.ac.at/~hanbury/hsy2rgb.m

http://www.prip.tuwien.ac.at/~hanbury/colour_histogram/

http://www.prip.tuwien.ac.at/~hanbury/Online_docs.html

www.prip.tuwien.ac.at/~hanbury/SCIA_Hanbury.pdf


Ken
Reply With Quote top
  #24  
Old 02-20-2006, 06:55 AM
Stroker's Avatar
Stroker Stroker is offline
Senior Member
 
Join Date: Jan 2005
Posts: 370
You are welcome, Ken and others. And thank you for listening. It's not that often I come out and play like this. Well, not much lately. So, I am enjoying myself rather muchly.

There are several reasons why what I'm talking about is rather exclusive. One of the main things is that HsY is an Adobe thing and they don't document things like this. Another reason is that Smax is something that I invented for working with HsY. If I remember, I'll tell you the really real reason behind Smax. Seems like the rabbit hole just keeps on getting deeper, eh?

Ken, it's good to see you getting out there and doing research on your own. And it's good to see Roland steam-rollin' some of this stuff.

Roland, try this:
Code:
setZoom(-888);
It comes in handy from time to time.

Sooner than I wanted, but I'm gonna move on a bit further.

Smax based on Lum. I said that there was a magic formula and that it has been staring us right in the face. Going to use a variable of double type called Lxyz.

Code:
double Lxyz;

// get full colour hue
r=hsl2rgb(hue,255,128,0);
g=hsl2rgb(hue,255,128,1);
b=hsl2rgb(hue,255,128,2);

Lxyz =r*0.30 + g*0.59 + b*0.11;
Oh! Look at the formula for Lxyz. Look familiar? I should hope so.

Not completely apparent in that code chunk, but Lxyz comes immediately after getting full colour hue. This is so we can find the point where Smax=255 for *any* given hue. This will give us that funky wiggle.

Lxyz is also a double. I'm not exactly sure why it has to be a double, but it does. I think it has to do with precision in the next few steps.

Now that we have Lxyz as the point where Smax=255, it's just a simple matter of triangles and ratios to find Smax for any given value of Lum. Coming soon.

Kind of funny, isn't it? We have to have Hue in order to limit Sat based on Lum. Some things just aren't as independant as we thought.
Reply With Quote top
  #25  
Old 02-20-2006, 07:42 AM
Stroker's Avatar
Stroker Stroker is offline
Senior Member
 
Join Date: Jan 2005
Posts: 370
Oh, triangles. Lovely triangles and ratios. You like percentages, don't you?

Some where around here I posted a graphic with a triangle. One corner was red, one corner was black, and the last corner was white. We are going to take another look at that triangle, but in a different light.

You do remember Geometry one-oh-one, right? Check out the attachment and be amazed at how much you remember.
Attached Images
File Type: gif Smaxtriangles.gif (4.2 KB, 11 views)
Reply With Quote top
  #26  
Old 02-20-2006, 07:44 AM
Stroker's Avatar
Stroker Stroker is offline
Senior Member
 
Join Date: Jan 2005
Posts: 370
Using that, we can easily come up with what's in the attachment.

Since the ratios are percentages, have to multiply by 255. The rest should be cake.
Attached Images
File Type: jpg Smaxformulas.jpg (15.3 KB, 11 views)
Reply With Quote top
  #27  
Old 02-20-2006, 07:47 AM
Stroker's Avatar
Stroker Stroker is offline
Senior Member
 
Join Date: Jan 2005
Posts: 370
New code chunk:
Code:
// get full colour hue
r=hsl2rgb(hue,255,128,0);
g=hsl2rgb(hue,255,128,1);
b=hsl2rgb(hue,255,128,2);

Lxyz =r*0.30 + g*0.59 + b*0.11;

if(lum>=Lxyz){
Smax=255* ((255-lum)/(255-Lxyz));
} // Lum > Lxyz

if(lum<=Lxyz){
Smax=(lum/Lxyz)*255;
} // Lum < Lxyz

if(sat>Smax){sat=Smax;}
if(sat<0){sat=0;}
Previously scaling down to Sat was easy because L* was right in the middle of min and max. Well, Lum isn't always going to be in the middle of min and max. So, how do we scale down to Sat? How do we compensate for a wiggly reference?


Hmmm....
Reply With Quote top
  #28  
Old 02-21-2006, 02:42 AM
Stroker's Avatar
Stroker Stroker is offline
Senior Member
 
Join Date: Jan 2005
Posts: 370
Something just for fun. The tweaks I added are very sloppy. Forgive me?

Code:
%ffp

supportedmodes: RGBMode

ctl(0):standard,"T1 Mult",range=(0,300),val=100,track
ctl(1):standard,"T2 Add",range=(0,100),val=0,track

OnFilterStart:{
//setPreviewCursor (32515);
setZoom(1);
return false;
}

ForEveryTile:{
int x,y,z;
int c1,c2,c3,c4,c5,c6,c7,c8,c9;
int gx,gy;
float distance;
float final;
int finint;

for (z=0;z<Z;z++){
for (y=y_start; y<y_end; y++){
//if(updateProgress(y,y_end)) abort();
for (x=x_start; x<x_end; x++){

//  1  2  3
//  4  5  6
//  7  8  9

c1=src(x-1,y-1,z);
c2=src(x,y-1,z);
c3=src(x+1,y-1,z);
c4=src(x-1,y,z);
// c5
c6=src(x+1,y,z);
c7=src(x-1,y+1,z);
c8=src(x,y+1,z);
c9=src(x+1,y+1,z);

gx= -c1 -c4*2 -c7 +c3 +c6*2 +c9;
gy= -c1 -c2*2 -c3 +c7 +c8*2 +c9;

distance=sqrt((float)gx*gx + gy*gy);

final=distance*(float)ctl(0)/100.00;
finint=255-(int)final+ctl(1);

pset(x,y,z,finint);

}}}// x, y,z

return true;
} // for every tile

Last edited by Stroker; 02-21-2006 at 03:22 AM.
Reply With Quote top
  #29  
Old 02-21-2006, 08:18 PM
Cameraken's Avatar
Cameraken Cameraken is offline
Senior Member
 
Join Date: Feb 2005
Location: Lancashire (UK)
Posts: 1,158
Thanks Stroker.
I’ve been a bit busy with more OPR Pictures. And a faulty Central Heating Boiler.

The code from Post 49 is great for the artists here. I’ve added an example below.

I have not got the code from post 45 and Post 48 working yet. I’m getting some strange results. I think I need to take something out.
I will try again tomorrow.

Fancy this next Rô
http://www.codeproject.com/cpp/howtofft.asp

Ken
Attached Images
File Type: jpg Ken_Old-Ethnic-Woman.jpg (99.6 KB, 20 views)
Reply With Quote top
  #30  
Old 02-21-2006, 10:20 PM
Stroker's Avatar
Stroker Stroker is offline
Senior Member
 
Join Date: Jan 2005
Posts: 370
Those code chunks won't exactly work because we are not quite done putting it all back together.

The next problem is dealing with Lum and Sat. Since Lum isn't always in the middle of min and max, we need a different approach. I've tried several different approaches and only one seems to work decently.

Take care of Smax and sat. Get hue in full colour. Scale RGB down to sat using range 0 to sat. Use another variable to get the luminosity of the scaled down RGB. Take the difference between this temporary luminosity and the desired luminosity. Add that difference to all RGB values. Since we are adding the same value to RGB, hue and sat will be preserved. Plus, in the end, we will have the desired luminosity.

Notice that the temporary lum variable, temL, is also double.

Final RGB <> HsY 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 Smax;
 double Lxyz;
 double tempL;

int final;

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=r*0.30 + g*0.59 + b*0.11;

// tweak
hue+=ctl(0);
if(sat!=0){sat+=ctl(1);}
lum+=ctl(2);
 if(lum>255){lum=255;}
 if(lum<0){lum=0;}

// get full colour hue
r=hsl2rgb(hue,255,128,0);
g=hsl2rgb(hue,255,128,1);
b=hsl2rgb(hue,255,128,2);

Lxyz =r*0.30 + g*0.59 + b*0.11;

if(lum>=Lxyz){
Smax=255* ((255-lum)/(255-Lxyz));
} // Lum > Lxyz

if(lum<=Lxyz){
Smax=(lum/Lxyz)*255;
} // Lum < Lxyz

if(sat>Smax){sat=Smax;}
if(sat<0){sat=0;}

// scale to sat
r=scl(r,0,255,0,sat);
g=scl(g,0,255,0,sat);
b=scl(b,0,255,0,sat);

// calc small lum and get difference
tempL= r*0.30 + g*0.59 + b*0.11;
tempL=lum-tempL;

// add the difference
r+=tempL;
g+=tempL;
b+=tempL;

// output
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
There. You can now RGB <> HsY with a fair amount of accuracy. Isn't it beautiful?

Why would you want to do this? I don't know about you, but I like being able to extend a filter beyond the filter itself. That is, making it blending mode friendly for further tweaks. If I want a filter that works with Colour blending mode (Hue + Sat), I can now do that. If I want a filter that manipulates Lum for contrast, I can now do that.

Another good thing is making greyscale masks based on HsY. Practice your ChOps and take it to the code. If we get far enough, I'll tell ya'll about my Trigs in Space.
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 03:52 PM.


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