Author Topic: PCL: how do I get the L and S values for a pixel?  (Read 6785 times)

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
PCL: how do I get the L and S values for a pixel?
« on: 2009 July 06 19:57:40 »

Hi,

decided to pick up my profile tool again. It can now plot RGB, R, G and B curves. Clearly it would be nice if it could do L and S curves as well. Trouble is I don't know how to derive these values from an image. I defined a little macro for grabbing R, G and B values:

Code: [Select]
#define   GETPIXEL(x,y) { \
for (color = 0; color < numChannels; color++) {\
P::FromSample(theInterface->theProfile[pIndex].colors[color],\
img.Pixel(x,y, color));\
theInterface->theProfile[pIndex].p.x = x;\
theInterface->theProfile[pIndex].p.y = y;\
}\
}

The P::FromSample is the magic sauce that converts the img.Pixel to the right format. I've looked at the PixelTraits documentation but nothing springs out except the headache it gives me :)

If I can derive Luminance and Saturation from the stored R, G and B values that would be even better. I mean I know I *can* but I don't know how.

Thanks,

   Sander
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: PCL: how do I get the L and S values for a pixel?
« Reply #1 on: 2009 July 09 08:31:57 »
Hi Sander,

Sorry for the late answer. Of course you can. Assuming that img is a RGB color image in the code below:

Code: [Select]
Generic2DImage<P> img;
// ...
RGBColorSystem::sample r, g, b;
Point pos;
P::FromSample( r, img.Pixel( pos, 0 ) );
P::FromSample( g, img.Pixel( pos, 1 ) );
P::FromSample( b, img.Pixel( pos, 2 ) );

// Nonlinear luminance (CIE L* component)
RGBColorSystem::sample L = img.RGBWorkingSpace().CIEL( r, g, b );

// Linear (as long as gamma=1) luminance (CIE Y component)
RGBColorSystem::sample Y = img.RGBWorkingSpace().CIEY( r, g, b );

// Color saturation in the HSV color ordering system
RGBColorSystem::sample Sv = RGBColorSystem::HSVSaturation( r, g, b );

// Color saturation in the HSI color ordering system
RGBColorSystem::sample Si = RGBColorSystem::HSISaturation( r, g, b );

Note that HSVSaturation() and HSISaturation() are both static member functions of RGBColorSystem, so their calculation does not depend on a particular RGB working space, as is the case for CIE components. This is because HSV and HSI are not color spaces (in the strict colorimetric sense defined by PI/PCL) but just color ordering systems, or different representations of the RGB color cube.

The S curve in CurvesTransformation corresponds to the S element of HSV. As an alternative, you can use the CIE c* component, which also represents color saturation (the c curve of CurvesTransformation) with a strict colorimetric basis.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
Re: PCL: how do I get the L and S values for a pixel?
« Reply #2 on: 2009 July 09 09:46:48 »
Thanks Juan, that looks easy enough. I'll add that and see if I can put out a beta version for people to try.
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
Re: PCL: how do I get the L and S values for a pixel?
« Reply #3 on: 2009 July 11 13:43:41 »
Hi,

ok, not so easy :) VC++ doesn't like it very much.

Here's part of a macro I use:

Code: [Select]
case CurveTypeParameter::HSVSCurve:\
P::FromSample( r, img.Pixel( x, y, 0 ) );\
P::FromSample( g, img.Pixel( x, y, 1 ) );\
P::FromSample( b, img.Pixel( x, y, 2 ) );\
theInterface->theProfile[pIndex].colors[0] = RGBColorSystem::HSVSaturation( r, g, b );\
break;\
case CurveTypeParameter::HSISCurve:\
P::FromSample( r, img.Pixel( x, y, 0 ) );\
P::FromSample( g, img.Pixel( x, y, 1 ) );\
P::FromSample( b, img.Pixel( x, y, 2 ) );\
theInterface->theProfile[pIndex].colors[0] = RGBColorSystem::HSISaturation( r, g, b );\
break;\

VS2008 complains:
Code: [Select]
1>..\ProfileInterface.cpp(440) : error C2352: 'pcl::RGBColorSystem::HSVSaturation' : illegal call of non-static member function
1>        c:\pcl64\include\pcl/RGBColorSystem.h(457) : see declaration of 'pcl::RGBColorSystem::HSVSaturation'
1>..\ProfileInterface.cpp(440) : error C2352: 'pcl::RGBColorSystem::HSISaturation' : illegal call of non-static member function
1>        c:\pcl64\include\pcl/RGBColorSystem.h(478) : see declaration of 'pcl::RGBColorSystem::HSISaturation'

What do I do? The part where I use the img object compiles fine. I also tried to avoid the intermediate assignment to r, g and b by feeding Pixel(x, y, 0) etc into the parameters but that didn't seem to work. I guess I can try that again once I get this code working.
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: PCL: how do I get the L and S values for a pixel?
« Reply #4 on: 2009 July 11 16:55:16 »
Oops! My mistake!  :-[

Since a few PCL versions, HSVSaturation and similar functions are no longer static member functions of RGBColorSystem (the reasons are complex and deeply involved with PCL internals). So you need an instance of RGBColorSystem in order to invoke them. I forgot this fact, and hence my answer to your question was incorrect.

Just call:

Code: [Select]
img.RGBWorkingSpace().HSVSaturation( r, g, b ); // CORRECT
img.RGBWorkingSpace().HSISaturation( r, g, b );

etc., instead of:

Code: [Select]
RGBColorSystem::HSVSaturation( r, g, b ); // WRONG
RGBColorSystem::HSISaturation( r, g, b );

and your macros should work fine. Let me know.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
Re: PCL: how do I get the L and S values for a pixel?
« Reply #5 on: 2009 July 11 17:34:03 »
Thanks Juan, that did it. I'll upload a 64 bit windows DynamicProfile module soon.
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity