Hi Gerrit,
Here we go. I'm not really sure if you refer to PCL (C++) or to the JavaScript runtime. Anyway, I'll tell you how to do this in both programming environments.
In JavaScript, you have to use the Image object. Here is a brief working example:
function outputPixelValue( image, x, y, c )
{
console.writeln( format( "<end><cbr>The pixel at x=%d y=%d c=%d has a value of %.7f",
x, y, c, image.sample( x, y, c ) ) );
}
// The curret image window.
var window = ImageWindow.activeWindow;
if ( window.isNull )
throw new Error( "I need an image to play!" );
// The image in the window's current view.
var image = window.currentView.image;
// Open the Process Console window.
console.show();
// Read some pixels.
outputPixelValue( image, 123, 456, 0 );
outputPixelValue( image, 300, 400, 1 );
outputPixelValue( image, 400, 500, 2 );
Copy the above code and paste it on a new JavaScript source document in Script Editor. Save the .js file wherever you want, open an image, and run it (on Linux and Windows you can press F9, Ctrl+R on macOS). The example assumes that the current image is an RGB color image, since it reads the three first channels (the c argument passed to outputPixelValue()).
As you see, the Image.sample() method does exactly what you want. There are other (faster) ways to read pixel values, but this is the basic technique.
Now in C++ with the PCL library:
#include <pcl/ImageWindow.h>
#include <pcl/Console.h>
void OutputPixelValue( const ImageVariant& image, int x, int y, int c )
{
Console().WriteLn( String().Format( "<end><cbr>The pixel at x=%d y=%d c=%d has a value of %.7f",
x, y, c, image( x, y, c ) ) );
}
void OutputSomePixels( const View& view )
{
AutoViewLock lock( view );
ImageVariant image = view.Image();
OutputPixelValue( image, 123, 456, 0 );
OutputPixelValue( image, 300, 400, 1 );
OutputPixelValue( image, 400, 500, 2 );
}
// ... somewhere from a function...
ImageWindow window = ImageWindow::ActiveWindow();
if ( window.IsNull() )
throw Error( "I need an image to play!" );
OutputSomePixels( window.CurrentView() );
Again, there are much faster (by orders of magnitude) ways to access pixel data in C++/PCL, but this would be a basic example. The OutputPixelValue() function makes use of the following operator member function of ImageVariant:
double pcl::ImageVariant::operator() ( int x, int y, int channel = 0 ) constwhich returns a pixel value in the normalized [0,1] range, just as Image.sample() in JavaScript. Both methods return a floating point pixel value irrespective of the actual pixel data type of the image; PCL and the JS runtime handle all of the involved complexities internally.
If you want to know how to modify pixels, not just how to read them, let me know. As I've said, these are absolutely basic examples, but also a good starting point to get the grasp of PixInsight development in JavaScript and C++. For PCL, the reference documentation is the main source of rigorous information:
https://pixinsight.com/developer/pcl/doc/html/For JavaScript we still don't have a complete documentation like PCL's (I am working on it), but you can use the Object Explorer window to obtain complete information on the available objects, their properties and methods. Note also that core JavaScript objects are normally very similar to their C++ counterparts (as these examples clearly show). Finally, a large amount of PixInsight source code is open source, available at our
official GitLab repositories (also still on
GitHub for a limited time), including the complete PCL library, utility programs and many official modules.
Let me know if this is what you were after.