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
  #11  
Old 02-13-2006, 05:10 PM
Stroker's Avatar
Stroker Stroker is offline
Senior Member
 
Join Date: Jan 2005
Posts: 370
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.
Reply With Quote top
  #12  
Old 02-14-2006, 01:08 AM
Stroker's Avatar
Stroker Stroker is offline
Senior Member
 
Join Date: Jan 2005
Posts: 370
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.
Attached Images
File Type: jpg tempRGB2hsl.jpg (19.0 KB, 20 views)

Last edited by Stroker; 02-14-2006 at 01:18 AM.
Reply With Quote top
  #13  
Old 02-14-2006, 08:59 AM
Stroker's Avatar
Stroker Stroker is offline
Senior Member
 
Join Date: Jan 2005
Posts: 370
I would like to thank the RTP 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.
Attached Images
File Type: jpg lsatclipping.jpg (42.9 KB, 19 views)
Reply With Quote top
  #14  
Old 02-14-2006, 07:28 PM
Cameraken's Avatar
Cameraken Cameraken is offline
Senior Member
 
Join Date: Feb 2005
Location: Lancashire (UK)
Posts: 1,158
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 07:56 PM.
Reply With Quote top
  #15  
Old 02-15-2006, 03:15 AM
Stroker's Avatar
Stroker Stroker is offline
Senior Member
 
Join Date: Jan 2005
Posts: 370
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.
Reply With Quote top
  #16  
Old 02-15-2006, 05:11 AM
Stroker's Avatar
Stroker Stroker is offline
Senior Member
 
Join Date: Jan 2005
Posts: 370
Okay, clamping and limiting saturation to get rid of funkiness. Right.

Already clamped sat to the 0 to 255 range. While this is good, it's not entirely good. If you can believe it, you can still get some shifts in hue. Egads! Still have your full colour hue code handy? Go ahead and use it to do some comparing.

In similar colour spaces, saturation is limited by the lightness component. You will find this in HSB, HSL, and Lab. You will even find it in our mix-n-match colour space.

We have to limit sat based on lum - not just 0 to 255. Emphasis!

In order to see this, we have to turn to the colour space itself. We have to look our custom space in a 2d/3d manner. Our custom space is a double-cone.

See attachment.

What we need is another variable that hold what the maximum amount of saturation can be. I'm going to use Smax. This variable, Smax, will be calculated directly from lum.

Since we are dealing with a cone and an isosceles triangle, we can use a simple formula.

Get the absolute difference between lum and 128, multiply it by 2 for full 0 to 255 range, and invert.

Code:
Smax=255-abs(lum-128)*2;
Can you see it? I hope so because being able to see these kinds of things is what it's all about.

By the attached graphic, it may look like Smax = sat. No! Remember that sat may be lower than Smax.

Going to use Smax to limit sat, and Smax is derived from lum. This means clamp lum to 0 to 255, and then clamp sat using Smax.

New chunk of code:
Code:
// tweak
hue+=ctl(0);
sat+=ctl(1);
lum+=ctl(2);
 if(lum>255){lum=255;}
 if(lum<0){lum=0;}

// limit sat
Smax=255-abs(lum-128)*2;
 if(sat>Smax){sat=Smax;}
 if(sat<0){sat=0;}
Don't forget to add int Smax in the declares.

Using that last chunk, we are done putting our custom mix-n-match colour space back together. It's all good and proper.

Now, while our space and code is very similiar to Hue/Sat in Photoshop, there is still at least one major difference. That major difference is in Hue/Sat > Lightness slider and our own Lum slider.
- cookie if you can illustrate the difference
- bonus cookie if you can explain the difference

Hang on... it's not all good and proper. There is one last little thing in our code. We still have to deal with sat=0. Gadzooks!
Attached Images
File Type: jpg smax.jpg (22.4 KB, 12 views)
Reply With Quote top
  #17  
Old 02-15-2006, 05:18 AM
Stroker's Avatar
Stroker Stroker is offline
Senior Member
 
Join Date: Jan 2005
Posts: 370
Okay, if sat=0 in the original, then there is no hue - it literally doesn't exist. However, our code will allow us to add saturation. This will result in our code defaulting to hue=0, which is red.

Desaturate some photograph
Run our code and use Sat +255

Not good, eh?

Change this:

Code:
sat+=ctl(1);
into this:

Code:
if(sat!=0){sat+=ctl(1);}
If there is no saturation in the original, then our code won't add any.
Tada.

Or maybe you can take advantage of this and come up with your own little way to colourize.
Reply With Quote top
  #18  
Old 02-15-2006, 08:32 PM
Cameraken's Avatar
Cameraken Cameraken is offline
Senior Member
 
Join Date: Feb 2005
Location: Lancashire (UK)
Posts: 1,158
Thanks Stroker.

I got all the tweaks in and its working OK.

You are loosing me a little. I thought colour was Hue+Sat If that’s the case then why does Sat(max) depend on Lum.
Surely if Sat has been extracted correctly then its dependency should be lost.
It makes me question whether sat=max-min is correct.
This obviously took you a long time to work out so I am sure you are correct. I just don’t quite understand it yet.
I guess The fact that sat+=ctl(1) does not work proves you are correct, (image goes Red)
(sat!=0){sat+=ctl(1);} works fine.

Can you point me to any further reading on this. There seems to be nothing on the web. A Google search found this
http://nebulus.org/tutorials/2d/phot...lor/index.html
Pretty pictures. But not a full explanation.
I think you have already explained this. It has just not sunk in yet.

Difference between PS Hue/Sat > Lightness slider and your Lum slider. Ours is increasing each pixel by a fixed amount hence keeping the contrast. PS looses contrast as the lightness in increased.


Ken
Reply With Quote top
  #19  
Old 02-16-2006, 12:12 AM
Stroker's Avatar
Stroker Stroker is offline
Senior Member
 
Join Date: Jan 2005
Posts: 370
Saturation is limited by Lum in certain cases. Lum is the starting point and everything else follows.

Consider
Lum = 100% or 255
This is pure white and has no saturation
It's just pure white and that's that
If saturation isn't already 0, then it has to be reduced to 0

RGB is a cube and HSL is a double-cone. The double-cone doesn't fit nice and snug into a cube, so something has got to give. Rather, something has got to be limited or clamped.

This is the case for similiar colour spaces. But in order to see exactly how Lum limits Sat for a given space, you have to get 2d/3d. For example, Lab is a sphere. Lab is also Cartesian. This means you have to use Pythagoras to limit Sat based on L. You know, circles and right triangles and stuff.

Once you are comfortable with the idea of L limiting S, or pretty sure you understand it, we'll move on.

I don't think you will anything on the 'net talking about these kinds of things. I've looked and never found anything explicit. I've had to take a lot of bits-n-pieces and do my own detective work. As far as I know, I'm the only guy willing to talk about these nitty-gritty things.

Quote:
Difference between PS Hue/Sat > Lightness slider and your Lum slider. Ours is increasing each pixel by a fixed amount hence keeping the contrast. PS looses contrast as the lightness in increased.
Oh, pretty close. Not as close as I would like, but close enough for a cookie.
Attached Images
File Type: jpg fortunecookie2.jpg (13.9 KB, 13 views)
Reply With Quote top
  #20  
Old 02-17-2006, 12:42 PM
Cameraken's Avatar
Cameraken Cameraken is offline
Senior Member
 
Join Date: Feb 2005
Location: Lancashire (UK)
Posts: 1,158
Thanks Stroker.

There are a lot of advantages to the new code.
The border now zooms with the picture and the border changes with the sliders as the slider is moved.
I must start reading that manual.

Here is the new code.

Code:
%ffp

SupportedModes: RGBMode

OnFilterstart:{
	//Info("isTileable %d",isTileable);
	isTileable=true;
//	setZoom(1);
	return false;
}

ctl(0):standard,"Border thickness",range=(0,100),val=0,track
ctl(2):standard,"Red coloring",range=(0,255),val=0,track
ctl(3):standard,"Green coloring",range=(0,255),val=0,track
ctl(4):standard,"Blue coloring",range=(0,255),val=0,track

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

Also I found this. I don’t know if its any use, Or if it can be converted.
http://www.mathworks.com/matlabcentr...MS_Equalizer.m


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 08:59 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