### Author Topic: PixelMaths output  (Read 4573 times)

#### Simon Hicks

• PixInsight Old Hand
• Posts: 333
##### PixelMaths output
« on: 2008 February 03 10:00:50 »
Hi PI Guys,
I am trying to find the average luminance of an image. I know how to use the basics of PixelMaths and I can use the average luminance in an expression to act on an image....the output always seems to be in terms of a processed image. But I just want to have a figure for the luminance of a particular image for calibration purposes.

Is it possible to somehow get this value to appear in the Processing Console?

Regards
Simon

#### Juan Conejero

• PTeam Member
• PixInsight Jedi Grand Master
• Posts: 6719
##### PixelMaths output
« Reply #1 on: 2008 February 03 10:55:30 »
Hi Simon,

For each pixel in a given image, the luminance is a function of:

- The individual RGB components of that pixel.
- The RGB Working Space currently associated with the image.

So you can't get a single figure as the luminance of a particular image. Instead, for a given RGB color image, you can extract a grayscale image whose pixels have values proportional to the luminance of the corresponding pixels in the original RGB image.

You can, however, read the luminance of each pixel very easily. Just use the ReadoutOptions standard process (Edit > Readout Options) and choose "RGB + L" for "Data / Color Space". In this way you'll obtain readouts of the individual RGB channels plus the luminance when you move the mouse cursor over RGB color images.

Is this what you are looking for?
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

#### Simon Hicks

• PixInsight Old Hand
• Posts: 333
##### PixelMaths output
« Reply #2 on: 2008 February 03 11:01:59 »
Hi Juan,
I need to get the average luminance for the whole image. I am trying to graph the luminance of dark frames vs temp and exposure time. So I need a value for each frame, like 0.03258.

Cheers
Simon

#### Juan Conejero

• PTeam Member
• PixInsight Jedi Grand Master
• Posts: 6719
##### PixelMaths output
« Reply #3 on: 2008 February 03 11:13:38 »
OK, no problem at all.

Go to the Script Editor window and create a new script (File > New > JavaScript Source File, or press Ctrl+N).

Then copy this little script:

Code: [Select]
`function main(){   // Get access to the current active image window.   var window = ImageWindow.activeWindow;   if ( window.isNull )      throw new Error( "No active image" );   // Extract the luminance of the current active view   var L = new Image;   // The second argument of extractLuminance is:   // - false to extract the CIE L* component (nonlinear)   // - true to extract the CIE Y component (linear)   window.currentView.image.extractLuminance( L, false );   console.show();   console.writeln( "<b>" + window.currentView.fullId + "</b>" );   console.writeln( format( "Average luminance = %.6f", L.mean() ) );}main();`

and paste it on the newly created script. Use File > Save As to save it with a suitable name; for example average-luminance.js.

make sure that you have the desired image selected, and select Execute > Compile & Run on the Script Editor. After a few moments you'll see the average luminance printed on the console.

Hope this helps.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

#### Simon Hicks

• PixInsight Old Hand
• Posts: 333
##### PixelMaths output
« Reply #4 on: 2008 February 03 11:17:14 »
Many Thanks for this Juan!

Cheers
Simon

#### Juan Conejero

• PTeam Member
• PixInsight Jedi Grand Master
• Posts: 6719
##### PixelMaths output
« Reply #5 on: 2008 February 03 11:20:45 »
Wait a minute. If you are working with dark frames, I assume that they are grayscale images. In this case you don't have to calculate a luminance, but just the average of all pixel values:

Code: [Select]
`function main(){   // Get access to the current active image window.   var window = ImageWindow.activeWindow;   if ( window.isNull )      throw new Error( "No active image" );   console.show();   console.writeln( "<b>" + window.currentView.fullId + "</b>" );   console.writeln( format( "Average pixel value = %.6f", window.currentView.image.mean() ) );}main();`

I think this is what you are trying to obtain, not the luminance. The luminance actually only makes sense for color images.

Am I right?
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

#### Simon Hicks

• PixInsight Old Hand
• Posts: 333
##### PixelMaths output
« Reply #6 on: 2008 February 03 11:26:20 »
Of course you are right !!! :-) That's exactly what I am trying to do.

But where is the Script Editor Window? I have just downloaded the Core.....do I need the Class Library to do this?

Cheers
Simon

#### Juan Conejero

• PTeam Member
• PixInsight Jedi Grand Master
• Posts: 6719
##### PixelMaths output
« Reply #7 on: 2008 February 03 11:30:14 »
The Script Editor window is available in the core application. If you don't see it docked at the lower left corner of the main window, just use View > Script Editor (Ctrl+Alt+E) to open it.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

#### Juan Conejero

• PTeam Member
• PixInsight Jedi Grand Master
• Posts: 6719
##### PixelMaths output
« Reply #8 on: 2008 February 03 11:33:02 »
Simon, also note that the average of all pixel values can be obtained with the Statistics tool, among other values. You don't need a script at all to do this!

The Statistics tool is under the Image category, on the Process Explorer.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

#### Carlos Milovic

• PTeam Member
• PixInsight Jedi Master
• Posts: 2173
• Join the dark side... we have cookies
##### PixelMaths output
« Reply #9 on: 2008 February 03 11:33:31 »
Hi Simon

Look under the main menu, under "View->Script Editor". You also may have a tab at the left of the screen where the Script Editor is located.

Another way to obtain the value you are looking for, is just to use the Statistics process (under the Image category). You'll see stats for each channel.
Regards,

Carlos Milovic F.
--------------------------------
PixInsight Project Developer
http://www.pixinsight.com

#### Juan Conejero

• PTeam Member
• PixInsight Jedi Grand Master
• Posts: 6719
##### PixelMaths output
« Reply #10 on: 2008 February 03 11:34:06 »
Hi Carlos, we crossed our answers! :lol:
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

#### Simon Hicks

• PixInsight Old Hand
• Posts: 333
##### PixelMaths output
« Reply #11 on: 2008 February 03 11:37:49 »
A million thanks to both of you! That's exactly what I needed, and I've now learnt a bit about script editing and about where the statistics can be found.

Cheers
Simon

#### Carlos Milovic

• PTeam Member
• PixInsight Jedi Master
• Posts: 2173
• Join the dark side... we have cookies
##### PixelMaths output
« Reply #12 on: 2008 February 03 11:39:24 »
Regards,

Carlos Milovic F.
--------------------------------
PixInsight Project Developer
http://www.pixinsight.com

#### Juan Conejero

• PTeam Member
• PixInsight Jedi Grand Master
• Posts: 6719
##### PixelMaths output
« Reply #13 on: 2008 February 04 03:30:45 »
Hi Simon,

Quote
I am trying to graph the luminance of dark frames vs temp and exposure time.

Just out of curiosity, what do you want to achieve with this? Hmmm, sounds interesting. Are you trying to characterize a model for automatic scaling of dark frames, by chance?
Juan Conejero
PixInsight Development Team
http://pixinsight.com/